From 99ac0390f559aa6dd09ffd8a15b9b562fda5f363 Mon Sep 17 00:00:00 2001 From: Hannu Lintala Date: Mon, 8 Jun 2015 05:58:41 +0300 Subject: [PATCH 1/2] [fivetv] Add extractor (Closes #5794) --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/fivetv.py | 67 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 youtube_dl/extractor/fivetv.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 67eb96057..d10275d03 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -152,6 +152,7 @@ from .firstpost import FirstpostIE from .firsttv import FirstTVIE from .fivemin import FiveMinIE +from .fivetv import FiveTVIE from .fktv import ( FKTVIE, FKTVPosteckeIE, diff --git a/youtube_dl/extractor/fivetv.py b/youtube_dl/extractor/fivetv.py new file mode 100644 index 000000000..e47383b39 --- /dev/null +++ b/youtube_dl/extractor/fivetv.py @@ -0,0 +1,67 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor +from ..utils import ( + int_or_none, +) + + +class FiveTVIE(InfoExtractor): + _VALID_URL = r'http://(?:www\.)?5-tv\.ru/[^/]*/(?P\d+)' + _TESTS = [ + { + 'url': 'http://5-tv.ru/news/96814/', + 'md5': 'bbff554ad415ecf5416a2f48c22d9283', + 'info_dict': { + 'id': '96814', + 'ext': 'mp4', + 'title': 'Россияне выбрали имя для общенациональной платежной системы', + 'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660', + 'thumbnail': 're:^https?://.*\.jpg$', + 'width': 480, + 'height': 360, + 'duration': 180, + }, + }, + { + 'url': 'http://5-tv.ru/video/1021729/', + 'md5': '299c8b72960efc9990acd2c784dc2296', + 'info_dict': { + 'id': '1021729', + 'ext': 'mp4', + 'title': '3D принтер', + 'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41', + 'thumbnail': 're:^https?://.*\.jpg$', + 'width': 480, + 'height': 360, + 'duration': 180, + }, + }, + ] + + def _real_extract(self, url): + video_id = self._match_id(url) + + webpage = self._download_webpage(url, video_id) + + video_link = self._search_regex( + r'()', webpage, 'video link') + + url = self._search_regex(r'href="([^"]+)"', video_link, 'video url') + width = int_or_none(self._search_regex( + 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( + 'video:duration', webpage, 'duration')) + return { + 'id': video_id, + 'url': url, + 'width': width, + 'height': height, + 'title': self._og_search_title(webpage), + 'description': self._og_search_description(webpage), + 'thumbnail': self._og_search_thumbnail(webpage), + 'duration': duration, + } From 499a077761b1577857952dc3b541c9f61a8bcade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Fri, 12 Jun 2015 17:48:42 +0600 Subject: [PATCH 2/2] [5tv] Improve --- youtube_dl/extractor/fivetv.py | 115 +++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/youtube_dl/extractor/fivetv.py b/youtube_dl/extractor/fivetv.py index e47383b39..13fbc4da2 100644 --- a/youtube_dl/extractor/fivetv.py +++ b/youtube_dl/extractor/fivetv.py @@ -1,67 +1,88 @@ # coding: utf-8 from __future__ import unicode_literals +import re + from .common import InfoExtractor -from ..utils import ( - int_or_none, -) +from ..utils import int_or_none class FiveTVIE(InfoExtractor): - _VALID_URL = r'http://(?:www\.)?5-tv\.ru/[^/]*/(?P\d+)' - _TESTS = [ - { - 'url': 'http://5-tv.ru/news/96814/', - 'md5': 'bbff554ad415ecf5416a2f48c22d9283', - 'info_dict': { - 'id': '96814', - 'ext': 'mp4', - 'title': 'Россияне выбрали имя для общенациональной платежной системы', - 'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660', - 'thumbnail': 're:^https?://.*\.jpg$', - 'width': 480, - 'height': 360, - 'duration': 180, - }, + _VALID_URL = r'''(?x) + http:// + (?:www\.)?5-tv\.ru/ + (?: + (?:[^/]+/)+(?P\d+)| + (?P[^/?#]+)(?:[/?#])? + ) + ''' + + _TESTS = [{ + 'url': 'http://5-tv.ru/news/96814/', + 'md5': 'bbff554ad415ecf5416a2f48c22d9283', + 'info_dict': { + 'id': '96814', + 'ext': 'mp4', + 'title': 'Россияне выбрали имя для общенациональной платежной системы', + 'description': 'md5:a8aa13e2b7ad36789e9f77a74b6de660', + 'thumbnail': 're:^https?://.*\.jpg$', + 'duration': 180, }, - { - 'url': 'http://5-tv.ru/video/1021729/', - 'md5': '299c8b72960efc9990acd2c784dc2296', - 'info_dict': { - 'id': '1021729', - 'ext': 'mp4', - 'title': '3D принтер', - 'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41', - 'thumbnail': 're:^https?://.*\.jpg$', - 'width': 480, - 'height': 360, - 'duration': 180, - }, + }, { + 'url': 'http://5-tv.ru/video/1021729/', + 'info_dict': { + 'id': '1021729', + 'ext': 'mp4', + 'title': '3D принтер', + 'description': 'md5:d76c736d29ef7ec5c0cf7d7c65ffcb41', + 'thumbnail': 're:^https?://.*\.jpg$', + '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): - 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) - video_link = self._search_regex( - r'()', webpage, 'video link') + video_url = self._search_regex( + r']+?href="([^"]+)"[^>]+?class="videoplayer"', + webpage, 'video url') - url = self._search_regex(r'href="([^"]+)"', video_link, 'video url') - width = int_or_none(self._search_regex( - 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)) + title = self._og_search_title(webpage, default=None) or self._search_regex( + r'([^<]+)', webpage, 'title') duration = int_or_none(self._og_search_property( - 'video:duration', webpage, 'duration')) + 'video:duration', webpage, 'duration', default=None)) + return { 'id': video_id, - 'url': url, - 'width': width, - 'height': height, - 'title': self._og_search_title(webpage), - 'description': self._og_search_description(webpage), - 'thumbnail': self._og_search_thumbnail(webpage), + 'url': video_url, + 'title': title, + 'description': self._og_search_description(webpage, default=None), + 'thumbnail': self._og_search_thumbnail(webpage, default=None), 'duration': duration, }