From d553c324dd8a62df4544b6572efa722714eca18c Mon Sep 17 00:00:00 2001 From: Irfan Charania Date: Thu, 23 Feb 2017 20:56:57 -0800 Subject: [PATCH 1/3] Tune.pk Add new extractor --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/tunepk.py | 51 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 youtube_dl/extractor/tunepk.py diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 55b4782d3..69f9890cc 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -990,6 +990,7 @@ from .tunein import ( TuneInTopicIE, TuneInShortenerIE, ) +from .tunepk import TunepkIE from .turbo import TurboIE from .tutv import TutvIE from .tv2 import ( diff --git a/youtube_dl/extractor/tunepk.py b/youtube_dl/extractor/tunepk.py new file mode 100644 index 000000000..d9d03629d --- /dev/null +++ b/youtube_dl/extractor/tunepk.py @@ -0,0 +1,51 @@ +from __future__ import unicode_literals + +import re + +from .common import InfoExtractor + + +class TunepkIE(InfoExtractor): + _VALID_URL = r'(?:https?://|\.)(tune\.pk)/(?:player|video|play)/(?:[\w\.\?]+=)?(?P\d+)' + _TEST = { + 'url': 'https://tune.pk/video/6919541/maudie-2017-international-trailer-1-ft-ethan-hawke-sally-hawkins', + 'md5': '0C537163B7F6F97DA3C5DD1E3EF6DD55', + 'info_dict': { + 'id': '6919541', + 'ext': 'mp4', + 'title': 'Maudie (2017) | International Trailer # 1 ft Ethan Hawke, Sally Hawkins', + 'thumbnail': r're:^https?://.*\.jpg$' + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + html = webpage.replace('\n\r', '').replace('\r', '').replace('\n', '').replace('\\', '') + sources = re.compile('"sources"\s*:\s*\[(.+?)\]').findall(html)[0] + sources = re.compile("{(.+?)}").findall(sources) + + formats = [] + + for source in sources: + video_link = str(re.compile('"file":"(.*?)"').findall(source)[0]) + video_type = str(re.compile('"type":"(.*?)"').findall(source)[0]) + video_bitrate = str(re.compile('"bitrate":(\d+)').findall(source)[0]) + formats.append({ + 'url': video_link, + 'ext': video_type, + 'format_id': video_bitrate + }) + + self._sort_formats(formats) + + return { + 'id': video_id, + 'formats': formats, + 'title': self._html_search_meta(r'title', webpage, 'title'), + 'description': self._html_search_meta(r'description', webpage, 'description'), + 'thumbnail': self._html_search_meta(r'thumbnail', webpage, 'thumbnail'), + 'uploader': self._html_search_meta(r'author', webpage, 'author'), + 'average_rating': self._html_search_meta(r'rating', webpage, 'rating') + } From c7af4ad90b8de31f6a3bb1afeb3ac00f5b36e574 Mon Sep 17 00:00:00 2001 From: Irfan Charania Date: Sun, 26 Feb 2017 10:12:26 -0800 Subject: [PATCH 2/3] Use self._parse_json --- youtube_dl/extractor/tunepk.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/tunepk.py b/youtube_dl/extractor/tunepk.py index d9d03629d..dd7984f79 100644 --- a/youtube_dl/extractor/tunepk.py +++ b/youtube_dl/extractor/tunepk.py @@ -23,15 +23,16 @@ class TunepkIE(InfoExtractor): webpage = self._download_webpage(url, video_id) html = webpage.replace('\n\r', '').replace('\r', '').replace('\n', '').replace('\\', '') - sources = re.compile('"sources"\s*:\s*\[(.+?)\]').findall(html)[0] - sources = re.compile("{(.+?)}").findall(sources) + player = re.compile('"player"\s*:\s*(\{.+?\]\}\})').findall(html)[0] + config = self._parse_json(player, video_id) formats = [] - for source in sources: - video_link = str(re.compile('"file":"(.*?)"').findall(source)[0]) - video_type = str(re.compile('"type":"(.*?)"').findall(source)[0]) - video_bitrate = str(re.compile('"bitrate":(\d+)').findall(source)[0]) + for source in config.get('sources'): + video_link = source.get('file') + video_type = source.get('type') + video_bitrate = str(source.get('bitrate')) + formats.append({ 'url': video_link, 'ext': video_type, From c313d6062c2d61c07287a23853a90817ebfb53ed Mon Sep 17 00:00:00 2001 From: Irfan Charania Date: Sun, 26 Feb 2017 10:53:56 -0800 Subject: [PATCH 3/3] Fix test --- youtube_dl/extractor/tunepk.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/tunepk.py b/youtube_dl/extractor/tunepk.py index dd7984f79..da8801ca5 100644 --- a/youtube_dl/extractor/tunepk.py +++ b/youtube_dl/extractor/tunepk.py @@ -9,12 +9,14 @@ class TunepkIE(InfoExtractor): _VALID_URL = r'(?:https?://|\.)(tune\.pk)/(?:player|video|play)/(?:[\w\.\?]+=)?(?P\d+)' _TEST = { 'url': 'https://tune.pk/video/6919541/maudie-2017-international-trailer-1-ft-ethan-hawke-sally-hawkins', - 'md5': '0C537163B7F6F97DA3C5DD1E3EF6DD55', + 'md5': '0c537163b7f6f97da3c5dd1e3ef6dd55', 'info_dict': { 'id': '6919541', 'ext': 'mp4', 'title': 'Maudie (2017) | International Trailer # 1 ft Ethan Hawke, Sally Hawkins', - 'thumbnail': r're:^https?://.*\.jpg$' + 'thumbnail': r're:^https?://.*\.jpg$', + 'uploader': 'Movie Trailers', + 'description': 'md5:791d36d2c67dca4be5855086a9454dbc' } }