1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-08 04:02:40 +01:00

[5tv] Improve

This commit is contained in:
Sergey M․ 2015-06-12 17:48:42 +06:00
parent 5da7177729
commit 499a077761

View File

@ -1,16 +1,23 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import int_or_none
int_or_none,
)
class FiveTVIE(InfoExtractor): class FiveTVIE(InfoExtractor):
_VALID_URL = r'http://(?:www\.)?5-tv\.ru/[^/]*/(?P<id>\d+)' _VALID_URL = r'''(?x)
_TESTS = [ http://
{ (?:www\.)?5-tv\.ru/
(?:
(?:[^/]+/)+(?P<id>\d+)|
(?P<path>[^/?#]+)(?:[/?#])?
)
'''
_TESTS = [{
'url': 'http://5-tv.ru/news/96814/', 'url': 'http://5-tv.ru/news/96814/',
'md5': 'bbff554ad415ecf5416a2f48c22d9283', 'md5': 'bbff554ad415ecf5416a2f48c22d9283',
'info_dict': { 'info_dict': {
@ -19,49 +26,63 @@ class FiveTVIE(InfoExtractor):
'title': 'Россияне выбрали имя для общенациональной платежной системы', 'title': 'Россияне выбрали имя для общенациональной платежной системы',
'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660', 'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
'width': 480,
'height': 360,
'duration': 180, 'duration': 180,
}, },
}, }, {
{
'url': 'http://5-tv.ru/video/1021729/', 'url': 'http://5-tv.ru/video/1021729/',
'md5': '299c8b72960efc9990acd2c784dc2296',
'info_dict': { 'info_dict': {
'id': '1021729', 'id': '1021729',
'ext': 'mp4', 'ext': 'mp4',
'title': '3D принтер', 'title': '3D принтер',
'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41', 'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
'width': 480,
'height': 360,
'duration': 180, 'duration': 180,
}, },
}, {
'url': 'http://www.5-tv.ru/glavnoe/#itemDetails',
'info_dict': {
'id': 'glavnoe',
'ext': 'mp4',
'title': 'Итоги недели с 8 по 14 июня 2015 года',
'thumbnail': 're:^https?://.*\.jpg$',
}, },
] }, {
'url': 'http://www.5-tv.ru/glavnoe/broadcasts/508645/',
'only_matching': True,
}, {
'url': 'http://5-tv.ru/films/1507502/',
'only_matching': True,
}, {
'url': 'http://5-tv.ru/programs/broadcast/508713/',
'only_matching': True,
}, {
'url': 'http://5-tv.ru/angel/',
'only_matching': True,
}, {
'url': 'http://www.5-tv.ru/schedule/?iframe=true&width=900&height=450',
'only_matching': True,
}]
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') or mobj.group('path')
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
video_link = self._search_regex( video_url = self._search_regex(
r'(<a.*?class="videoplayer">)', webpage, 'video link') r'<a[^>]+?href="([^"]+)"[^>]+?class="videoplayer"',
webpage, 'video url')
url = self._search_regex(r'href="([^"]+)"', video_link, 'video url') title = self._og_search_title(webpage, default=None) or self._search_regex(
width = int_or_none(self._search_regex( r'<title>([^<]+)</title>', webpage, 'title')
r'width:(\d+)px', video_link, 'width', default=None, fatal=False))
height = int_or_none(self._search_regex(
r'height:(\d+)px', video_link, 'height', default=None, fatal=False))
duration = int_or_none(self._og_search_property( duration = int_or_none(self._og_search_property(
'video:duration', webpage, 'duration')) 'video:duration', webpage, 'duration', default=None))
return { return {
'id': video_id, 'id': video_id,
'url': url, 'url': video_url,
'width': width, 'title': title,
'height': height, 'description': self._og_search_description(webpage, default=None),
'title': self._og_search_title(webpage), 'thumbnail': self._og_search_thumbnail(webpage, default=None),
'description': self._og_search_description(webpage),
'thumbnail': self._og_search_thumbnail(webpage),
'duration': duration, 'duration': duration,
} }