From 790b06b7d4490e1e54659fafb71167bc459c701c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sergey=20M=E2=80=A4?= Date: Wed, 20 Jul 2016 21:43:22 +0700 Subject: [PATCH] [odatv] Improve (Closes #9285) --- youtube_dl/extractor/odatv.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/youtube_dl/extractor/odatv.py b/youtube_dl/extractor/odatv.py index dbf96aefe..314527f98 100644 --- a/youtube_dl/extractor/odatv.py +++ b/youtube_dl/extractor/odatv.py @@ -1,51 +1,50 @@ # coding: utf-8 - from __future__ import unicode_literals + from .common import InfoExtractor from ..utils import ( ExtractorError, + NO_DEFAULT, remove_start ) -import re class OdaTVIE(InfoExtractor): - _VALID_URL = r'^https?://(?:www\.)?odatv\.com/(?:mob|vid)_video\.php\?id=(?P[^&]*)' + _VALID_URL = r'https?://(?:www\.)?odatv\.com/(?:mob|vid)_video\.php\?.*\bid=(?P[^&]+)' _TESTS = [{ 'url': 'http://odatv.com/vid_video.php?id=8E388', 'md5': 'dc61d052f205c9bf2da3545691485154', 'info_dict': { 'id': '8E388', 'ext': 'mp4', - 'title': 'md5:69654805a16a16cf9ec9d055e079831c' + 'title': 'Artık Davutoğlu ile devam edemeyiz' } }, { + # mobile URL 'url': 'http://odatv.com/mob_video.php?id=8E388', - 'md5': 'dc61d052f205c9bf2da3545691485154', - 'info_dict': { - 'id': '8E388', - 'ext': 'mp4', - 'title': 'md5:69654805a16a16cf9ec9d055e079831c' - } + 'only_matching': True, }, { + # no video 'url': 'http://odatv.com/mob_video.php?id=8E900', - 'md5': '', - 'info_dict': { - 'id': '8E900', - 'ext': 'mp4', - 'title': 'not found check' - } + 'only_matching': True, }] def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - if 'NO VIDEO!' in webpage: + + no_video = 'NO VIDEO!' in webpage + + video_url = self._search_regex( + r'mp4\s*:\s*(["\'])(?Phttp.+?)\1', webpage, 'video url', + default=None if no_video else NO_DEFAULT, group='url') + + if no_video: raise ExtractorError('Video %s does not exist' % video_id, expected=True) return { 'id': video_id, + 'url': video_url, 'title': remove_start(self._og_search_title(webpage), 'Video: '), 'thumbnail': self._og_search_thumbnail(webpage), - 'url': self._html_search_regex(r"(http.+?video_%s\.mp4)" % re.escape(video_id), webpage, 'url', flags=re.IGNORECASE) } -- 2.22.2