From 9f4921bfa0ce3a48d2f93b4946f361116cfde5e9 Mon Sep 17 00:00:00 2001 From: remitamine Date: Thu, 3 Sep 2015 00:29:53 +0100 Subject: [PATCH 1/7] [dcn] add show extraction and support for other types of urls --- youtube_dl/extractor/__init__.py | 6 ++- youtube_dl/extractor/dcn.py | 81 ++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 39b05ce8f..d4a3e8ab0 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -118,7 +118,11 @@ ) from .daum import DaumIE from .dbtv import DBTVIE -from .dcn import DCNIE +from .dcn import ( + DCNGeneralIE, + DCNVideoIE, + DCNShowIE, +) from .dctp import DctpTvIE from .deezer import DeezerPlaylistIE from .dfb import DFBIE diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index 82261e25c..352d35c7a 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -1,6 +1,8 @@ # coding: utf-8 from __future__ import unicode_literals +import re + from .common import InfoExtractor from ..compat import ( compat_urllib_parse, @@ -12,10 +14,33 @@ ) -class DCNIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/.+|show/\d+/.+?)/(?P\d+)' +class DCNGeneralIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?show/(?P\d+)/[^/]+(?:/(?P\d+)/(?P\d+))?' + + def _real_extract(self, url): + show_id, video_id, season_id = re.match(self._VALID_URL, url).groups() + url = '' + ie_key = '' + if video_id and int(video_id) > 0: + url = 'http://www.dcndigital.ae/#/media/%s' % video_id + ie_key = 'DCNVideo' + else: + ie_key = 'DCNShow' + if season_id and int(season_id) > 0: + url = 'http://www.dcndigital.ae/#/program/season/%s' % season_id + else: + url = 'http://www.dcndigital.ae/#/program/%s' % show_id + return { + 'url': url, + '_type': 'url', + 'ie_key': ie_key + } + + +class DCNVideoIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media)/(?P\d+)' _TEST = { - 'url': 'http://www.dcndigital.ae/#/show/199074/%D8%B1%D8%AD%D9%84%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D8%B1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/17375/6887', + 'url': 'http://www.dcndigital.ae/#/video/%D8%B1%D8%AD%D9%84%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D8%B1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/17375', 'info_dict': { 'id': '17375', @@ -82,3 +107,53 @@ def _real_extract(self, url): 'timestamp': timestamp, 'formats': formats, } + + +class DCNShowIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P\d+)|season/(?P\d+))' + _TEST = { + 'url': 'http://dcndigital.ae/#/program/205024/%D9%85%D8%AD%D8%A7%D8%B6%D8%B1%D8%A7%D8%AA-%D8%A7%D9%84%D8%B4%D9%8A%D8%AE-%D8%A7%D9%84%D8%B4%D8%B9%D8%B1%D8%A7%D9%88%D9%8A', + 'info_dict': + { + 'id': '205024', + 'title': 'محاضرات الشيخ الشعراوي', + 'description': '', + }, + 'playlist_mincount': 27, + } + + def _real_extract(self, url): + show_id, season_id = re.match(self._VALID_URL, url).groups() + data = {} + if season_id: + request = compat_urllib_request.Request( + 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id, + headers={'Origin': 'http://www.dcndigital.ae'}) + season = self._download_json(request, season_id) + show_id = season['id'] + data['season'] = season_id + data['show_id'] = show_id + request = compat_urllib_request.Request( + 'http://admin.mangomolo.com/analytics/index.php/plus/show', + compat_urllib_parse.urlencode(data), + { + 'Origin': 'http://www.dcndigital.ae', + 'Content-Type': 'application/x-www-form-urlencoded' + }) + show = self._download_json(request, show_id) + title = show['cat'].get('title_en') or show['cat']['title_ar'] + description = show['cat'].get('description_en') or show['cat'].get('description_ar') + entries = [] + for video in show['videos']: + entries.append({ + 'url': 'http://www.dcndigital.ae/#/media/%s' % video['id'], + '_type': 'url', + 'ie_key': 'DCNVideo', + }) + return { + 'id': show_id, + 'title': title, + 'description': description, + 'entries': entries, + '_type': 'playlist', + } From b477da2094db30a232f67edf3b342dc460aa14d4 Mon Sep 17 00:00:00 2001 From: remitamine Date: Thu, 3 Sep 2015 16:59:10 +0100 Subject: [PATCH 2/7] correct the extractor name and id and remove unnecessary request --- youtube_dl/extractor/__init__.py | 2 +- youtube_dl/extractor/dcn.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index d4a3e8ab0..4e41d9bf9 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -121,7 +121,7 @@ from .dcn import ( DCNGeneralIE, DCNVideoIE, - DCNShowIE, + DCNSeasonIE, ) from .dctp import DctpTvIE from .deezer import DeezerPlaylistIE diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index 352d35c7a..8a36c10f6 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -11,6 +11,8 @@ from ..utils import ( int_or_none, parse_iso8601, + smuggle_url, + unsmuggle_url, ) @@ -25,9 +27,9 @@ def _real_extract(self, url): url = 'http://www.dcndigital.ae/#/media/%s' % video_id ie_key = 'DCNVideo' else: - ie_key = 'DCNShow' + ie_key = 'DCNSeason' if season_id and int(season_id) > 0: - url = 'http://www.dcndigital.ae/#/program/season/%s' % season_id + url = smuggle_url('http://www.dcndigital.ae/#/program/season/%s' % season_id, {'show_id': show_id}) else: url = 'http://www.dcndigital.ae/#/program/%s' % show_id return { @@ -38,6 +40,7 @@ def _real_extract(self, url): class DCNVideoIE(InfoExtractor): + IE_NAME = 'dcn:video' _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media)/(?P\d+)' _TEST = { 'url': 'http://www.dcndigital.ae/#/video/%D8%B1%D8%AD%D9%84%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D8%B1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/17375', @@ -109,13 +112,14 @@ def _real_extract(self, url): } -class DCNShowIE(InfoExtractor): +class DCNSeasonIE(InfoExtractor): + IE_NAME = 'dcn:season' _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P\d+)|season/(?P\d+))' _TEST = { 'url': 'http://dcndigital.ae/#/program/205024/%D9%85%D8%AD%D8%A7%D8%B6%D8%B1%D8%A7%D8%AA-%D8%A7%D9%84%D8%B4%D9%8A%D8%AE-%D8%A7%D9%84%D8%B4%D8%B9%D8%B1%D8%A7%D9%88%D9%8A', 'info_dict': { - 'id': '205024', + 'id': '7910', 'title': 'محاضرات الشيخ الشعراوي', 'description': '', }, @@ -123,15 +127,18 @@ class DCNShowIE(InfoExtractor): } def _real_extract(self, url): + url, smuggled_data = unsmuggle_url(url, {}) show_id, season_id = re.match(self._VALID_URL, url).groups() data = {} if season_id: - request = compat_urllib_request.Request( - 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id, - headers={'Origin': 'http://www.dcndigital.ae'}) - season = self._download_json(request, season_id) - show_id = season['id'] data['season'] = season_id + show_id = smuggled_data.get('show_id') + if show_id is None: + request = compat_urllib_request.Request( + 'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id, + headers={'Origin': 'http://www.dcndigital.ae'}) + season = self._download_json(request, season_id) + show_id = season['id'] data['show_id'] = show_id request = compat_urllib_request.Request( 'http://admin.mangomolo.com/analytics/index.php/plus/show', @@ -141,6 +148,7 @@ def _real_extract(self, url): 'Content-Type': 'application/x-www-form-urlencoded' }) show = self._download_json(request, show_id) + season_id = season_id or show['default_season'] title = show['cat'].get('title_en') or show['cat']['title_ar'] description = show['cat'].get('description_en') or show['cat'].get('description_ar') entries = [] @@ -151,7 +159,7 @@ def _real_extract(self, url): 'ie_key': 'DCNVideo', }) return { - 'id': show_id, + 'id': season_id, 'title': title, 'description': description, 'entries': entries, From 8e2898edf930830260ab6b294c8866e7651a01a6 Mon Sep 17 00:00:00 2001 From: remitamine Date: Fri, 4 Sep 2015 15:42:09 +0100 Subject: [PATCH 3/7] [dcn] add support for live streams and catchup videos --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/dcn.py | 62 +++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 4e41d9bf9..677c75564 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -121,6 +121,7 @@ from .dcn import ( DCNGeneralIE, DCNVideoIE, + DCNLiveIE, DCNSeasonIE, ) from .dctp import DctpTvIE diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index 8a36c10f6..2e8fff660 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import re +import base64 from .common import InfoExtractor from ..compat import ( @@ -41,7 +42,7 @@ def _real_extract(self, url): class DCNVideoIE(InfoExtractor): IE_NAME = 'dcn:video' - _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media)/(?P\d+)' + _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media|catchup/[^/]+/[^/]+)/(?P\d+)' _TEST = { 'url': 'http://www.dcndigital.ae/#/video/%D8%B1%D8%AD%D9%84%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D8%B1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/17375', 'info_dict': @@ -112,6 +113,65 @@ def _real_extract(self, url): } +class DCNLiveIE(InfoExtractor): + IE_NAME = 'dcn:live' + _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?live/(?P\d+)' + _TEST = { + 'url': 'http://www.dcndigital.ae/#/live/6/dubai-tv', + 'info_dict': + { + 'id': '6', + 'ext': 'mp4', + 'title': 'Dubai Al Oula', + }, + 'params': { + # m3u8 download + 'skip_download': True, + }, + } + + def _real_extract(self, url): + channel_id = self._match_id(url) + + request = compat_urllib_request.Request( + 'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id, + headers={'Origin': 'http://www.dcndigital.ae'}) + + channel = self._download_json(request, channel_id) + title = channel.get('title_en') or channel['title_ar'] + + webpage = self._download_webpage( + 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + + compat_urllib_parse.urlencode({ + 'id': base64.b64encode(channel['user_id'].encode()).decode(), + 'channelid': base64.b64encode(channel['id'].encode()).decode(), + 'signature': channel['signature'], + 'countries': 'Q0M=', + 'filter': 'DENY', + }), channel_id) + + m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url') + formats = self._extract_m3u8_formats( + m3u8_url, channel_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls') + + rtsp_url = self._search_regex( + r']+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False) + if rtsp_url: + formats.append({ + 'url': rtsp_url, + 'format_id': 'rtsp', + }) + + self._sort_formats(formats) + + return { + 'id': channel_id, + 'title': title, + 'formats': formats, + 'is_live': True, + } + + class DCNSeasonIE(InfoExtractor): IE_NAME = 'dcn:season' _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P\d+)|season/(?P\d+))' From 486375154cb7d79bd084879467bc70550104b555 Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 5 Sep 2015 11:30:42 +0100 Subject: [PATCH 4/7] correct season info extraction and simplify --- youtube_dl/extractor/dcn.py | 64 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index 2e8fff660..8b360a9d7 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -25,19 +25,13 @@ def _real_extract(self, url): url = '' ie_key = '' if video_id and int(video_id) > 0: - url = 'http://www.dcndigital.ae/#/media/%s' % video_id - ie_key = 'DCNVideo' + return self.url_result('http://www.dcndigital.ae/#/media/%s' % video_id, 'DCNVideo') else: - ie_key = 'DCNSeason' if season_id and int(season_id) > 0: url = smuggle_url('http://www.dcndigital.ae/#/program/season/%s' % season_id, {'show_id': show_id}) else: url = 'http://www.dcndigital.ae/#/program/%s' % show_id - return { - 'url': url, - '_type': 'url', - 'ie_key': ie_key - } + return self.url_result(url, 'DCNSeason') class DCNVideoIE(InfoExtractor): @@ -71,6 +65,11 @@ def _real_extract(self, url): video = self._download_json(request, video_id) title = video.get('title_en') or video['title_ar'] + img = video.get('img') + thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None + duration = int_or_none(video.get('duration')) + description = video.get('description_en') or video.get('description_ar') + timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ') webpage = self._download_webpage( 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' @@ -96,12 +95,6 @@ def _real_extract(self, url): self._sort_formats(formats) - img = video.get('img') - thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None - duration = int_or_none(video.get('duration')) - description = video.get('description_en') or video.get('description_ar') - timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ') - return { 'id': video_id, 'title': title, @@ -122,7 +115,9 @@ class DCNLiveIE(InfoExtractor): { 'id': '6', 'ext': 'mp4', - 'title': 'Dubai Al Oula', + 'title': 're:^Dubai Al Oula [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', + 'thumbnail': 're:^https?://.*\.png$', + 'is_live': True, }, 'params': { # m3u8 download @@ -139,10 +134,14 @@ def _real_extract(self, url): channel = self._download_json(request, channel_id) title = channel.get('title_en') or channel['title_ar'] + img = channel.get('thumbnail') + thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None + description = channel.get('description_en') or channel.get('description_ar') + timestamp = parse_iso8601(channel.get('create_time') or channel.get('update_time'), ' ') webpage = self._download_webpage( - 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' - + compat_urllib_parse.urlencode({ + 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + + compat_urllib_parse.urlencode({ 'id': base64.b64encode(channel['user_id'].encode()).decode(), 'channelid': base64.b64encode(channel['id'].encode()).decode(), 'signature': channel['signature'], @@ -166,7 +165,9 @@ def _real_extract(self, url): return { 'id': channel_id, - 'title': title, + 'title': self._live_title(title), + 'description': description, + 'thumbnail': thumbnail, 'formats': formats, 'is_live': True, } @@ -181,7 +182,6 @@ class DCNSeasonIE(InfoExtractor): { 'id': '7910', 'title': 'محاضرات الشيخ الشعراوي', - 'description': '', }, 'playlist_mincount': 27, } @@ -189,6 +189,7 @@ class DCNSeasonIE(InfoExtractor): def _real_extract(self, url): url, smuggled_data = unsmuggle_url(url, {}) show_id, season_id = re.match(self._VALID_URL, url).groups() + data = {} if season_id: data['season'] = season_id @@ -207,21 +208,18 @@ def _real_extract(self, url): 'Origin': 'http://www.dcndigital.ae', 'Content-Type': 'application/x-www-form-urlencoded' }) + show = self._download_json(request, show_id) season_id = season_id or show['default_season'] - title = show['cat'].get('title_en') or show['cat']['title_ar'] - description = show['cat'].get('description_en') or show['cat'].get('description_ar') + season = {} + for _ in show['seasons']: + if _['id'] == season_id: + season = _ + break + title = season.get('title_en') or season['title_ar'] + entries = [] for video in show['videos']: - entries.append({ - 'url': 'http://www.dcndigital.ae/#/media/%s' % video['id'], - '_type': 'url', - 'ie_key': 'DCNVideo', - }) - return { - 'id': season_id, - 'title': title, - 'description': description, - 'entries': entries, - '_type': 'playlist', - } + entries.append(self.url_result('http://www.dcndigital.ae/#/media/%s' % video['id'], 'DCNVideo')) + + return self.playlist_result(entries, season_id, title) From 50b9dd734423231f7a01ed8a156d09ca04a23a31 Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 31 Oct 2015 15:40:11 +0100 Subject: [PATCH 5/7] [dcn] improve season info extraction --- youtube_dl/extractor/dcn.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index 8b360a9d7..a9a5e94f5 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -210,16 +210,14 @@ def _real_extract(self, url): }) show = self._download_json(request, show_id) - season_id = season_id or show['default_season'] - season = {} - for _ in show['seasons']: - if _['id'] == season_id: - season = _ - break - title = season.get('title_en') or season['title_ar'] + if not season_id: + season_id = show['default_season'] + for season in show['seasons']: + if season['id'] == season_id: + title = season.get('title_en') or season['title_ar'] - entries = [] - for video in show['videos']: - entries.append(self.url_result('http://www.dcndigital.ae/#/media/%s' % video['id'], 'DCNVideo')) + entries = [] + for video in show['videos']: + entries.append(self.url_result('http://www.dcndigital.ae/#/media/%s' % video['id'], 'DCNVideo')) - return self.playlist_result(entries, season_id, title) + return self.playlist_result(entries, season_id, title) From 6afe044b51e99a3a0e638492e118634a2ca3cdad Mon Sep 17 00:00:00 2001 From: remitamine Date: Sun, 27 Dec 2015 09:56:15 +0100 Subject: [PATCH 6/7] [dcn] improve extraction --- youtube_dl/extractor/__init__.py | 2 +- youtube_dl/extractor/dcn.py | 148 ++++++++++++++----------------- 2 files changed, 67 insertions(+), 83 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 677c75564..abf36caf3 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -119,7 +119,7 @@ from .daum import DaumIE from .dbtv import DBTVIE from .dcn import ( - DCNGeneralIE, + DCNIE, DCNVideoIE, DCNLiveIE, DCNSeasonIE, diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index a9a5e94f5..3857ba334 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -17,24 +17,61 @@ ) -class DCNGeneralIE(InfoExtractor): +class DCNIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?show/(?P\d+)/[^/]+(?:/(?P\d+)/(?P\d+))?' def _real_extract(self, url): show_id, video_id, season_id = re.match(self._VALID_URL, url).groups() - url = '' - ie_key = '' if video_id and int(video_id) > 0: - return self.url_result('http://www.dcndigital.ae/#/media/%s' % video_id, 'DCNVideo') + return self.url_result( + 'http://www.dcndigital.ae/media/%s' % video_id, 'DCNVideo') + elif season_id and int(season_id) > 0: + return self.url_result(smuggle_url( + 'http://www.dcndigital.ae/program/season/%s' % season_id, + {'show_id': show_id}), 'DCNSeason') else: - if season_id and int(season_id) > 0: - url = smuggle_url('http://www.dcndigital.ae/#/program/season/%s' % season_id, {'show_id': show_id}) - else: - url = 'http://www.dcndigital.ae/#/program/%s' % show_id - return self.url_result(url, 'DCNSeason') + return self.url_result( + 'http://www.dcndigital.ae/program/%s' % show_id, 'DCNSeason') -class DCNVideoIE(InfoExtractor): +class DCNBaseIE(InfoExtractor): + def _extract_video_info(self, video_data, video_id, is_live): + title = video_data.get('title_en') or video_data['title_ar'] + img = video_data.get('img') + thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None + duration = int_or_none(video_data.get('duration')) + description = video_data.get('description_en') or video_data.get('description_ar') + timestamp = parse_iso8601(video_data.get('create_time'), ' ') + + return { + 'id': video_id, + 'title': self._live_title(title) if is_live else title, + 'description': description, + 'thumbnail': thumbnail, + 'duration': duration, + 'timestamp': timestamp, + 'is_live': is_live, + } + + def _extract_video_formats(self, webpage, video_id, entry_protocol): + m3u8_url = self._html_search_regex( + r'file\s*:\s*"([^"]+)', webpage, 'm3u8 url') + formats = self._extract_m3u8_formats( + m3u8_url, video_id, 'mp4', entry_protocol, m3u8_id='hls') + + rtsp_url = self._search_regex( + r']+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False) + if rtsp_url: + formats.append({ + 'url': rtsp_url, + 'format_id': 'rtsp', + }) + + self._sort_formats(formats) + return formats + + +class DCNVideoIE(DCNBaseIE): IE_NAME = 'dcn:video' _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media|catchup/[^/]+/[^/]+)/(?P\d+)' _TEST = { @@ -45,7 +82,6 @@ class DCNVideoIE(InfoExtractor): 'ext': 'mp4', 'title': 'رحلة العمر : الحلقة 1', 'description': 'md5:0156e935d870acb8ef0a66d24070c6d6', - 'thumbnail': 're:^https?://.*\.jpg$', 'duration': 2041, 'timestamp': 1227504126, 'upload_date': '20081124', @@ -62,51 +98,23 @@ def _real_extract(self, url): request = compat_urllib_request.Request( 'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id, headers={'Origin': 'http://www.dcndigital.ae'}) - - video = self._download_json(request, video_id) - title = video.get('title_en') or video['title_ar'] - img = video.get('img') - thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None - duration = int_or_none(video.get('duration')) - description = video.get('description_en') or video.get('description_ar') - timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ') + video_data = self._download_json(request, video_id) + info = self._extract_video_info(video_data, video_id, False) webpage = self._download_webpage( - 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' - + compat_urllib_parse.urlencode({ - 'id': video['id'], - 'user_id': video['user_id'], - 'signature': video['signature'], + 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' + + compat_urllib_parse.urlencode({ + 'id': video_data['id'], + 'user_id': video_data['user_id'], + 'signature': video_data['signature'], 'countries': 'Q0M=', 'filter': 'DENY', }), video_id) - - m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url') - formats = self._extract_m3u8_formats( - m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls') - - rtsp_url = self._search_regex( - r']+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False) - if rtsp_url: - formats.append({ - 'url': rtsp_url, - 'format_id': 'rtsp', - }) - - self._sort_formats(formats) - - return { - 'id': video_id, - 'title': title, - 'description': description, - 'thumbnail': thumbnail, - 'duration': duration, - 'timestamp': timestamp, - 'formats': formats, - } + info['formats'] = self._extract_video_formats(webpage, video_id, 'm3u8_native') + return info -class DCNLiveIE(InfoExtractor): +class DCNLiveIE(DCNBaseIE): IE_NAME = 'dcn:live' _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?live/(?P\d+)' _TEST = { @@ -132,45 +140,20 @@ def _real_extract(self, url): 'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id, headers={'Origin': 'http://www.dcndigital.ae'}) - channel = self._download_json(request, channel_id) - title = channel.get('title_en') or channel['title_ar'] - img = channel.get('thumbnail') - thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None - description = channel.get('description_en') or channel.get('description_ar') - timestamp = parse_iso8601(channel.get('create_time') or channel.get('update_time'), ' ') + channel_data = self._download_json(request, channel_id) + info = self._extract_video_info(channel_data, channel_id, True) webpage = self._download_webpage( 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + compat_urllib_parse.urlencode({ - 'id': base64.b64encode(channel['user_id'].encode()).decode(), - 'channelid': base64.b64encode(channel['id'].encode()).decode(), - 'signature': channel['signature'], + 'id': base64.b64encode(channel_data['user_id'].encode()).decode(), + 'channelid': base64.b64encode(channel_data['id'].encode()).decode(), + 'signature': channel_data['signature'], 'countries': 'Q0M=', 'filter': 'DENY', }), channel_id) - - m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url') - formats = self._extract_m3u8_formats( - m3u8_url, channel_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls') - - rtsp_url = self._search_regex( - r']+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False) - if rtsp_url: - formats.append({ - 'url': rtsp_url, - 'format_id': 'rtsp', - }) - - self._sort_formats(formats) - - return { - 'id': channel_id, - 'title': self._live_title(title), - 'description': description, - 'thumbnail': thumbnail, - 'formats': formats, - 'is_live': True, - } + info['formats'] = self._extract_video_formats(webpage, channel_id, 'm3u8') + return info class DCNSeasonIE(InfoExtractor): @@ -218,6 +201,7 @@ def _real_extract(self, url): entries = [] for video in show['videos']: - entries.append(self.url_result('http://www.dcndigital.ae/#/media/%s' % video['id'], 'DCNVideo')) + entries.append(self.url_result( + 'http://www.dcndigital.ae/media/%s' % video['id'], 'DCNVideo')) return self.playlist_result(entries, season_id, title) From bca9bea1c1a13d2f9ad3244a2b11979220c30484 Mon Sep 17 00:00:00 2001 From: remitamine Date: Mon, 28 Dec 2015 10:27:17 +0100 Subject: [PATCH 7/7] [dcn] make m3u8 formats extraction non fatal --- youtube_dl/extractor/dcn.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/youtube_dl/extractor/dcn.py b/youtube_dl/extractor/dcn.py index 3857ba334..d9485cd86 100644 --- a/youtube_dl/extractor/dcn.py +++ b/youtube_dl/extractor/dcn.py @@ -54,10 +54,14 @@ def _extract_video_info(self, video_data, video_id, is_live): } def _extract_video_formats(self, webpage, video_id, entry_protocol): + formats = [] m3u8_url = self._html_search_regex( - r'file\s*:\s*"([^"]+)', webpage, 'm3u8 url') - formats = self._extract_m3u8_formats( - m3u8_url, video_id, 'mp4', entry_protocol, m3u8_id='hls') + r'file\s*:\s*"([^"]+)', webpage, 'm3u8 url', fatal=False) + if m3u8_url: + m3u8_formats = self._extract_m3u8_formats( + m3u8_url, video_id, 'mp4', entry_protocol, m3u8_id='hls', fatal=None) + if m3u8_formats: + formats.extend(m3u8_formats) rtsp_url = self._search_regex( r']+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False) @@ -117,21 +121,6 @@ def _real_extract(self, url): class DCNLiveIE(DCNBaseIE): IE_NAME = 'dcn:live' _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?live/(?P\d+)' - _TEST = { - 'url': 'http://www.dcndigital.ae/#/live/6/dubai-tv', - 'info_dict': - { - 'id': '6', - 'ext': 'mp4', - 'title': 're:^Dubai Al Oula [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', - 'thumbnail': 're:^https?://.*\.png$', - 'is_live': True, - }, - 'params': { - # m3u8 download - 'skip_download': True, - }, - } def _real_extract(self, url): channel_id = self._match_id(url)