aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/youporn.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-10-28 10:44:13 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-10-28 10:44:13 +0100
commitebc14f251c2968f4cb6cb18610b857ecb24348c8 (patch)
treed33050d96f576d2a9710ccea7fac729116358025 /youtube_dl/extractor/youporn.py
parentd41e6efc852c34da582790a54ecc4f5e9dbbedda (diff)
parent8ffa13e03e995f2009d8240cbdc6ba7aba9d3759 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'youtube_dl/extractor/youporn.py')
-rw-r--r--youtube_dl/extractor/youporn.py81
1 files changed, 28 insertions, 53 deletions
diff --git a/youtube_dl/extractor/youporn.py b/youtube_dl/extractor/youporn.py
index e3b56cece..e46a9b4d6 100644
--- a/youtube_dl/extractor/youporn.py
+++ b/youtube_dl/extractor/youporn.py
@@ -17,7 +17,7 @@ from ..aes import (
)
class YouPornIE(InfoExtractor):
- _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+)'
+ _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+))'
_TEST = {
u'url': u'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
u'file': u'505835.mp4',
@@ -31,23 +31,10 @@ class YouPornIE(InfoExtractor):
}
}
- def _print_formats(self, formats):
- """Print all available formats"""
- print(u'Available formats:')
- print(u'ext\t\tformat')
- print(u'---------------------------------')
- for format in formats:
- print(u'%s\t\t%s' % (format['ext'], format['format']))
-
- def _specific(self, req_format, formats):
- for x in formats:
- if x["format"] == req_format:
- return x
- return None
-
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('videoid')
+ url = 'http://www.' + mobj.group('url')
req = compat_urllib_request.Request(url)
req.add_header('Cookie', 'age_verified=1')
@@ -71,27 +58,22 @@ class YouPornIE(InfoExtractor):
except KeyError:
raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
- # Get all of the formats available
+ # Get all of the links from the page
DOWNLOAD_LIST_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
webpage, u'download list').strip()
-
- # Get all of the links from the page
- LINK_RE = r'(?s)<a href="(?P<url>[^"]+)">'
+ LINK_RE = r'<a href="([^"]+)">'
links = re.findall(LINK_RE, download_list_html)
-
- # Get link of hd video if available
- mobj = re.search(r'var encryptedQuality720URL = \'(?P<encrypted_video_url>[a-zA-Z0-9+/]+={0,2})\';', webpage)
- if mobj != None:
- encrypted_video_url = mobj.group(u'encrypted_video_url')
- video_url = aes_decrypt_text(encrypted_video_url, video_title, 32).decode('utf-8')
- links = [video_url] + links
+
+ # Get all encrypted links
+ encrypted_links = re.findall(r'var encryptedQuality[0-9]{3}URL = \'([a-zA-Z0-9+/]+={0,2})\';', webpage)
+ for encrypted_link in encrypted_links:
+ link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
+ links.append(link)
if not links:
raise ExtractorError(u'ERROR: no known formats available for video')
- self.to_screen(u'Links found: %d' % len(links))
-
formats = []
for link in links:
@@ -103,39 +85,32 @@ class YouPornIE(InfoExtractor):
path = compat_urllib_parse_urlparse( video_url ).path
extension = os.path.splitext( path )[1][1:]
format = path.split('/')[4].split('_')[:2]
+
# size = format[0]
# bitrate = format[1]
format = "-".join( format )
# title = u'%s-%s-%s' % (video_title, size, bitrate)
formats.append({
- 'id': video_id,
'url': video_url,
- 'uploader': video_uploader,
- 'upload_date': upload_date,
- 'title': video_title,
'ext': extension,
'format': format,
- 'thumbnail': thumbnail,
- 'description': video_description,
- 'age_limit': age_limit,
+ 'format_id': format,
})
- if self._downloader.params.get('listformats', None):
- self._print_formats(formats)
- return
-
- req_format = self._downloader.params.get('format', 'best')
- self.to_screen(u'Format: %s' % req_format)
-
- if req_format is None or req_format == 'best':
- return [formats[0]]
- elif req_format == 'worst':
- return [formats[-1]]
- elif req_format in ('-1', 'all'):
- return formats
- else:
- format = self._specific( req_format, formats )
- if format is None:
- raise ExtractorError(u'Requested format not available')
- return [format]
+ # Sort and remove doubles
+ formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-'))))
+ for i in range(len(formats)-1,0,-1):
+ if formats[i]['format_id'] == formats[i-1]['format_id']:
+ del formats[i]
+
+ return {
+ 'id': video_id,
+ 'uploader': video_uploader,
+ 'upload_date': upload_date,
+ 'title': video_title,
+ 'thumbnail': thumbnail,
+ 'description': video_description,
+ 'age_limit': age_limit,
+ 'formats': formats,
+ }