From 74adbfe7ab672e2e5a08b39733dd6f4aaf4914ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCndig?= Date: Thu, 9 Apr 2015 23:55:13 +0700 Subject: [PATCH 1/2] add high bitrate sources (HLS), solves issue #3564 --- youtube_dl/extractor/pbs.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/pbs.py b/youtube_dl/extractor/pbs.py index afce732e1..1ac1a96a7 100644 --- a/youtube_dl/extractor/pbs.py +++ b/youtube_dl/extractor/pbs.py @@ -155,7 +155,7 @@ class PBSIE(InfoExtractor): redirect_url = info['alternate_encoding']['url'] redirect_info = self._download_json( redirect_url + '?format=json', display_id, - 'Downloading video url info') + 'Downloading alternate_encoding video url info') if redirect_info['status'] == 'error': if redirect_info['http_code'] == 403: message = ( @@ -170,12 +170,36 @@ class PBSIE(InfoExtractor): rating_str = rating_str.rpartition('-')[2] age_limit = US_RATINGS.get(rating_str) + formats = [] + formats.append({ + 'format_id': info['alternate_encoding']['eeid'], + 'url': redirect_info['url'], + 'ext': 'mp4' + }) + + redirect_url_hls = info['recommended_encoding']['url'] + redirect_info_hls = self._download_json( + redirect_url_hls + '?format=json', display_id, + 'Downloading recommended_encoding video url info'); + + formats.append({ + 'format_id': info['recommended_encoding']['eeid'], + 'url': redirect_info_hls['url'], + 'protocol': 'm3u8', + 'ext': 'mp4' + }) + formats.append({ + 'format_id': info['recommended_encoding']['eeid'].replace("hls-800k-16x9", "hls-2500k-16x9"), + 'url': redirect_info_hls['url'].replace("hls-64-800k", "hls-400-2500k"), + 'protocol': 'm3u8', + 'ext': 'mp4' + }) + return { 'id': video_id, 'display_id': display_id, 'title': info['title'], - 'url': redirect_info['url'], - 'ext': 'mp4', + 'formats': formats, 'description': info['program'].get('description'), 'thumbnail': info.get('image_url'), 'duration': info.get('duration'), From dd57bb21a837183ddd910084f087ad7ebcc3b0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCndig?= Date: Thu, 16 Apr 2015 02:00:22 +0700 Subject: [PATCH 2/2] lower priority for HLS formats and only add high bitrate if regular bitrate follows the expected URL pattern --- youtube_dl/extractor/pbs.py | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/youtube_dl/extractor/pbs.py b/youtube_dl/extractor/pbs.py index 1ac1a96a7..3329d7fde 100644 --- a/youtube_dl/extractor/pbs.py +++ b/youtube_dl/extractor/pbs.py @@ -171,30 +171,35 @@ class PBSIE(InfoExtractor): age_limit = US_RATINGS.get(rating_str) formats = [] + + if info['alternate_encoding']['eeid'] != info['recommended_encoding']['eeid']: + redirect_url_hls = info['recommended_encoding']['url'] + redirect_info_hls = self._download_json( + redirect_url_hls + '?format=json', display_id, + 'Downloading recommended_encoding video url info'); + if redirect_info_hls['url'].endswith('m3u8'): + formats.append({ + 'format_id': info['recommended_encoding']['eeid'], + 'url': redirect_info_hls['url'], + 'protocol': 'm3u8', + 'ext': 'mp4', + 'preference': -2 + }) + if 'hls-64-800k' in redirect_info_hls['url']: + formats.append({ + 'format_id': info['recommended_encoding']['eeid'].replace("hls-800k-16x9", "hls-2500k-16x9"), + 'url': redirect_info_hls['url'].replace("hls-64-800k", "hls-64-2500k"), + 'protocol': 'm3u8', + 'ext': 'mp4', + 'preference': -2 + }) + formats.append({ 'format_id': info['alternate_encoding']['eeid'], 'url': redirect_info['url'], 'ext': 'mp4' }) - - redirect_url_hls = info['recommended_encoding']['url'] - redirect_info_hls = self._download_json( - redirect_url_hls + '?format=json', display_id, - 'Downloading recommended_encoding video url info'); - - formats.append({ - 'format_id': info['recommended_encoding']['eeid'], - 'url': redirect_info_hls['url'], - 'protocol': 'm3u8', - 'ext': 'mp4' - }) - formats.append({ - 'format_id': info['recommended_encoding']['eeid'].replace("hls-800k-16x9", "hls-2500k-16x9"), - 'url': redirect_info_hls['url'].replace("hls-64-800k", "hls-400-2500k"), - 'protocol': 'm3u8', - 'ext': 'mp4' - }) - + return { 'id': video_id, 'display_id': display_id,