mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2026-05-26 23:35:20 +00:00
[youtube] add storyboards meta field with list and write options
Storyboards are grids of small images that appear when the user hovers their cursor over a video's timeline. See related issue #9868. Options added: * --list-storyboards * --write-storyboards Co-authored by @benob (See: https://github.com/MarcAbonce/youtube-dl/pull/1)
This commit is contained in:
@@ -226,6 +226,12 @@ class InfoExtractor(object):
|
||||
deprecated)
|
||||
* "filesize" (optional, int)
|
||||
thumbnail: Full URL to a video thumbnail image.
|
||||
storyboards: A list of dictionaries representing storyboards.
|
||||
A storyboard is an image grid made of frames from the video.
|
||||
This has the same structure as the thumbnails list, plus:
|
||||
* "cols" (optional, int)
|
||||
* "rows" (optional, int)
|
||||
* "frames" (optional, int)
|
||||
description: Full video description.
|
||||
uploader: Full name of the video uploader.
|
||||
license: License name the video is licensed under.
|
||||
|
||||
@@ -8,6 +8,7 @@ import os.path
|
||||
import random
|
||||
import re
|
||||
import traceback
|
||||
import math
|
||||
|
||||
from .common import InfoExtractor, SearchInfoExtractor
|
||||
from ..compat import (
|
||||
@@ -1694,6 +1695,58 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
if thumbnail:
|
||||
thumbnails = [{'url': thumbnail}]
|
||||
|
||||
storyboards = []
|
||||
sb_spec = try_get(player_response,
|
||||
lambda x: x['storyboards']['playerStoryboardSpecRenderer']['spec'],
|
||||
compat_str)
|
||||
if sb_spec:
|
||||
s_parts = sb_spec.split('|')
|
||||
base_url = s_parts[0]
|
||||
for i, params in enumerate(s_parts[1:]):
|
||||
storyboard_attrib = params.split('#')
|
||||
if len(storyboard_attrib) != 8:
|
||||
self._downloader.report_warning('Unable to extract storyboard')
|
||||
continue
|
||||
|
||||
frame_width = int_or_none(storyboard_attrib[0])
|
||||
frame_height = int_or_none(storyboard_attrib[1])
|
||||
total_frames = int_or_none(storyboard_attrib[2])
|
||||
cols = int_or_none(storyboard_attrib[3])
|
||||
rows = int_or_none(storyboard_attrib[4])
|
||||
filename = storyboard_attrib[6]
|
||||
sigh = storyboard_attrib[7]
|
||||
|
||||
if frame_width and frame_height and cols and rows and total_frames:
|
||||
frames = cols * rows
|
||||
width, height = frame_width * cols, frame_height * rows
|
||||
n_images = int(math.ceil(total_frames / float(cols * rows)))
|
||||
else:
|
||||
self._downloader.report_warning('Unable to extract storyboard')
|
||||
continue
|
||||
|
||||
storyboards_url = base_url.replace('$L', compat_str(i)) + '&'
|
||||
for j in range(n_images):
|
||||
url = storyboards_url.replace('$N', filename).replace('$M', compat_str(j)) + 'sigh=' + sigh
|
||||
if j == n_images - 1:
|
||||
remaining_frames = total_frames % (cols * rows)
|
||||
if remaining_frames != 0:
|
||||
frames = remaining_frames
|
||||
rows = int(math.ceil(float(remaining_frames) / rows))
|
||||
height = rows * frame_height
|
||||
if rows == 1:
|
||||
cols = remaining_frames
|
||||
width = cols * frame_width
|
||||
|
||||
storyboards.append({
|
||||
'id': 'L{0}-M{1}'.format(i, j),
|
||||
'width': width,
|
||||
'height': height,
|
||||
'cols': cols,
|
||||
'rows': rows,
|
||||
'frames': frames,
|
||||
'url': url
|
||||
})
|
||||
|
||||
category = microformat.get('category') or search_meta('genre')
|
||||
channel_id = video_details.get('channelId') \
|
||||
or microformat.get('externalChannelId') \
|
||||
@@ -1733,6 +1786,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
'categories': [category] if category else None,
|
||||
'tags': keywords,
|
||||
'is_live': is_live,
|
||||
'storyboards': storyboards,
|
||||
}
|
||||
|
||||
pctr = try_get(
|
||||
|
||||
Reference in New Issue
Block a user