[tvc] Separate embed extractor

This commit is contained in:
Sergey M․ 2015-06-12 16:13:36 +06:00
parent fff3455f58
commit 9f15bdabc8
2 changed files with 77 additions and 53 deletions

View file

@ -584,7 +584,10 @@
TV2ArticleIE, TV2ArticleIE,
) )
from .tv4 import TV4IE from .tv4 import TV4IE
from .tvc import TVCIE from .tvc import (
TVCIE,
TVCEmbedIE,
)
from .tvigle import TvigleIE from .tvigle import TvigleIE
from .tvp import TvpIE, TvpSeriesIE from .tvp import TvpIE, TvpSeriesIE
from .tvplay import TVPlayIE from .tvplay import TVPlayIE

View file

@ -3,77 +3,98 @@
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
clean_html,
int_or_none, int_or_none,
str_or_none,
) )
class TVCIE(InfoExtractor): class TVCEmbedIE(InfoExtractor):
_VALID_URL = r'http://(?:www\.)?tvc\.ru/.*/show/.*id/(?P<id>\d+)' _VALID_URL = r'http://(?:www\.)?tvc\.ru/video/iframe/id/(?P<id>\d+)'
_TESTS = [ _TEST = {
{ 'url': 'http://www.tvc.ru/video/iframe/id/74622/isPlay/false/id_stat/channel/?acc_video_id=/channel/brand/id/17/show/episodes/episode_id/39702',
'url': 'http://www.tvc.ru/channel/brand/id/29/show/episodes/episode_id/39702/', 'md5': 'bbc5ff531d1e90e856f60fc4b3afd708',
'md5': 'aa6fb3cf384e18a0ad3b30ee2898beba', 'info_dict': {
'info_dict': { 'id': '74622',
'id': '74622', 'ext': 'mp4',
'display_id': '39702', 'title': 'События. "События". Эфир от 22.05.2015 14:30',
'ext': 'mp4', 'thumbnail': 're:^https?://.*\.jpg$',
'title': 'События. "События". Эфир от 22.05.2015 14:30', 'duration': 1122,
'description': 'md5:ad7aa7db22903f983e687b8a3e98c6dd',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': 1122,
},
}, },
{ }
'url': 'http://www.tvc.ru/news/show/id/69944',
'md5': 'b173128ee7b88b5b06c84e5f7880909f',
'info_dict': {
'id': '75399',
'display_id': '69944',
'ext': 'mp4',
'title': 'Эксперты: в столице встал вопрос о максимально безопасных остановках',
'description': 'md5:f675c8eaf23aab9df542d31773ed6518',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': 278,
},
},
]
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, display_id) video = self._download_json(
'http://www.tvc.ru/video/json/id/%s' % video_id, video_id)
video_url = self._og_search_video_url(webpage)
video_id = self._search_regex(
r'video/iframe/id/(\d+)/', video_url, 'video id')
video_json_url = 'http://www.tvc.ru/video/json/id/%s' % (video_id)
video_json = self._download_json(video_json_url, video_id)
formats = [] formats = []
for info in video_json.get('path', {}).get('quality', []): for info in video.get('path', {}).get('quality', []):
video_url = info.get('url')
if not video_url:
continue
format_id = self._search_regex( format_id = self._search_regex(
r'cdnvideo/([^-]+)-[^/]+/', info.get('url'), 'format id', r'cdnvideo/([^/]+?)(?:-[^/]+?)?/', video_url,
fatal=False) 'format id', default=None)
formats.append({ formats.append({
'format_id': str_or_none(format_id), 'url': video_url,
'url': info.get('url'), 'format_id': format_id,
'width': int_or_none(info.get('width')), 'width': int_or_none(info.get('width')),
'height': int_or_none(info.get('height')), 'height': int_or_none(info.get('height')),
'tbr': int_or_none(info.get('bitrate')), 'tbr': int_or_none(info.get('bitrate')),
}) })
self._sort_formats(formats) self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'display_id': display_id, 'title': video['title'],
'title': self._og_search_title(webpage), 'thumbnail': video.get('picture'),
'description': self._og_search_description(webpage), 'duration': int_or_none(video.get('duration')),
'thumbnail': self._og_search_thumbnail(webpage),
'duration': int_or_none(video_json.get('duration')),
'formats': formats, 'formats': formats,
} }
class TVCIE(InfoExtractor):
_VALID_URL = r'http://(?:www\.)?tvc\.ru/(?!video/iframe/id/)(?P<id>[^?#]+)'
_TESTS = [{
'url': 'http://www.tvc.ru/channel/brand/id/29/show/episodes/episode_id/39702/',
'info_dict': {
'id': '74622',
'ext': 'mp4',
'title': 'События. "События". Эфир от 22.05.2015 14:30',
'description': 'md5:ad7aa7db22903f983e687b8a3e98c6dd',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': 1122,
},
}, {
'url': 'http://www.tvc.ru/news/show/id/69944',
'info_dict': {
'id': '75399',
'ext': 'mp4',
'title': 'Эксперты: в столице встал вопрос о максимально безопасных остановках',
'description': 'md5:f2098f71e21f309e89f69b525fd9846e',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': 278,
},
}, {
'url': 'http://www.tvc.ru/channel/brand/id/47/show/episodes#',
'info_dict': {
'id': '2185',
'ext': 'mp4',
'title': 'Ещё не поздно. Эфир от 03.08.2013',
'description': 'md5:51fae9f3f8cfe67abce014e428e5b027',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': 3316,
},
}]
def _real_extract(self, url):
webpage = self._download_webpage(url, self._match_id(url))
return {
'_type': 'url_transparent',
'ie_key': 'TVCEmbed',
'url': self._og_search_video_url(webpage),
'title': clean_html(self._og_search_title(webpage)),
'description': clean_html(self._og_search_description(webpage)),
'thumbnail': self._og_search_thumbnail(webpage),
}