mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-03-18 05:52:21 +09:00
Implement format listing and selection for vimeo.
This commit is contained in:
parent
fa343954d4
commit
8534da9840
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import operator
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
@ -50,6 +51,12 @@ class VimeoIE(InfoExtractor):
|
|||||||
u'Verifying the password',
|
u'Verifying the password',
|
||||||
u'Wrong password')
|
u'Wrong password')
|
||||||
|
|
||||||
|
def _print_formats(self, formats):
|
||||||
|
print('Available formats:')
|
||||||
|
width = max([len(f['id']) for f in formats])
|
||||||
|
for f in formats:
|
||||||
|
print('%-*s\t:\t%s' % (width, f['id'], f['ext']))
|
||||||
|
|
||||||
def _real_extract(self, url, new_video=True):
|
def _real_extract(self, url, new_video=True):
|
||||||
# Extract ID from URL
|
# Extract ID from URL
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
@ -112,39 +119,62 @@ class VimeoIE(InfoExtractor):
|
|||||||
|
|
||||||
# Vimeo specific: extract video codec and quality information
|
# Vimeo specific: extract video codec and quality information
|
||||||
# First consider quality, then codecs, then take everything
|
# First consider quality, then codecs, then take everything
|
||||||
# TODO bind to format param
|
|
||||||
codecs = [('h264', 'mp4'), ('vp8', 'flv'), ('vp6', 'flv')]
|
codecs = [('h264', 'mp4'), ('vp8', 'flv'), ('vp6', 'flv')]
|
||||||
files = { 'hd': [], 'sd': [], 'other': []}
|
files = { 'hd': [], 'sd': [], 'other': []}
|
||||||
for codec_name, codec_extension in codecs:
|
for codec_name, codec_extension in codecs:
|
||||||
if codec_name in config["video"]["files"]:
|
for quality in config["video"]["files"].get(codec_name, []):
|
||||||
if 'hd' in config["video"]["files"][codec_name]:
|
format_id = '-'.join((codec_name, quality)).lower()
|
||||||
files['hd'].append((codec_name, codec_extension, 'hd'))
|
key = quality if quality in files else 'other'
|
||||||
elif 'sd' in config["video"]["files"][codec_name]:
|
files[key].append({
|
||||||
files['sd'].append((codec_name, codec_extension, 'sd'))
|
'codec': codec_name,
|
||||||
else:
|
'ext': codec_extension,
|
||||||
files['other'].append((codec_name, codec_extension, config["video"]["files"][codec_name][0]))
|
'quality': quality,
|
||||||
|
'id': format_id,
|
||||||
for quality in ('hd', 'sd', 'other'):
|
})
|
||||||
if len(files[quality]) > 0:
|
formats = reduce(operator.add,
|
||||||
video_quality = files[quality][0][2]
|
[files[q] for q in ('hd', 'sd', 'other')])
|
||||||
video_codec = files[quality][0][0]
|
if len(formats) == 0:
|
||||||
video_extension = files[quality][0][1]
|
|
||||||
self.to_screen(u'%s: Downloading %s file at %s quality' % (video_id, video_codec.upper(), video_quality))
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ExtractorError(u'No known codec found')
|
raise ExtractorError(u'No known codec found')
|
||||||
|
|
||||||
video_url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
|
if self._downloader.params.get('listformats', None):
|
||||||
%(video_id, sig, timestamp, video_quality, video_codec.upper())
|
self._print_formats(formats)
|
||||||
|
return
|
||||||
|
|
||||||
return [{
|
# Decide which formats to download
|
||||||
|
req_format = self._downloader.params.get('format', None)
|
||||||
|
if req_format is None or req_format == 'best':
|
||||||
|
req_format_list = [formats[0]] # Best quality
|
||||||
|
elif req_format == 'worst':
|
||||||
|
req_format_list = [formats[-1]] # worst quality (maybe?)
|
||||||
|
elif req_format in ('-1', 'all'):
|
||||||
|
req_format_list = formats # All formats
|
||||||
|
else:
|
||||||
|
# Specific formats. We pick the first in a slash-delimeted sequence.
|
||||||
|
# For example, if '1/2/3/4' is requested and '2' and '4' are available, we pick '2'.
|
||||||
|
req_formats = req_format.lower().split('/')
|
||||||
|
format_map = dict([(c['id'], c) for c in formats])
|
||||||
|
req_format_list = None
|
||||||
|
for rf in req_formats:
|
||||||
|
if rf in format_map:
|
||||||
|
req_format_list = [format_map[rf]]
|
||||||
|
break
|
||||||
|
if req_format_list is None:
|
||||||
|
raise ExtractorError(u'requested format not available')
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for format in req_format_list:
|
||||||
|
video_url = "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
|
||||||
|
%(video_id, sig, timestamp, format['quality'], format['codec'].upper())
|
||||||
|
results.append({
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'uploader': video_uploader,
|
'uploader': video_uploader,
|
||||||
'uploader_id': video_uploader_id,
|
'uploader_id': video_uploader_id,
|
||||||
'upload_date': video_upload_date,
|
'upload_date': video_upload_date,
|
||||||
'title': video_title,
|
'title': video_title,
|
||||||
'ext': video_extension,
|
'ext': format['ext'],
|
||||||
|
'format': format['id'],
|
||||||
'thumbnail': video_thumbnail,
|
'thumbnail': video_thumbnail,
|
||||||
'description': video_description,
|
'description': video_description,
|
||||||
}]
|
})
|
||||||
|
return results
|
||||||
|
Loading…
Reference in New Issue
Block a user