mirror of https://github.com/yt-dlp/yt-dlp.git
Compare commits
14 Commits
b3b90f2569
...
3001fb031c
Author | SHA1 | Date |
---|---|---|
HobbyistDev | 3001fb031c | |
sepro | 96da952504 | |
HobbyistDev | eecd76dd92 | |
HobbyistDev | 24e83cf661 | |
HobbyistDev | bcda65fcc5 | |
HobbyistDev | 31c45e0dfd | |
HobbyistDev | 0b9fc25be6 | |
HobbyistDev | 6c6ad3298d | |
HobbyistDev | c895dfea10 | |
HobbyistDev | 05648c4fe9 | |
HobbyistDev | 27a6f8330b | |
HobbyistDev | aa2dda16cd | |
HobbyistDev | 8f2567f048 | |
HobbyistDev | 363f6b3029 |
|
@ -2136,6 +2136,11 @@ class YoutubeDL:
|
||||||
|
|
||||||
def _check_formats(self, formats):
|
def _check_formats(self, formats):
|
||||||
for f in formats:
|
for f in formats:
|
||||||
|
working = f.get('__working')
|
||||||
|
if working is not None:
|
||||||
|
if working:
|
||||||
|
yield f
|
||||||
|
continue
|
||||||
self.to_screen('[info] Testing format %s' % f['format_id'])
|
self.to_screen('[info] Testing format %s' % f['format_id'])
|
||||||
path = self.get_output_path('temp')
|
path = self.get_output_path('temp')
|
||||||
if not self._ensure_dir_exists(f'{path}/'):
|
if not self._ensure_dir_exists(f'{path}/'):
|
||||||
|
@ -2152,33 +2157,44 @@ class YoutubeDL:
|
||||||
os.remove(temp_file.name)
|
os.remove(temp_file.name)
|
||||||
except OSError:
|
except OSError:
|
||||||
self.report_warning('Unable to delete temporary file "%s"' % temp_file.name)
|
self.report_warning('Unable to delete temporary file "%s"' % temp_file.name)
|
||||||
|
f['__working'] = success
|
||||||
if success:
|
if success:
|
||||||
yield f
|
yield f
|
||||||
else:
|
else:
|
||||||
self.to_screen('[info] Unable to download format %s. Skipping...' % f['format_id'])
|
self.to_screen('[info] Unable to download format %s. Skipping...' % f['format_id'])
|
||||||
|
|
||||||
|
def _select_formats(self, formats, selector):
|
||||||
|
return list(selector({
|
||||||
|
'formats': formats,
|
||||||
|
'has_merged_format': any('none' not in (f.get('acodec'), f.get('vcodec')) for f in formats),
|
||||||
|
'incomplete_formats': (all(f.get('vcodec') == 'none' for f in formats) # No formats with video
|
||||||
|
or all(f.get('acodec') == 'none' for f in formats)), # OR, No formats with audio
|
||||||
|
}))
|
||||||
|
|
||||||
def _default_format_spec(self, info_dict, download=True):
|
def _default_format_spec(self, info_dict, download=True):
|
||||||
|
download = download and not self.params.get('simulate')
|
||||||
|
prefer_best = download and (
|
||||||
|
self.params['outtmpl']['default'] == '-'
|
||||||
|
or info_dict.get('is_live') and not self.params.get('live_from_start'))
|
||||||
|
|
||||||
def can_merge():
|
def can_merge():
|
||||||
merger = FFmpegMergerPP(self)
|
merger = FFmpegMergerPP(self)
|
||||||
return merger.available and merger.can_merge()
|
return merger.available and merger.can_merge()
|
||||||
|
|
||||||
prefer_best = (
|
if not prefer_best and download and not can_merge():
|
||||||
not self.params.get('simulate')
|
prefer_best = True
|
||||||
and download
|
formats = self._get_formats(info_dict)
|
||||||
and (
|
evaluate_formats = lambda spec: self._select_formats(formats, self.build_format_selector(spec))
|
||||||
not can_merge()
|
if evaluate_formats('b/bv+ba') != evaluate_formats('bv*+ba/b'):
|
||||||
or info_dict.get('is_live') and not self.params.get('live_from_start')
|
self.report_warning('ffmpeg not found. The downloaded format may not be the best available. '
|
||||||
or self.params['outtmpl']['default'] == '-'))
|
'Installing ffmpeg is strongly recommended: https://github.com/yt-dlp/yt-dlp#dependencies')
|
||||||
compat = (
|
|
||||||
prefer_best
|
|
||||||
or self.params.get('allow_multiple_audio_streams', False)
|
|
||||||
or 'format-spec' in self.params['compat_opts'])
|
|
||||||
|
|
||||||
return (
|
compat = (self.params.get('allow_multiple_audio_streams')
|
||||||
'best/bestvideo+bestaudio' if prefer_best
|
or 'format-spec' in self.params['compat_opts'])
|
||||||
else 'bestvideo*+bestaudio/best' if not compat
|
|
||||||
else 'bestvideo+bestaudio/best')
|
return ('best/bestvideo+bestaudio' if prefer_best
|
||||||
|
else 'bestvideo+bestaudio/best' if compat
|
||||||
|
else 'bestvideo*+bestaudio/best')
|
||||||
|
|
||||||
def build_format_selector(self, format_spec):
|
def build_format_selector(self, format_spec):
|
||||||
def syntax_error(note, start):
|
def syntax_error(note, start):
|
||||||
|
@ -2928,12 +2944,7 @@ class YoutubeDL:
|
||||||
self.write_debug(f'Default format spec: {req_format}')
|
self.write_debug(f'Default format spec: {req_format}')
|
||||||
format_selector = self.build_format_selector(req_format)
|
format_selector = self.build_format_selector(req_format)
|
||||||
|
|
||||||
formats_to_download = list(format_selector({
|
formats_to_download = self._select_formats(formats, format_selector)
|
||||||
'formats': formats,
|
|
||||||
'has_merged_format': any('none' not in (f.get('acodec'), f.get('vcodec')) for f in formats),
|
|
||||||
'incomplete_formats': (all(f.get('vcodec') == 'none' for f in formats) # No formats with video
|
|
||||||
or all(f.get('acodec') == 'none' for f in formats)), # OR, No formats with audio
|
|
||||||
}))
|
|
||||||
if interactive_format_selection and not formats_to_download:
|
if interactive_format_selection and not formats_to_download:
|
||||||
self.report_error('Requested format is not available', tb=False, is_error=False)
|
self.report_error('Requested format is not available', tb=False, is_error=False)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -2379,6 +2379,7 @@ from .xhamster import (
|
||||||
XHamsterEmbedIE,
|
XHamsterEmbedIE,
|
||||||
XHamsterUserIE,
|
XHamsterUserIE,
|
||||||
)
|
)
|
||||||
|
from .xiaohongshu import XiaoHongShuIE
|
||||||
from .ximalaya import (
|
from .ximalaya import (
|
||||||
XimalayaIE,
|
XimalayaIE,
|
||||||
XimalayaAlbumIE
|
XimalayaAlbumIE
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
from .common import InfoExtractor
|
||||||
|
from ..utils import (
|
||||||
|
float_or_none,
|
||||||
|
js_to_json,
|
||||||
|
url_or_none,
|
||||||
|
)
|
||||||
|
from ..utils.traversal import traverse_obj
|
||||||
|
|
||||||
|
|
||||||
|
class XiaoHongShuIE(InfoExtractor):
|
||||||
|
_VALID_URL = r'https?://www\.xiaohongshu.com/explore/(?P<id>[a-f0-9]+)'
|
||||||
|
IE_DESC = '小红书'
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'https://www.xiaohongshu.com/explore/6411cf99000000001300b6d9',
|
||||||
|
'md5': '2a87a77ddbedcaeeda8d7eae61b61228',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '6411cf99000000001300b6d9',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'uploader_id': '5c31698d0000000007018a31',
|
||||||
|
'description': '#今日快乐今日发[话题]# #吃货薯看这里[话题]# #香妃蛋糕[话题]# #小五卷蛋糕[话题]# #新手蛋糕卷[话题]#',
|
||||||
|
'title': '香妃蛋糕也太香了吧🔥不需要卷❗️绝对的友好',
|
||||||
|
'tags': ['今日快乐今日发', '吃货薯看这里', '香妃蛋糕', '小五卷蛋糕', '新手蛋糕卷'],
|
||||||
|
'duration': 101.726,
|
||||||
|
'thumbnail': r're:https?://sns-webpic-qc\.xhscdn\.com/\d+/[a-z0-9]+/[\w]+',
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
display_id = self._match_id(url)
|
||||||
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
initial_state = self._search_json(
|
||||||
|
r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', display_id, transform_source=js_to_json)
|
||||||
|
|
||||||
|
note_info = traverse_obj(initial_state, ('note', 'noteDetailMap', display_id, 'note'))
|
||||||
|
video_info = traverse_obj(note_info, ('video', 'media', 'stream', ('h264', 'av1', 'h265'), ...))
|
||||||
|
|
||||||
|
formats = []
|
||||||
|
for info in video_info:
|
||||||
|
format_info = traverse_obj(info, {
|
||||||
|
'fps': 'fps',
|
||||||
|
'width': 'width',
|
||||||
|
'height': 'height',
|
||||||
|
'vcodec': 'videoCodec',
|
||||||
|
'acodec': 'audioCodec',
|
||||||
|
'abr': 'audioBitrate',
|
||||||
|
'vbr': 'videoBitrate',
|
||||||
|
'audio_channels': 'audioChannels',
|
||||||
|
'tbr': 'avgBitrate',
|
||||||
|
'format': 'qualityType',
|
||||||
|
'filesize': 'size',
|
||||||
|
'duration': ('duration', {lambda x: float_or_none(x, scale=1000)})
|
||||||
|
})
|
||||||
|
|
||||||
|
formats.extend(traverse_obj(info, (('mediaUrl', ('backupUrls', ...)), {
|
||||||
|
lambda url: url_or_none(url) and {'url': url, 'ext': 'mp4', **format_info}})))
|
||||||
|
|
||||||
|
thumbnails = []
|
||||||
|
for image_info in traverse_obj(note_info, ('imageList', ...)):
|
||||||
|
thumbnail_info = traverse_obj(image_info, {
|
||||||
|
'height': 'height',
|
||||||
|
'width': 'width'
|
||||||
|
})
|
||||||
|
for url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
|
||||||
|
thumbnails.append({
|
||||||
|
'url': url,
|
||||||
|
**thumbnail_info
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'id': display_id,
|
||||||
|
'formats': formats or [{
|
||||||
|
'url': self._html_search_meta(['og:video'], webpage, fatal=True),
|
||||||
|
'ext': 'mp4'
|
||||||
|
}],
|
||||||
|
'thumbnails': thumbnails or [{
|
||||||
|
'url': self._html_search_meta(['og:image'], webpage, default=None)
|
||||||
|
}],
|
||||||
|
'title': self._html_search_meta(['og:title'], webpage, default=None),
|
||||||
|
**traverse_obj(note_info, {
|
||||||
|
'title': 'title',
|
||||||
|
'description': 'desc',
|
||||||
|
'tags': ('tagList', ..., 'name', {str}),
|
||||||
|
'uploader_id': ('user', 'userId'),
|
||||||
|
}),
|
||||||
|
}
|
Loading…
Reference in New Issue