From 1dba4a2185dda37fb4c22e65f5115abfea32e38e Mon Sep 17 00:00:00 2001 From: peugeot Date: Wed, 3 Sep 2014 14:10:06 +0200 Subject: [PATCH 1/4] Add support for TNAFlix --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/tnaflix.py | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 youtube_dl/extractor/tnaflix.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 6c7668fe2..ff5b9a29e 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -348,6 +348,7 @@ from .thisav import ThisAVIE from .tinypic import TinyPicIE from .tlc import TlcIE, TlcDeIE +from .tnaflix import TNAFlixIE from .toutv import TouTvIE from .toypics import ToypicsUserIE, ToypicsIE from .traileraddict import TrailerAddictIE diff --git a/youtube_dl/extractor/tnaflix.py b/youtube_dl/extractor/tnaflix.py new file mode 100644 index 000000000..078e55483 --- /dev/null +++ b/youtube_dl/extractor/tnaflix.py @@ -0,0 +1,68 @@ +from __future__ import unicode_literals + +import re + +from .common import InfoExtractor +from ..utils import ( + parse_duration, + str_to_int, +) + +class TNAFlixIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/(?P[\w-]+)/(?P[\w-]+)/video(?P\d+)' + _TEST = { + 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878', + 'md5': 'ecf3498417d09216374fc5907f9c6ec0', + 'info_dict': { + 'id': '553878', + 'display_id': 'Carmella-Decesare-striptease', + 'ext': 'mp4', + 'title': 'Carmella Decesare - striptease', + 'thumbnail': 're:https?://.*\.jpg$', + #'duration': 84, + 'age_limit': 18, + } + } + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + video_id = mobj.group('id') + display_id = mobj.group('display_id') + + webpage = self._download_webpage(url, display_id) + + redir_url = self._html_search_regex( + r'flashvars.config = escape\("([^"]+)"', webpage, 'redirection URL') + redirection_webpage = self._download_webpage(redir_url, display_id) + sources = self._search_regex( + r'(.+)', redirection_webpage, 'sources', flags=re.MULTILINE|re.DOTALL) + + formats = [] + for format_id, video_url in re.findall(r'([^<]+)\s*([^<]+)', sources, flags=re.MULTILINE|re.DOTALL): + fmt = { + 'url': video_url, + 'format_id': format_id, + } + m = re.search(r'^(\d+)', format_id) + if m: + fmt['height'] = int(m.group(1)) + formats.append(fmt) + self._sort_formats(formats) + + title = self._og_search_title(webpage) + + #duration = self._html_search_regex(r' Date: Wed, 3 Sep 2014 21:03:36 +0700 Subject: [PATCH 2/4] [utils] Make parse_duration case insensitive --- youtube_dl/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 91afe8622..3846dfdca 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1336,7 +1336,7 @@ def parse_duration(s): s = s.strip() m = re.match( - r'(?:(?:(?P[0-9]+)\s*(?:[:h]|hours?)\s*)?(?P[0-9]+)\s*(?:[:m]|mins?|minutes?)\s*)?(?P[0-9]+)(?P\.[0-9]+)?\s*(?:s|secs?|seconds?)?$', s) + r'(?i)(?:(?:(?P[0-9]+)\s*(?:[:h]|hours?)\s*)?(?P[0-9]+)\s*(?:[:m]|mins?|minutes?)\s*)?(?P[0-9]+)(?P\.[0-9]+)?\s*(?:s|secs?|seconds?)?$', s) if not m: return None res = int(m.group('secs')) From eb833b7f5a0d92e89095fff236e1b6bf1d1742de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 3 Sep 2014 21:07:18 +0700 Subject: [PATCH 3/4] [tnaflix] Improve and make generic --- youtube_dl/extractor/tnaflix.py | 56 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/youtube_dl/extractor/tnaflix.py b/youtube_dl/extractor/tnaflix.py index 078e55483..4956f8577 100644 --- a/youtube_dl/extractor/tnaflix.py +++ b/youtube_dl/extractor/tnaflix.py @@ -5,11 +5,17 @@ from .common import InfoExtractor from ..utils import ( parse_duration, - str_to_int, + fix_xml_ampersands, ) + class TNAFlixIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/(?P[\w-]+)/(?P[\w-]+)/video(?P\d+)' + + _TITLE_REGEX = None + _DESCRIPTION_REGEX = r'

([^<]+)

' + _CONFIG_REGEX = r'flashvars\.config\s*=\s*escape\("([^"]+)"' + _TEST = { 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878', 'md5': 'ecf3498417d09216374fc5907f9c6ec0', @@ -18,8 +24,9 @@ class TNAFlixIE(InfoExtractor): 'display_id': 'Carmella-Decesare-striptease', 'ext': 'mp4', 'title': 'Carmella Decesare - striptease', + 'description': '', 'thumbnail': 're:https?://.*\.jpg$', - #'duration': 84, + 'duration': 91, 'age_limit': 18, } } @@ -31,14 +38,30 @@ def _real_extract(self, url): webpage = self._download_webpage(url, display_id) - redir_url = self._html_search_regex( - r'flashvars.config = escape\("([^"]+)"', webpage, 'redirection URL') - redirection_webpage = self._download_webpage(redir_url, display_id) - sources = self._search_regex( - r'(.+)', redirection_webpage, 'sources', flags=re.MULTILINE|re.DOTALL) - + title = self._html_search_regex( + self._TITLE_REGEX, webpage, 'title') if self._TITLE_REGEX else self._og_search_title(webpage) + description = self._html_search_regex( + self._DESCRIPTION_REGEX, webpage, 'description', fatal=False, default='') + + age_limit = self._rta_search(webpage) + + duration = self._html_search_meta('duration', webpage, 'duration', default=None) + if duration: + duration = parse_duration(duration[1:]) + + cfg_url = self._html_search_regex( + self._CONFIG_REGEX, webpage, 'flashvars.config') + + cfg_xml = self._download_xml( + cfg_url, display_id, note='Downloading metadata', + transform_source=fix_xml_ampersands) + + thumbnail = cfg_xml.find('./startThumb').text + formats = [] - for format_id, video_url in re.findall(r'([^<]+)\s*([^<]+)', sources, flags=re.MULTILINE|re.DOTALL): + for item in cfg_xml.findall('./quality/item'): + video_url = re.sub('speed=\d+', 'speed=', item.find('videoLink').text) + format_id = item.find('res').text fmt = { 'url': video_url, 'format_id': format_id, @@ -49,20 +72,13 @@ def _real_extract(self, url): formats.append(fmt) self._sort_formats(formats) - title = self._og_search_title(webpage) - - #duration = self._html_search_regex(r' Date: Wed, 3 Sep 2014 21:08:36 +0700 Subject: [PATCH 4/4] [empflix] Rewrite in terms of tnaflix --- youtube_dl/extractor/__init__.py | 2 +- youtube_dl/extractor/empflix.py | 53 ++++++-------------------------- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index ff5b9a29e..d54ad8057 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -86,7 +86,7 @@ EllenTVClipsIE, ) from .elpais import ElPaisIE -from .empflix import EmpflixIE +from .empflix import EMPFlixIE from .engadget import EngadgetIE from .eporner import EpornerIE from .escapist import EscapistIE diff --git a/youtube_dl/extractor/empflix.py b/youtube_dl/extractor/empflix.py index 1c498d8c8..70f8efe27 100644 --- a/youtube_dl/extractor/empflix.py +++ b/youtube_dl/extractor/empflix.py @@ -1,58 +1,25 @@ from __future__ import unicode_literals -import re - -from .common import InfoExtractor -from ..utils import fix_xml_ampersands +from .tnaflix import TNAFlixIE -class EmpflixIE(InfoExtractor): - _VALID_URL = r'^https?://www\.empflix\.com/videos/.*?-(?P[0-9]+)\.html' +class EMPFlixIE(TNAFlixIE): + _VALID_URL = r'^https?://www\.empflix\.com/videos/(?P[0-9a-zA-Z-]+)-(?P[0-9]+)\.html' + + _TITLE_REGEX = r'name="title" value="(?P[^"]*)"' + _DESCRIPTION_REGEX = r'name="description" value="([^"]*)"' + _CONFIG_REGEX = r'flashvars\.config\s*=\s*escape\("([^"]+)"' + _TEST = { 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html', 'md5': 'b1bc15b6412d33902d6e5952035fcabc', 'info_dict': { 'id': '33051', + 'display_id': 'Amateur-Finger-Fuck', 'ext': 'mp4', 'title': 'Amateur Finger Fuck', 'description': 'Amateur solo finger fucking.', + 'thumbnail': 're:https?://.*\.jpg$', 'age_limit': 18, } } - - def _real_extract(self, url): - mobj = re.match(self._VALID_URL, url) - video_id = mobj.group('id') - - webpage = self._download_webpage(url, video_id) - age_limit = self._rta_search(webpage) - - video_title = self._html_search_regex( - r'name="title" value="(?P<title>[^"]*)"', webpage, 'title') - video_description = self._html_search_regex( - r'name="description" value="([^"]*)"', webpage, 'description', fatal=False) - - cfg_url = self._html_search_regex( - r'flashvars\.config = escape\("([^"]+)"', - webpage, 'flashvars.config') - - cfg_xml = self._download_xml( - cfg_url, video_id, note='Downloading metadata', - transform_source=fix_xml_ampersands) - - formats = [ - { - 'url': item.find('videoLink').text, - 'format_id': item.find('res').text, - } for item in cfg_xml.findall('./quality/item') - ] - thumbnail = cfg_xml.find('./startThumb').text - - return { - 'id': video_id, - 'title': video_title, - 'description': video_description, - 'thumbnail': thumbnail, - 'formats': formats, - 'age_limit': age_limit, - }