From 2ac8ea5e181372fd8344c1cf8d8c655e4e667b0a Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Thu, 8 Jun 2017 17:59:23 -0500 Subject: [PATCH 1/9] [DrTuber] Fetch video URL from JSON stream (fixes issue #12058) --- youtube_dl/extractor/drtuber.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 1eca82b3b..98b0962df 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -44,8 +44,15 @@ class DrTuberIE(InfoExtractor): webpage = self._download_webpage( 'http://www.drtuber.com/video/%s' % video_id, display_id) - video_url = self._html_search_regex( - r']*><(?:p|h\d+)[^>]*>([^<]+)<', From 10dacd58d74768170a7d16649a8915a2f4d489de Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Sat, 10 Jun 2017 19:57:16 -0500 Subject: [PATCH 2/9] [DrTuber] Applied requested fixes for PR #13322 --- youtube_dl/extractor/drtuber.py | 38 ++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 98b0962df..025c44462 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -44,15 +44,33 @@ class DrTuberIE(InfoExtractor): webpage = self._download_webpage( 'http://www.drtuber.com/video/%s' % video_id, display_id) - # the video URL must be extracted from an external JSON stream - video_data = self._download_json( - 'http://www.drtuber.com/player_config_json/?vid=%s&embed=0&aid=0&domain_id=0' - % video_id, video_id) - # is a high-quality video available? - video_url = video_data['files']['hq'] - if video_url is None: - # nope - use the standard-quality video instead - video_url = video_data['files']['lq'] + video_data = self._download_json('http://www.drtuber.com/player_config_json/', video_id, query={ + 'vid': video_id, + 'embed': 0, + 'aid': 0, + 'domain_id': 0, + }, fatal=False) + + formats = [] + if video_data: + # standard-quality video format + video_url_lq = video_data.get('files', {}).get('lq') + if video_url_lq: + formats.append({ + 'format_id': 'LQ', + 'quality': 1, + 'url': video_url_lq + }) + # high-quality video format is preferred, if available + video_url_hq = video_data.get('files', {}).get('hq') + if video_url_hq: + formats.append({ + 'format_id': 'HQ', + 'quality': 2, + 'url': video_url_hq + }) + self._check_formats(formats, video_id) + self._sort_formats(formats, 'quality') title = self._html_search_regex( (r'class="title_watch"[^>]*><(?:p|h\d+)[^>]*>([^<]+)<', @@ -82,7 +100,7 @@ class DrTuberIE(InfoExtractor): return { 'id': video_id, 'display_id': display_id, - 'url': video_url, + 'formats': formats, 'title': title, 'thumbnail': thumbnail, 'like_count': like_count, From b46c28eba8a71b426995010d4842ffeeac120ea4 Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Wed, 14 Jun 2017 16:21:52 -0500 Subject: [PATCH 3/9] [DrTuber] Applied second requested fixes for PR #13322 --- youtube_dl/extractor/drtuber.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 025c44462..28e7eaf93 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -6,6 +6,7 @@ from .common import InfoExtractor from ..utils import ( NO_DEFAULT, str_to_int, + ExtractorError, ) @@ -53,24 +54,18 @@ class DrTuberIE(InfoExtractor): formats = [] if video_data: - # standard-quality video format - video_url_lq = video_data.get('files', {}).get('lq') - if video_url_lq: - formats.append({ - 'format_id': 'LQ', - 'quality': 1, - 'url': video_url_lq - }) - # high-quality video format is preferred, if available - video_url_hq = video_data.get('files', {}).get('hq') - if video_url_hq: - formats.append({ - 'format_id': 'HQ', - 'quality': 2, - 'url': video_url_hq - }) + for video_url_key in video_data.get('files', {}): + # high-quality video format is preferred, if available + if video_data['files'][video_url_key]: + formats.append({ + 'format_id': video_url_key.upper(), + 'quality': 2 if video_url_key == 'hq' else 1, + 'url': video_data['files'][video_url_key] + }) + if not formats: + raise ExtractorError('Video %s is not available' % video_id, expected=True) self._check_formats(formats, video_id) - self._sort_formats(formats, 'quality') + self._sort_formats(formats) title = self._html_search_regex( (r'class="title_watch"[^>]*><(?:p|h\d+)[^>]*>([^<]+)<', From 5c71d4a4367c4279013c0b6e92f5ca499d8720e0 Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Thu, 15 Jun 2017 16:41:09 -0500 Subject: [PATCH 4/9] [DrTuber] Applied third requested fixes for PR #13322 --- youtube_dl/extractor/drtuber.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 28e7eaf93..417406d64 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -6,7 +6,6 @@ from .common import InfoExtractor from ..utils import ( NO_DEFAULT, str_to_int, - ExtractorError, ) @@ -50,20 +49,16 @@ class DrTuberIE(InfoExtractor): 'embed': 0, 'aid': 0, 'domain_id': 0, - }, fatal=False) + }, fatal=True) formats = [] - if video_data: - for video_url_key in video_data.get('files', {}): - # high-quality video format is preferred, if available - if video_data['files'][video_url_key]: - formats.append({ - 'format_id': video_url_key.upper(), - 'quality': 2 if video_url_key == 'hq' else 1, - 'url': video_data['files'][video_url_key] - }) - if not formats: - raise ExtractorError('Video %s is not available' % video_id, expected=True) + for video_url_key in video_data.get('files', {}): + if video_data['files'][video_url_key]: + formats.append({ + 'format_id': video_url_key.upper(), + 'quality': 2 if video_url_key == 'hq' else 1, + 'url': video_data['files'][video_url_key] + }) self._check_formats(formats, video_id) self._sort_formats(formats) From 6ee6e9c6c665fd4859fdc96593cffe23db06838a Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Thu, 15 Jun 2017 19:01:07 -0500 Subject: [PATCH 5/9] [DrTuber] Applied fourth requested fixes for PR #13322 --- youtube_dl/extractor/drtuber.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 417406d64..178ae72d1 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -49,15 +49,15 @@ class DrTuberIE(InfoExtractor): 'embed': 0, 'aid': 0, 'domain_id': 0, - }, fatal=True) + }) formats = [] - for video_url_key in video_data.get('files', {}): - if video_data['files'][video_url_key]: + for video_url_key, video_url_value in video_data['files'].items(): + if video_url_value: formats.append({ 'format_id': video_url_key.upper(), 'quality': 2 if video_url_key == 'hq' else 1, - 'url': video_data['files'][video_url_key] + 'url': video_url_value }) self._check_formats(formats, video_id) self._sort_formats(formats) From ab83335789d736993205ac4e241a27cebfec255b Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Thu, 15 Jun 2017 19:53:08 -0500 Subject: [PATCH 6/9] [DrTuber] Fail gracefully if video data cannot be extracted - PR #13322 --- youtube_dl/extractor/drtuber.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 178ae72d1..693f20047 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -52,13 +52,15 @@ class DrTuberIE(InfoExtractor): }) formats = [] - for video_url_key, video_url_value in video_data['files'].items(): - if video_url_value: - formats.append({ - 'format_id': video_url_key.upper(), - 'quality': 2 if video_url_key == 'hq' else 1, - 'url': video_url_value - }) + for video_key, video_value in video_data.items(): + if video_key == 'files': + for video_url_key, video_url_value in video_data[video_key].items(): + if video_url_value: + formats.append({ + 'format_id': video_url_key.upper(), + 'quality': 2 if video_url_key == 'hq' else 1, + 'url': video_url_value + }) self._check_formats(formats, video_id) self._sort_formats(formats) From 1137b21a366beb27a320ccc060cbf49aad0bc3c5 Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Tue, 20 Jun 2017 16:51:53 -0500 Subject: [PATCH 7/9] [DrTuber] Corrected video data for-in loop - fifth requested fixes for PR #13322 --- youtube_dl/extractor/drtuber.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 693f20047..178ae72d1 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -52,15 +52,13 @@ class DrTuberIE(InfoExtractor): }) formats = [] - for video_key, video_value in video_data.items(): - if video_key == 'files': - for video_url_key, video_url_value in video_data[video_key].items(): - if video_url_value: - formats.append({ - 'format_id': video_url_key.upper(), - 'quality': 2 if video_url_key == 'hq' else 1, - 'url': video_url_value - }) + for video_url_key, video_url_value in video_data['files'].items(): + if video_url_value: + formats.append({ + 'format_id': video_url_key.upper(), + 'quality': 2 if video_url_key == 'hq' else 1, + 'url': video_url_value + }) self._check_formats(formats, video_id) self._sort_formats(formats) From 09994895eaf1d0ff71e672b52684f8532fea09aa Mon Sep 17 00:00:00 2001 From: Parmjit Virk Date: Thu, 22 Jun 2017 02:33:39 -0500 Subject: [PATCH 8/9] [DrTuber] Removed call to _check_formats - fifth requested fixes for PR #13322 --- youtube_dl/extractor/drtuber.py | 1 - 1 file changed, 1 deletion(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 178ae72d1..13ebfa634 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -59,7 +59,6 @@ class DrTuberIE(InfoExtractor): 'quality': 2 if video_url_key == 'hq' else 1, 'url': video_url_value }) - self._check_formats(formats, video_id) self._sort_formats(formats) title = self._html_search_regex( From 0f7a5235899640fe90ed02b9ecc926875a157edf Mon Sep 17 00:00:00 2001 From: Sergey M Date: Fri, 23 Jun 2017 00:07:39 +0700 Subject: [PATCH 9/9] Update drtuber.py --- youtube_dl/extractor/drtuber.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/drtuber.py b/youtube_dl/extractor/drtuber.py index 13ebfa634..c5d56a9ad 100644 --- a/youtube_dl/extractor/drtuber.py +++ b/youtube_dl/extractor/drtuber.py @@ -44,20 +44,21 @@ class DrTuberIE(InfoExtractor): webpage = self._download_webpage( 'http://www.drtuber.com/video/%s' % video_id, display_id) - video_data = self._download_json('http://www.drtuber.com/player_config_json/', video_id, query={ - 'vid': video_id, - 'embed': 0, - 'aid': 0, - 'domain_id': 0, - }) + video_data = self._download_json( + 'http://www.drtuber.com/player_config_json/', video_id, query={ + 'vid': video_id, + 'embed': 0, + 'aid': 0, + 'domain_id': 0, + }) formats = [] - for video_url_key, video_url_value in video_data['files'].items(): - if video_url_value: + for format_id, video_url in video_data['files'].items(): + if video_url: formats.append({ - 'format_id': video_url_key.upper(), - 'quality': 2 if video_url_key == 'hq' else 1, - 'url': video_url_value + 'format_id': format_id, + 'quality': 2 if format_id == 'hq' else 1, + 'url': video_url }) self._sort_formats(formats)