mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-15 22:24:32 +01:00
[YouPornIE] Extract all encrypted links and remove doubles at the end
This commit is contained in:
parent
49a25557b0
commit
7df286540f
@ -462,7 +462,7 @@ class YoutubeDL(object):
|
|||||||
info_dict['playlist_index'] = None
|
info_dict['playlist_index'] = None
|
||||||
|
|
||||||
# This extractors handle format selection themselves
|
# This extractors handle format selection themselves
|
||||||
if info_dict['extractor'] in [u'youtube', u'Youku', u'YouPorn', u'mixcloud']:
|
if info_dict['extractor'] in [u'youtube', u'Youku', u'mixcloud']:
|
||||||
if download:
|
if download:
|
||||||
self.process_info(info_dict)
|
self.process_info(info_dict)
|
||||||
return info_dict
|
return info_dict
|
||||||
|
@ -31,20 +31,6 @@ 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):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
video_id = mobj.group('videoid')
|
video_id = mobj.group('videoid')
|
||||||
@ -71,27 +57,22 @@ class YouPornIE(InfoExtractor):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise ExtractorError('Missing JSON parameter: ' + sys.exc_info()[1])
|
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_RE = r'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
|
||||||
download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
|
download_list_html = self._search_regex(DOWNLOAD_LIST_RE,
|
||||||
webpage, u'download list').strip()
|
webpage, u'download list').strip()
|
||||||
|
LINK_RE = r'<a href="([^"]+)">'
|
||||||
# Get all of the links from the page
|
|
||||||
LINK_RE = r'(?s)<a href="(?P<url>[^"]+)">'
|
|
||||||
links = re.findall(LINK_RE, download_list_html)
|
links = re.findall(LINK_RE, download_list_html)
|
||||||
|
|
||||||
# Get link of hd video if available
|
# Get all encrypted links
|
||||||
mobj = re.search(r'var encryptedQuality720URL = \'(?P<encrypted_video_url>[a-zA-Z0-9+/]+={0,2})\';', webpage)
|
encrypted_links = re.findall(r'var encryptedQuality[0-9]{3}URL = \'([a-zA-Z0-9+/]+={0,2})\';', webpage)
|
||||||
if mobj != None:
|
for encrypted_link in encrypted_links:
|
||||||
encrypted_video_url = mobj.group(u'encrypted_video_url')
|
link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
|
||||||
video_url = aes_decrypt_text(encrypted_video_url, video_title, 32).decode('utf-8')
|
links.append(link)
|
||||||
links = [video_url] + links
|
|
||||||
|
|
||||||
if not links:
|
if not links:
|
||||||
raise ExtractorError(u'ERROR: no known formats available for video')
|
raise ExtractorError(u'ERROR: no known formats available for video')
|
||||||
|
|
||||||
self.to_screen(u'Links found: %d' % len(links))
|
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for link in links:
|
for link in links:
|
||||||
|
|
||||||
@ -103,39 +84,32 @@ class YouPornIE(InfoExtractor):
|
|||||||
path = compat_urllib_parse_urlparse( video_url ).path
|
path = compat_urllib_parse_urlparse( video_url ).path
|
||||||
extension = os.path.splitext( path )[1][1:]
|
extension = os.path.splitext( path )[1][1:]
|
||||||
format = path.split('/')[4].split('_')[:2]
|
format = path.split('/')[4].split('_')[:2]
|
||||||
|
|
||||||
# size = format[0]
|
# size = format[0]
|
||||||
# bitrate = format[1]
|
# bitrate = format[1]
|
||||||
format = "-".join( format )
|
format = "-".join( format )
|
||||||
# title = u'%s-%s-%s' % (video_title, size, bitrate)
|
# title = u'%s-%s-%s' % (video_title, size, bitrate)
|
||||||
|
|
||||||
formats.append({
|
formats.append({
|
||||||
'id': video_id,
|
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
|
'ext': extension,
|
||||||
|
'format': format,
|
||||||
|
'format_id': 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,
|
'uploader': video_uploader,
|
||||||
'upload_date': upload_date,
|
'upload_date': upload_date,
|
||||||
'title': video_title,
|
'title': video_title,
|
||||||
'ext': extension,
|
|
||||||
'format': format,
|
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'description': video_description,
|
'description': video_description,
|
||||||
'age_limit': age_limit,
|
'age_limit': age_limit,
|
||||||
})
|
'formats': formats,
|
||||||
|
}
|
||||||
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]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user