[youporn] Add support for multiple formats

pull/2061/head
Philipp Hagemeister 11 years ago
parent 5ecd3c6a09
commit bfe9de8510

@ -1,5 +1,4 @@
import json import json
import os
import re import re
import sys import sys
@ -16,6 +15,7 @@ from ..aes import (
aes_decrypt_text aes_decrypt_text
) )
class YouPornIE(InfoExtractor): class YouPornIE(InfoExtractor):
_VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>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 = { _TEST = {
@ -71,38 +71,36 @@ class YouPornIE(InfoExtractor):
link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8') link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
links.append(link) links.append(link)
if not links:
raise ExtractorError(u'ERROR: no known formats available for video')
formats = [] formats = []
for link in links: for link in links:
# A link looks like this: # A link looks like this:
# http://cdn1.download.youporn.phncdn.com/201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4?nvb=20121113051249&nva=20121114051249&ir=1200&sr=1200&hash=014b882080310e95fb6a0 # http://cdn1.download.youporn.phncdn.com/201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4?nvb=20121113051249&nva=20121114051249&ir=1200&sr=1200&hash=014b882080310e95fb6a0
# A path looks like this: # A path looks like this:
# /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4 # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
video_url = unescapeHTML(link) video_url = unescapeHTML(link)
path = compat_urllib_parse_urlparse(video_url).path path = compat_urllib_parse_urlparse(video_url).path
extension = os.path.splitext(path)[1][1:] format_parts = path.split('/')[4].split('_')[:2]
format = path.split('/')[4].split('_')[:2]
# size = format[0] dn = compat_urllib_parse_urlparse(video_url).netloc.partition('.')[0]
# bitrate = format[1]
format = "-".join(format) resolution = format_parts[0]
# title = u'%s-%s-%s' % (video_title, size, bitrate) height = int(resolution[:-len('p')])
bitrate = int(format_parts[1][:-len('k')])
format = u'-'.join(format_parts) + u'-' + dn
formats.append({ formats.append({
'url': video_url, 'url': video_url,
'ext': extension,
'format': format, 'format': format,
'format_id': format, 'format_id': format,
'height': height,
'tbr': bitrate,
'resolution': resolution,
}) })
# Sort and remove doubles self._sort_formats(formats)
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 not formats:
if formats[i]['format_id'] == formats[i-1]['format_id']: raise ExtractorError(u'ERROR: no known formats available for video')
del formats[i]
return { return {
'id': video_id, 'id': video_id,

Loading…
Cancel
Save