mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-07 20:30:41 -05:00
[extractor] Add convinience function _yes_playlist
This commit is contained in:
parent
1f13021eca
commit
f40ee5e9a0
12 changed files with 49 additions and 87 deletions
|
@ -300,11 +300,10 @@ def _real_extract(self, url):
|
||||||
unescapeHTML(webpage_data).encode('utf-8').decode('unicode_escape'), show_id)
|
unescapeHTML(webpage_data).encode('utf-8').decode('unicode_escape'), show_id)
|
||||||
video_data = video_data['route']['pageData']['_embedded']
|
video_data = video_data['route']['pageData']['_embedded']
|
||||||
|
|
||||||
if self.get_param('noplaylist') and 'highlightVideo' in video_data:
|
highlight = try_get(video_data, lambda x: ['highlightVideo']['shareUrl'])
|
||||||
self.to_screen('Downloading just the highlight video because of --no-playlist')
|
if not self._yes_playlist(show_id, bool(highlight), video_label='highlight video'):
|
||||||
return self.url_result(video_data['highlightVideo']['shareUrl'], ie=ABCIViewIE.ie_key())
|
return self.url_result(highlight, ie=ABCIViewIE.ie_key())
|
||||||
|
|
||||||
self.to_screen(f'Downloading playlist {show_id} - add --no-playlist to just download the highlight video')
|
|
||||||
series = video_data['selectedSeries']
|
series = video_data['selectedSeries']
|
||||||
return {
|
return {
|
||||||
'_type': 'playlist',
|
'_type': 'playlist',
|
||||||
|
|
|
@ -3710,6 +3710,22 @@ def _configuration_arg(self, key, default=NO_DEFAULT, *, ie_key=None, casesense=
|
||||||
return [] if default is NO_DEFAULT else default
|
return [] if default is NO_DEFAULT else default
|
||||||
return list(val) if casesense else [x.lower() for x in val]
|
return list(val) if casesense else [x.lower() for x in val]
|
||||||
|
|
||||||
|
def _yes_playlist(self, playlist_id, video_id, smuggled_data=None, *, playlist_label='playlist', video_label='video'):
|
||||||
|
if not playlist_id or not video_id:
|
||||||
|
return not video_id
|
||||||
|
|
||||||
|
no_playlist = (smuggled_data or {}).get('force_noplaylist')
|
||||||
|
if no_playlist is not None:
|
||||||
|
return not no_playlist
|
||||||
|
|
||||||
|
video_id = '' if video_id is True else f' {video_id}'
|
||||||
|
playlist_id = '' if playlist_id is True else f' {playlist_id}'
|
||||||
|
if self.get_param('noplaylist'):
|
||||||
|
self.to_screen(f'Downloading just the {video_label}{video_id} because of --no-playlist')
|
||||||
|
return False
|
||||||
|
self.to_screen(f'Downloading {playlist_label}{playlist_id} - add --no-playlist to download just the {video_label}{video_id}')
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class SearchInfoExtractor(InfoExtractor):
|
class SearchInfoExtractor(InfoExtractor):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -207,12 +207,10 @@ def _real_extract(self, url):
|
||||||
video_id, playlist_id = self._match_valid_url(url).groups()
|
video_id, playlist_id = self._match_valid_url(url).groups()
|
||||||
|
|
||||||
if playlist_id:
|
if playlist_id:
|
||||||
if not self.get_param('noplaylist'):
|
if self._yes_playlist(playlist_id, video_id):
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % playlist_id)
|
|
||||||
return self.url_result(
|
return self.url_result(
|
||||||
'http://www.dailymotion.com/playlist/' + playlist_id,
|
'http://www.dailymotion.com/playlist/' + playlist_id,
|
||||||
'DailymotionPlaylist', playlist_id)
|
'DailymotionPlaylist', playlist_id)
|
||||||
self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
|
|
||||||
|
|
||||||
password = self.get_param('videopassword')
|
password = self.get_param('videopassword')
|
||||||
media = self._call_api(
|
media = self._call_api(
|
||||||
|
|
|
@ -157,11 +157,8 @@ def _check_clip(self, url, list_id):
|
||||||
query_dict = parse_qs(url)
|
query_dict = parse_qs(url)
|
||||||
if 'clipid' in query_dict:
|
if 'clipid' in query_dict:
|
||||||
clip_id = query_dict['clipid'][0]
|
clip_id = query_dict['clipid'][0]
|
||||||
if self.get_param('noplaylist'):
|
if not self._yes_playlist(list_id, clip_id):
|
||||||
self.to_screen('Downloading just video %s because of --no-playlist' % clip_id)
|
|
||||||
return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip')
|
return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip')
|
||||||
else:
|
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % list_id)
|
|
||||||
|
|
||||||
|
|
||||||
class DaumPlaylistIE(DaumListIE):
|
class DaumPlaylistIE(DaumListIE):
|
||||||
|
|
|
@ -64,10 +64,7 @@ def _real_extract(self, url):
|
||||||
domain, media_type, media_id, playlist_id = self._match_valid_url(url).groups()
|
domain, media_type, media_id, playlist_id = self._match_valid_url(url).groups()
|
||||||
|
|
||||||
if playlist_id:
|
if playlist_id:
|
||||||
if self.get_param('noplaylist'):
|
if self._yes_playlist(playlist_id, media_id):
|
||||||
self.to_screen('Downloading just video %s because of --no-playlist' % media_id)
|
|
||||||
else:
|
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % playlist_id)
|
|
||||||
media_type, media_id = 'playlist', playlist_id
|
media_type, media_id = 'playlist', playlist_id
|
||||||
|
|
||||||
if media_type == 'playlist':
|
if media_type == 'playlist':
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
traverse_obj,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
unsmuggle_url,
|
unsmuggle_url,
|
||||||
)
|
)
|
||||||
|
@ -55,9 +56,6 @@ def _extract_playlist(self, season_list, video_id, program_info, prompt=True):
|
||||||
episode_title = program_info['title']
|
episode_title = program_info['title']
|
||||||
content_id = season_list['contentId']
|
content_id = season_list['contentId']
|
||||||
|
|
||||||
if prompt:
|
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video %s' % (content_id, video_id))
|
|
||||||
|
|
||||||
all_episodes = [
|
all_episodes = [
|
||||||
self.url_result(smuggle_url(
|
self.url_result(smuggle_url(
|
||||||
self._URL_TEMPLATE % (program_info['contentType'], episode['contentId']),
|
self._URL_TEMPLATE % (program_info['contentType'], episode['contentId']),
|
||||||
|
@ -71,12 +69,6 @@ def _real_extract(self, url):
|
||||||
|
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
noplaylist = self.get_param('noplaylist')
|
|
||||||
noplaylist_prompt = True
|
|
||||||
if 'force_noplaylist' in data:
|
|
||||||
noplaylist = data['force_noplaylist']
|
|
||||||
noplaylist_prompt = False
|
|
||||||
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
program_info = self._parse_json(self._search_regex(
|
program_info = self._parse_json(self._search_regex(
|
||||||
|
@ -84,14 +76,9 @@ def _real_extract(self, url):
|
||||||
video_id)
|
video_id)
|
||||||
|
|
||||||
season_list = list(program_info.get('seasonList', {}).values())
|
season_list = list(program_info.get('seasonList', {}).values())
|
||||||
if season_list:
|
playlist_id = traverse_obj(season_list, 0, 'contentId')
|
||||||
if not noplaylist:
|
if self._yes_playlist(playlist_id, video_id, smuggled_data):
|
||||||
return self._extract_playlist(
|
return self._extract_playlist(season_list[0], video_id, program_info)
|
||||||
season_list[0], video_id, program_info,
|
|
||||||
prompt=noplaylist_prompt)
|
|
||||||
|
|
||||||
if noplaylist_prompt:
|
|
||||||
self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
|
|
||||||
|
|
||||||
# In browsers `getMainUrl` request is always issued. Usually this
|
# In browsers `getMainUrl` request is always issued. Usually this
|
||||||
# endpoint gives the same result as the data embedded in the webpage.
|
# endpoint gives the same result as the data embedded in the webpage.
|
||||||
|
|
|
@ -165,14 +165,10 @@ class NBAWatchIE(NBAWatchBaseIE):
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
collection_id = parse_qs(url).get('collection', [None])[0]
|
collection_id = parse_qs(url).get('collection', [None])[0]
|
||||||
if collection_id:
|
if self._yes_playlist(collection_id, display_id):
|
||||||
if self.get_param('noplaylist'):
|
return self.url_result(
|
||||||
self.to_screen('Downloading just video %s because of --no-playlist' % display_id)
|
'https://www.nba.com/watch/list/collection/' + collection_id,
|
||||||
else:
|
NBAWatchCollectionIE.ie_key(), collection_id)
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % collection_id)
|
|
||||||
return self.url_result(
|
|
||||||
'https://www.nba.com/watch/list/collection/' + collection_id,
|
|
||||||
NBAWatchCollectionIE.ie_key(), collection_id)
|
|
||||||
return self._extract_video('seoName', display_id)
|
return self._extract_video('seoName', display_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -405,17 +405,12 @@ def _real_extract(self, url):
|
||||||
name = info['name']
|
name = info['name']
|
||||||
description = info['description']
|
description = info['description']
|
||||||
|
|
||||||
if not info['songs'] or self.get_param('noplaylist'):
|
if not self._yes_playlist(info['songs'] and program_id, info['mainSong']['id']):
|
||||||
if info['songs']:
|
|
||||||
self.to_screen(
|
|
||||||
'Downloading just the main audio %s because of --no-playlist'
|
|
||||||
% info['mainSong']['id'])
|
|
||||||
|
|
||||||
formats = self.extract_formats(info['mainSong'])
|
formats = self.extract_formats(info['mainSong'])
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': program_id,
|
'id': info['mainSong']['id'],
|
||||||
'title': name,
|
'title': name,
|
||||||
'description': description,
|
'description': description,
|
||||||
'creator': info['dj']['brand'],
|
'creator': info['dj']['brand'],
|
||||||
|
@ -425,10 +420,6 @@ def _real_extract(self, url):
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.to_screen(
|
|
||||||
'Downloading playlist %s - add --no-playlist to just download the main audio %s'
|
|
||||||
% (program_id, info['mainSong']['id']))
|
|
||||||
|
|
||||||
song_ids = [info['mainSong']['id']]
|
song_ids = [info['mainSong']['id']]
|
||||||
song_ids.extend([song['id'] for song in info['songs']])
|
song_ids.extend([song['id'] for song in info['songs']])
|
||||||
entries = [
|
entries = [
|
||||||
|
|
|
@ -182,14 +182,9 @@ def _real_extract(self, url):
|
||||||
video_id = remove_start(current_clip_info['ckmId'], 'mvp:')
|
video_id = remove_start(current_clip_info['ckmId'], 'mvp:')
|
||||||
video_name = url_basename(current_clip_info['url'])
|
video_name = url_basename(current_clip_info['url'])
|
||||||
|
|
||||||
if self.get_param('noplaylist'):
|
if not self._yes_playlist(channel_id, video_name, playlist_label='channel'):
|
||||||
self.to_screen(
|
|
||||||
'Downloading just video %s because of --no-playlist' % video_name)
|
|
||||||
return self._extract_from_id(video_id, webpage)
|
return self._extract_from_id(video_id, webpage)
|
||||||
|
|
||||||
self.to_screen(
|
|
||||||
'Downloading channel %s - add --no-playlist to just download video %s' % (
|
|
||||||
channel_id, video_name))
|
|
||||||
matches = re.findall(
|
matches = re.findall(
|
||||||
r'<a[^>]+href=[\'"](%s[a-z]+/[0-9a-z-]+/[0-9a-z]+)' % self._URL_BASE_RE,
|
r'<a[^>]+href=[\'"](%s[a-z]+/[0-9a-z-]+/[0-9a-z]+)' % self._URL_BASE_RE,
|
||||||
webpage)
|
webpage)
|
||||||
|
|
|
@ -59,12 +59,8 @@ def _real_extract(self, url):
|
||||||
videos = asset.get('videos') or []
|
videos = asset.get('videos') or []
|
||||||
if len(videos) > 1:
|
if len(videos) > 1:
|
||||||
playlist_id = parse_qs(url).get('playlistId', [None])[0]
|
playlist_id = parse_qs(url).get('playlistId', [None])[0]
|
||||||
if playlist_id:
|
if not self._yes_playlist(playlist_id, asset_id):
|
||||||
if self.get_param('noplaylist'):
|
videos = [videos[int(playlist_id)]]
|
||||||
videos = [videos[int(playlist_id)]]
|
|
||||||
self.to_screen('Downloading just a single video because of --no-playlist')
|
|
||||||
else:
|
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % asset_id)
|
|
||||||
|
|
||||||
def entries():
|
def entries():
|
||||||
for i, video in enumerate(videos, 1):
|
for i, video in enumerate(videos, 1):
|
||||||
|
|
|
@ -287,8 +287,7 @@ def _real_extract(self, url):
|
||||||
raise ExtractorError('This video is not available in your region.', expected=True)
|
raise ExtractorError('This video is not available in your region.', expected=True)
|
||||||
|
|
||||||
series_id = video_data.get('series_id')
|
series_id = video_data.get('series_id')
|
||||||
if not self.get_param('noplaylist') and not idata.get('force_noplaylist'):
|
if self._yes_playlist(series_id, video_id, idata):
|
||||||
self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % series_id)
|
|
||||||
series = product_data.get('series', {})
|
series = product_data.get('series', {})
|
||||||
product = series.get('product')
|
product = series.get('product')
|
||||||
if product:
|
if product:
|
||||||
|
@ -308,9 +307,6 @@ def _real_extract(self, url):
|
||||||
|
|
||||||
return self.playlist_result(entries, series_id, series.get('name'), series.get('description'))
|
return self.playlist_result(entries, series_id, series.get('name'), series.get('description'))
|
||||||
|
|
||||||
if self.get_param('noplaylist'):
|
|
||||||
self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
|
|
||||||
|
|
||||||
duration_limit = False
|
duration_limit = False
|
||||||
query = {
|
query = {
|
||||||
'ccs_product_id': video_data['ccs_product_id'],
|
'ccs_product_id': video_data['ccs_product_id'],
|
||||||
|
|
|
@ -146,30 +146,24 @@ def _real_extract(self, url):
|
||||||
'post/v1.0/officialVideoPost-%s', video_id,
|
'post/v1.0/officialVideoPost-%s', video_id,
|
||||||
'author{nickname},channel{channelCode,channelName},officialVideo{commentCount,exposeStatus,likeCount,playCount,playTime,status,title,type,vodId},playlist{playlistSeq,totalCount,name}')
|
'author{nickname},channel{channelCode,channelName},officialVideo{commentCount,exposeStatus,likeCount,playCount,playTime,status,title,type,vodId},playlist{playlistSeq,totalCount,name}')
|
||||||
|
|
||||||
playlist = post.get('playlist')
|
playlist_id = str_or_none(try_get(post, lambda x: x['playlist']['playlistSeq']))
|
||||||
if not playlist or self.get_param('noplaylist'):
|
if not self._yes_playlist(playlist_id, video_id):
|
||||||
if playlist:
|
|
||||||
self.to_screen(
|
|
||||||
'Downloading just video %s because of --no-playlist'
|
|
||||||
% video_id)
|
|
||||||
|
|
||||||
video = post['officialVideo']
|
video = post['officialVideo']
|
||||||
return self._get_vlive_info(post, video, video_id)
|
return self._get_vlive_info(post, video, video_id)
|
||||||
else:
|
|
||||||
playlist_name = playlist.get('name')
|
|
||||||
playlist_id = str_or_none(playlist.get('playlistSeq'))
|
|
||||||
playlist_count = str_or_none(playlist.get('totalCount'))
|
|
||||||
|
|
||||||
playlist = self._call_api(
|
playlist_name = str_or_none(try_get(post, lambda x: x['playlist']['name']))
|
||||||
'playlist/v1.0/playlist-%s/posts', playlist_id, 'data', {'limit': playlist_count})
|
playlist_count = str_or_none(try_get(post, lambda x: x['playlist']['totalCount']))
|
||||||
|
|
||||||
entries = []
|
playlist = self._call_api(
|
||||||
for video_data in playlist['data']:
|
'playlist/v1.0/playlist-%s/posts', playlist_id, 'data', {'limit': playlist_count})
|
||||||
video = video_data.get('officialVideo')
|
|
||||||
video_id = str_or_none(video.get('videoSeq'))
|
|
||||||
entries.append(self._get_vlive_info(video_data, video, video_id))
|
|
||||||
|
|
||||||
return self.playlist_result(entries, playlist_id, playlist_name)
|
entries = []
|
||||||
|
for video_data in playlist['data']:
|
||||||
|
video = video_data.get('officialVideo')
|
||||||
|
video_id = str_or_none(video.get('videoSeq'))
|
||||||
|
entries.append(self._get_vlive_info(video_data, video, video_id))
|
||||||
|
|
||||||
|
return self.playlist_result(entries, playlist_id, playlist_name)
|
||||||
|
|
||||||
def _get_vlive_info(self, post, video, video_id):
|
def _get_vlive_info(self, post, video, video_id):
|
||||||
def get_common_fields():
|
def get_common_fields():
|
||||||
|
|
Loading…
Reference in a new issue