mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-03 06:02:51 +08:00
[ellentube] Implement code review changes.
This commit is contained in:
parent
196b0d7a36
commit
6d006044bc
@ -5,14 +5,31 @@ from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
clean_html,
|
||||
int_or_none,
|
||||
urljoin,
|
||||
)
|
||||
|
||||
|
||||
class EllenTubeBaseIE(InfoExtractor):
|
||||
API_URL = 'https://api-prod.ellentube.com/'
|
||||
class EllenTubeIE(InfoExtractor):
|
||||
_VALID_URL = r'''(?x)
|
||||
(?:
|
||||
https://api-prod\.ellentube\.com/ellenapi/api/item/
|
||||
|ellentube:
|
||||
)
|
||||
(?P<id>
|
||||
[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}
|
||||
)'''
|
||||
|
||||
def _extract_video_from_json(self, data, video_id, display_id=None):
|
||||
_TESTS = [{
|
||||
'url': 'https://api-prod.ellentube.com/ellenapi/api/item/75c64c16-aefd-4558-b4f5-3de09b22e6fc',
|
||||
'match_only': True,
|
||||
}, {
|
||||
'url': 'ellentube:734a3353-f697-4e79-9ca9-bfc3002dc1e0',
|
||||
'match_only': True,
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
data = self._download_json(
|
||||
'https://api-prod.ellentube.com/ellenapi/api/item/%s' % video_id, video_id)
|
||||
title = data['title']
|
||||
description = data.get('description')
|
||||
publish_time = int_or_none(data.get('publishTime'))
|
||||
@ -31,21 +48,43 @@ class EllenTubeBaseIE(InfoExtractor):
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'display_id': display_id,
|
||||
'duration': duration,
|
||||
'thumbnail': thumbnail,
|
||||
'timestamp': publish_time,
|
||||
'formats': formats,
|
||||
}
|
||||
|
||||
def _extract_playlist_entries_from_json(self, data, display_id):
|
||||
return [self._extract_video_from_json(elem, elem['id'])
|
||||
for elem in data if elem.get('type') == 'VIDEO']
|
||||
|
||||
def _extract_from_video_id(self, video_id, display_id=None):
|
||||
api_data = self._download_json(
|
||||
urljoin(self.API_URL, 'ellenapi/api/item/%s' % video_id), video_id)
|
||||
return self._extract_video_from_json(api_data, video_id, display_id)
|
||||
class EllenTubeVideoIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?ellentube\.com/video/(?P<id>.+)\.html'
|
||||
|
||||
_TEST = {
|
||||
'url': 'https://www.ellentube.com/video/ellen-meets-las-vegas-survivors-jesus-campos-and-stephen-schuck.html',
|
||||
'md5': '2fabc277131bddafdd120e0fc0f974c9',
|
||||
'info_dict': {
|
||||
'id': '0822171c-3829-43bf-b99f-d77358ae75e3',
|
||||
'ext': 'mp4',
|
||||
'title': 'Ellen Meets Las Vegas Survivors Jesus Campos and Stephen Schuck',
|
||||
'description': 'md5:76e3355e2242a78ad9e3858e5616923f',
|
||||
'duration': 514,
|
||||
'timestamp': 1508505120000,
|
||||
'thumbnail': 'https://warnerbros-h.assetsadobe.com/is/image/content/dam/ellen/videos/episodes/season15/32/video--2728751654987218111',
|
||||
}
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, display_id)
|
||||
video_id = self._html_search_regex(
|
||||
r'(?s)<!--\s*CONTENT\s*-->.*data-config.+([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
|
||||
webpage, 'video id')
|
||||
return self.url_result('ellentube:%s' % video_id)
|
||||
|
||||
|
||||
class EllenTubePlaylistIE(InfoExtractor):
|
||||
def _extract_videos_from_json(self, data, display_id):
|
||||
return [self.url_result('ellentube:%s' % elem['id'], 'EllenTube')
|
||||
for elem in data if elem.get('type') == 'VIDEO']
|
||||
|
||||
def _extract_playlist(self, url, display_id, extract_description=True):
|
||||
webpage = self._download_webpage(url, display_id)
|
||||
@ -59,40 +98,14 @@ class EllenTubeBaseIE(InfoExtractor):
|
||||
api_search = self._search_regex(
|
||||
r'"filter"\s*:\s*"(.+?)"', playlist_data, 'playlist api request')
|
||||
api_data = self._download_json(
|
||||
urljoin(self.API_URL, 'ellenapi/api/feed/?%s' % api_search), display_id)
|
||||
'https://api-prod.ellentube.com/ellenapi/api/feed/?%s' % api_search,
|
||||
display_id)
|
||||
return self.playlist_result(
|
||||
self._extract_playlist_entries_from_json(api_data, display_id),
|
||||
self._extract_videos_from_json(api_data, display_id),
|
||||
display_id, playlist_title, playlist_description)
|
||||
|
||||
|
||||
class EllenTubeVideoIE(EllenTubeBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?ellentube\.com/video/(?P<id>.+)\.html'
|
||||
|
||||
_TEST = {
|
||||
'url': 'https://www.ellentube.com/video/ellen-meets-las-vegas-survivors-jesus-campos-and-stephen-schuck.html',
|
||||
'md5': '2fabc277131bddafdd120e0fc0f974c9',
|
||||
'info_dict': {
|
||||
'id': '0822171c-3829-43bf-b99f-d77358ae75e3',
|
||||
'ext': 'mp4',
|
||||
'title': 'Ellen Meets Las Vegas Survivors Jesus Campos and Stephen Schuck',
|
||||
'description': 'md5:76e3355e2242a78ad9e3858e5616923f',
|
||||
'display_id': 'ellen-meets-las-vegas-survivors-jesus-campos-and-stephen-schuck',
|
||||
'duration': 514,
|
||||
'timestamp': 1508505120000,
|
||||
'thumbnail': 'https://warnerbros-h.assetsadobe.com/is/image/content/dam/ellen/videos/episodes/season15/32/video--2728751654987218111',
|
||||
}
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, display_id)
|
||||
video_id = self._html_search_regex(
|
||||
r'(?s)<!--\s*CONTENT\s*-->.*data-config.+([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
|
||||
webpage, 'video id')
|
||||
return self._extract_from_video_id(video_id, display_id)
|
||||
|
||||
|
||||
class EllenTubeEpisodeIE(EllenTubeBaseIE):
|
||||
class EllenTubeEpisodeIE(EllenTubePlaylistIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?ellentube\.com/episode/(?P<id>.+)\.html'
|
||||
|
||||
_TEST = {
|
||||
@ -110,7 +123,7 @@ class EllenTubeEpisodeIE(EllenTubeBaseIE):
|
||||
return self._extract_playlist(url, display_id)
|
||||
|
||||
|
||||
class EllenTubeStudioIE(EllenTubeBaseIE):
|
||||
class EllenTubeStudioIE(EllenTubePlaylistIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?ellentube\.com/studios/(?P<id>.+)\.html'
|
||||
|
||||
_TEST = {
|
||||
|
@ -309,6 +309,7 @@ from .eighttracks import EightTracksIE
|
||||
from .einthusan import EinthusanIE
|
||||
from .eitb import EitbIE
|
||||
from .ellentube import (
|
||||
EllenTubeIE,
|
||||
EllenTubeEpisodeIE,
|
||||
EllenTubeStudioIE,
|
||||
EllenTubeVideoIE,
|
||||
|
Loading…
Reference in New Issue
Block a user