This commit is contained in:
Josef Bohórquez 2024-07-02 14:28:59 -04:00 committed by GitHub
commit 3432f0a00a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 139 deletions

View File

@ -2388,60 +2388,38 @@ class YoutubeDL(object):
return res return res
def _format_note(self, fdict): def _format_note(self, fdict):
res = '' note_parts = []
if fdict.get('ext') in ['f4f', 'f4m']: if fdict.get('ext') in ('f4f', 'f4m'):
res += '(unsupported) ' note_parts.append('(unsupported)')
if fdict.get('language'): if fdict.get('language'):
if res: note_parts.append(f'[{fdict["language"]}]')
res += ' ' if fdict.get('format_note'):
res += '[%s] ' % fdict['language'] note_parts.append(fdict['format_note'])
if fdict.get('format_note') is not None:
res += fdict['format_note'] + ' '
if fdict.get('tbr') is not None: if fdict.get('tbr') is not None:
res += '%4dk ' % fdict['tbr'] note_parts.append('%4dk' % fdict['tbr'])
if fdict.get('container') is not None: if fdict.get('container') is not None:
if res: note_parts.append('%s container' % fdict['container'])
res += ', ' if fdict.get('vcodec') not in (None, 'none'):
res += '%s container' % fdict['container'] note_parts.append(fdict['vcodec'] + ('@' if fdict.get('vbr') else ''))
if (fdict.get('vcodec') is not None elif fdict.get('vbr') is not None:
and fdict.get('vcodec') != 'none'): note_parts.append('video@')
if res:
res += ', '
res += fdict['vcodec']
if fdict.get('vbr') is not None: if fdict.get('vbr') is not None:
res += '@' note_parts.append('%4dk' % fdict['vbr'])
elif fdict.get('vbr') is not None and fdict.get('abr') is not None:
res += 'video@'
if fdict.get('vbr') is not None:
res += '%4dk' % fdict['vbr']
if fdict.get('fps') is not None: if fdict.get('fps') is not None:
if res: note_parts.append('%sfps' % fdict['fps'])
res += ', '
res += '%sfps' % fdict['fps']
if fdict.get('acodec') is not None: if fdict.get('acodec') is not None:
if res: note_parts.append('video only' if fdict['acodec'] == 'none' else '%-5s' % fdict['acodec'])
res += ', '
if fdict['acodec'] == 'none':
res += 'video only'
else:
res += '%-5s' % fdict['acodec']
elif fdict.get('abr') is not None: elif fdict.get('abr') is not None:
if res: note_parts.append('audio')
res += ', '
res += 'audio'
if fdict.get('abr') is not None: if fdict.get('abr') is not None:
res += '@%3dk' % fdict['abr'] note_parts.append('@%3dk' % fdict['abr'])
if fdict.get('asr') is not None: if fdict.get('asr') is not None:
res += ' (%5dHz)' % fdict['asr'] note_parts.append('(%5dHz)' % fdict['asr'])
if fdict.get('filesize') is not None: if fdict.get('filesize') is not None:
if res: note_parts.append(format_bytes(fdict['filesize']))
res += ', '
res += format_bytes(fdict['filesize'])
elif fdict.get('filesize_approx') is not None: elif fdict.get('filesize_approx') is not None:
if res: note_parts.append('~' + format_bytes(fdict['filesize_approx']))
res += ', ' return ' '.join(note_parts)
res += '~' + format_bytes(fdict['filesize_approx'])
return res
def list_formats(self, info_dict): def list_formats(self, info_dict):
formats = info_dict.get('formats', [info_dict]) formats = info_dict.get('formats', [info_dict])

View File

@ -87,6 +87,7 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised. If _LOGIN_REQUIRED is set and no authentication was provided, an error is raised.
""" """
username, password = self._get_login_info() username, password = self._get_login_info()
# No authentication to be performed # No authentication to be performed
if username is None: if username is None:
if self._LOGIN_REQUIRED and self._downloader.params.get('cookiefile') is None: if self._LOGIN_REQUIRED and self._downloader.params.get('cookiefile') is None:
@ -129,22 +130,21 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
self._downloader.report_warning(message) self._downloader.report_warning(message)
lookup_req = [ lookup_req = [
username, username, None, [], None, 'US', None, None, 2, False, True,
None, [], None, 'US', None, None, 2, False, True, [None, None, [2, 1, None, 1,
[
None, None,
[2, 1, None, 1,
'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
None, [], 4], None, [], 4], 1, [None, None, []], None, None, None, True],
1, [None, None, []], None, None, None, True
],
username, username,
] ]
lookup_results = req( # --- Cambio 1: Extracción de función para mejorar la legibilidad ---
self._LOOKUP_URL, lookup_req, def perform_lookup(req):
return self._download_json(
self._LOOKUP_URL, req,
'Looking up account info', 'Unable to look up account info') 'Looking up account info', 'Unable to look up account info')
lookup_results = perform_lookup(lookup_req)
if lookup_results is False: if lookup_results is False:
return False return False
@ -154,12 +154,10 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
return False return False
challenge_req = [ challenge_req = [
user_hash, user_hash, None, 1, None, [1, None, None, None, [password, None, True]],
None, 1, None, [1, None, None, None, [password, None, True]], [None, None, [2, 1, None, 1,
[ 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn',
None, None, [2, 1, None, 1, 'https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252F%26action_handle_signin%3Dtrue%26hl%3Den%26app%3Ddesktop%26feature%3Dsign_in_button&hl=en&service=youtube&uilel=3&requestPath=%2FServiceLogin&Page=PasswordSeparationSignIn', None, [], 4], None, [], 4], 1, [None, None, []], None, None, None, True]]
1, [None, None, []], None, None, None, True
]]
challenge_results = req( challenge_results = req(
self._CHALLENGE_URL, challenge_req, self._CHALLENGE_URL, challenge_req,

View File

@ -5990,81 +5990,46 @@ def parse_m3u8_attributes(attrib):
def urshift(val, n): def urshift(val, n):
return val >> n if val >= 0 else (val + 0x100000000) >> n return val >> n if val >= 0 else (val + 0x100000000) >> n
# Based on png2str() written by @gdkchan and improved by @yokrysty # Based on png2str() written by @gdkchan and improved by @yokrysty
# Originally posted at https://github.com/ytdl-org/youtube-dl/issues/9706 # Originally posted at https://github.com/ytdl-org/youtube-dl/issues/9706
def decode_png(png_data): def decode_png(png_data):
# Reference: https://www.w3.org/TR/PNG/ # Reference: https://www.w3.org/TR/PNG/
header = png_data[8:] if png_data[:8] != b'\x89PNG\x0d\x0a\x1a\x0a':
if png_data[:8] != b'\x89PNG\x0d\x0a\x1a\x0a' or header[4:8] != b'IHDR':
raise IOError('Not a valid PNG file.') raise IOError('Not a valid PNG file.')
int_map = {1: '>B', 2: '>H', 4: '>I'} def unpack_integer(data):
unpack_integer = lambda x: compat_struct_unpack(int_map[len(x)], x)[0] return compat_struct_unpack(f'>{int_map[len(data)]}', data)[0]
int_map = {1: 'B', 2: 'H', 4: 'I'}
header = png_data[8:]
chunks = [] chunks = []
while header: while header:
length = unpack_integer(header[:4]) length = unpack_integer(header[:4])
header = header[4:] chunk_type, chunk_data, header = header[4:8], header[8:8 + length], header[8 + length + 4:]
chunks.append({'type': chunk_type, 'data': chunk_data})
chunk_type = header[:4] if not (ihdr := next((c["data"] for c in chunks if c["type"] == b'IHDR'), None)):
header = header[4:] raise IOError("Unable to read PNG header.")
chunk_data = header[:length] width, height = unpack_integer(ihdr[:4]), unpack_integer(ihdr[4:8])
header = header[length:] idat = b''.join(c['data'] for c in chunks if c['type'] == b'IDAT')
header = header[4:] # Skip CRC
chunks.append({
'type': chunk_type,
'length': length,
'data': chunk_data
})
ihdr = chunks[0]['data']
width = unpack_integer(ihdr[:4])
height = unpack_integer(ihdr[4:8])
idat = b''
for chunk in chunks:
if chunk['type'] == b'IDAT':
idat += chunk['data']
if not idat: if not idat:
raise IOError('Unable to read PNG data.') raise IOError('Unable to read PNG data.')
decompressed_data = bytearray(zlib.decompress(idat)) decompressed_data = bytearray(zlib.decompress(idat))
stride = width * 3 stride = width * 3
pixels = [] pixels = [[] for _ in range(height)]
def _get_pixel(idx): def _get_pixel(x, y):
x = idx % stride return pixels[y][x] if x >= 0 and y >= 0 else 0
y = idx // stride
return pixels[y][x]
for y in range(height): for y in range(height):
basePos = y * (1 + stride) filter_type = decompressed_data[y * (1 + stride)]
filter_type = decompressed_data[basePos]
current_row = []
pixels.append(current_row)
for x in range(stride): for x in range(stride):
color = decompressed_data[1 + basePos + x] color = decompressed_data[1 + y * (1 + stride) + x]
basex = y * stride + x left, up = _get_pixel(x - 3, y), _get_pixel(x, y - 1)
left = 0
up = 0
if x > 2:
left = _get_pixel(basex - 3)
if y > 0:
up = _get_pixel(basex - stride)
if filter_type == 1: # Sub if filter_type == 1: # Sub
color = (color + left) & 0xff color = (color + left) & 0xff
@ -6073,31 +6038,15 @@ def decode_png(png_data):
elif filter_type == 3: # Average elif filter_type == 3: # Average
color = (color + ((left + up) >> 1)) & 0xff color = (color + ((left + up) >> 1)) & 0xff
elif filter_type == 4: # Paeth elif filter_type == 4: # Paeth
a = left a, b, c = left, up, _get_pixel(x - 3, y - 1)
b = up
c = 0
if x > 2 and y > 0:
c = _get_pixel(basex - stride - 3)
p = a + b - c p = a + b - c
pa, pb, pc = abs(p - a), abs(p - b), abs(p - c)
color = (color + (a if pa <= pb and pa <= pc else b if pb <= pc else c)) & 0xff
pa = abs(p - a) pixels[y].append(color)
pb = abs(p - b)
pc = abs(p - c)
if pa <= pb and pa <= pc:
color = (color + a) & 0xff
elif pb <= pc:
color = (color + b) & 0xff
else:
color = (color + c) & 0xff
current_row.append(color)
return width, height, pixels return width, height, pixels
def write_xattr(path, key, value): def write_xattr(path, key, value):
# This mess below finds the best xattr tool for the job # This mess below finds the best xattr tool for the job
try: try: