Apply suggestions from code review

Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
sepro 2024-11-24 10:45:13 +01:00 committed by GitHub
parent 8ed7a5343c
commit 0a88e784c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 22 additions and 22 deletions

View file

@ -1654,7 +1654,7 @@ def _wait_for_video(self, ie_result={}):
or ie_result.get('formats') or ie_result.get('url')): or ie_result.get('formats') or ie_result.get('url')):
return return
format_dur = lambda dur: '{:02}:{:02}:{:02}'.format(*timetuple_from_msec(dur * 1000)[:-1]) format_dur = lambda dur: '{:02.0f}:{:02.0f}:{:02.0f}'.format(*timetuple_from_msec(dur * 1000)[:-1])
last_msg = '' last_msg = ''
def progress(msg): def progress(msg):
@ -3817,7 +3817,7 @@ def _format_note(self, fdict):
if fdict.get('tbr') is not None: if fdict.get('tbr') is not None:
if res: if res:
res += ', ' res += ', '
res += '{:4d}k'.format(fdict['tbr']) res += '{:4.0f}k'.format(fdict['tbr'])
if fdict.get('container') is not None: if fdict.get('container') is not None:
if res: if res:
res += ', ' res += ', '
@ -3832,7 +3832,7 @@ def _format_note(self, fdict):
elif fdict.get('vbr') is not None and fdict.get('abr') is not None: elif fdict.get('vbr') is not None and fdict.get('abr') is not None:
res += 'video@' res += 'video@'
if fdict.get('vbr') is not None: if fdict.get('vbr') is not None:
res += '{:4d}k'.format(fdict['vbr']) res += '{:4.0f}k'.format(fdict['vbr'])
if fdict.get('fps') is not None: if fdict.get('fps') is not None:
if res: if res:
res += ', ' res += ', '
@ -3849,9 +3849,9 @@ def _format_note(self, fdict):
res += ', ' res += ', '
res += 'audio' res += 'audio'
if fdict.get('abr') is not None: if fdict.get('abr') is not None:
res += '@{:3d}k'.format(fdict['abr']) res += '@{:3.0f}k'.format(fdict['abr'])
if fdict.get('asr') is not None: if fdict.get('asr') is not None:
res += ' ({:5d}Hz)'.format(fdict['asr']) res += ' ({:5.0f}Hz)'.format(fdict['asr'])
if fdict.get('filesize') is not None: if fdict.get('filesize') is not None:
if res: if res:
res += ', ' res += ', '

View file

@ -125,7 +125,7 @@ def format_seconds(seconds):
time = timetuple_from_msec(seconds * 1000) time = timetuple_from_msec(seconds * 1000)
if time.hours > 99: if time.hours > 99:
return '--:--:--' return '--:--:--'
return '{:02d}:{:02d}:{:02d}'.format(*map(int, time[:-1])) return '{:02.0f}:{:02.0f}:{:02.0f}'.format(*time[:-1])
@classmethod @classmethod
def format_eta(cls, seconds): def format_eta(cls, seconds):

View file

@ -134,7 +134,7 @@ def _get_subtitles(self, sub_url, video_id):
ssa += os.linesep + 'Dialogue: Marked=0,{},{},Default,,0,0,0,,{}{}'.format( ssa += os.linesep + 'Dialogue: Marked=0,{},{},Default,,0,0,0,,{}{}'.format(
ass_subtitles_timecode(start), ass_subtitles_timecode(start),
ass_subtitles_timecode(end), ass_subtitles_timecode(end),
f'{{\\a{alignment}}}' if alignment != 2 else '', '{\\a%d}' % alignment if alignment != 2 else '', # noqa: UP031
text.replace('\n', '\\N').replace('<i>', '{\\i1}').replace('</i>', '{\\i0}')) text.replace('\n', '\\N').replace('<i>', '{\\i1}').replace('</i>', '{\\i0}'))
if sub_lang == 'vostf': if sub_lang == 'vostf':

View file

@ -118,7 +118,7 @@ def _real_extract(self, url):
if isinstance(f['tbr'], float): if isinstance(f['tbr'], float):
f['vbr'] = f['tbr'] * 1000 f['vbr'] = f['tbr'] * 1000
del f['tbr'] del f['tbr']
f['format_id'] = 'rtmp-{}'.format(f['vbr']) f['format_id'] = 'rtmp-{:.0f}'.format(f['vbr'])
formats.extend(smil_formats) formats.extend(smil_formats)
elif stream_type in ('ts', 'hls'): elif stream_type in ('ts', 'hls'):
m3u8_formats = self._extract_m3u8_formats( m3u8_formats = self._extract_m3u8_formats(

View file

@ -2469,7 +2469,7 @@ def _parse_smil_formats_and_subtitles(
'url': streamer, 'url': streamer,
'play_path': src, 'play_path': src,
'ext': 'flv', 'ext': 'flv',
'format_id': f'rtmp-{rtmp_count if bitrate is None else bitrate}', 'format_id': f'rtmp-{(rtmp_count if bitrate is None else bitrate):.0f}',
'tbr': bitrate, 'tbr': bitrate,
'filesize': filesize, 'filesize': filesize,
'width': width, 'width': width,
@ -2493,7 +2493,7 @@ def _parse_smil_formats_and_subtitles(
if len(m3u8_formats) == 1: if len(m3u8_formats) == 1:
m3u8_count += 1 m3u8_count += 1
m3u8_formats[0].update({ m3u8_formats[0].update({
'format_id': f'hls-{m3u8_count if bitrate is None else bitrate}', 'format_id': f'hls-{(m3u8_count if bitrate is None else bitrate):.0f}',
'tbr': bitrate, 'tbr': bitrate,
'width': width, 'width': width,
'height': height, 'height': height,
@ -2524,7 +2524,7 @@ def _parse_smil_formats_and_subtitles(
formats.append({ formats.append({
'url': src_url, 'url': src_url,
'ext': ext or src_ext or 'flv', 'ext': ext or src_ext or 'flv',
'format_id': f'http-{bitrate or http_count}', 'format_id': f'http-{(bitrate or http_count):.0f}',
'tbr': bitrate, 'tbr': bitrate,
'filesize': filesize, 'filesize': filesize,
'width': width, 'width': width,

View file

@ -100,7 +100,7 @@ def _parse_smil_formats_and_subtitles(
furl += '&ssek=' + vn.attrib['clipBegin'] furl += '&ssek=' + vn.attrib['clipBegin']
formats.append({ formats.append({
'url': furl, 'url': furl,
'format_id': f'smil_{tbr}', 'format_id': f'smil_{tbr:.0f}',
'ext': 'flv', 'ext': 'flv',
'tbr': tbr, 'tbr': tbr,
'preference': -1000, # Strictly inferior than all other formats? 'preference': -1000, # Strictly inferior than all other formats?

View file

@ -204,7 +204,7 @@ def extract_bitrate(url):
ext = media.get('ext') or determine_ext(media_url, 'mp4') ext = media.get('ext') or determine_ext(media_url, 'mp4')
format_id = ext format_id = ext
if rate: if rate:
format_id += f'-{rate}k' format_id += f'-{rate:.0f}k'
formats.append({ formats.append({
'format_id': format_id, 'format_id': format_id,
'url': urljoin(download_base, media_url), 'url': urljoin(download_base, media_url),

View file

@ -61,7 +61,7 @@ def _real_extract(self, url):
'encoded data') 'encoded data')
h = time.time() / 3600 h = time.time() / 3600
a = sum(map(int, [compat_ord(c) for c in k])) + int(video_id) + h a = sum(map(int, [compat_ord(c) for c in k])) + int(video_id) + h
video_url = f'http://x-minus.me/dl/minus?id={video_id}&tkn2={a}f{h}' video_url = f'http://x-minus.me/dl/minus?id={video_id}&tkn2={a}f{h:.0f}'
return { return {
'id': video_id, 'id': video_id,

View file

@ -74,7 +74,7 @@ def _extract_video_info(self, partner_id, video_id):
'app': mobj.group('app'), 'app': mobj.group('app'),
'ext': 'flv', 'ext': 'flv',
'tbr': tbr, 'tbr': tbr,
'format_id': f'rtmp-{tbr}', 'format_id': f'rtmp-{tbr:.0f}',
}) })
else: else:
formats.append({ formats.append({

View file

@ -927,12 +927,12 @@ def timetuple_from_msec(msec):
def formatSeconds(secs, delim=':', msec=False): def formatSeconds(secs, delim=':', msec=False):
time = timetuple_from_msec(secs * 1000) time = timetuple_from_msec(secs * 1000)
if time.hours: if time.hours:
ret = f'{time.hours}{delim}{time.minutes:02d}{delim}{time.seconds:02d}' ret = f'{time.hours:.0f}{delim}{time.minutes:02.0f}{delim}{time.seconds:02.0f}'
elif time.minutes: elif time.minutes:
ret = f'{time.minutes}{delim}{time.seconds:02d}' ret = f'{time.minutes:.0f}{delim}{time.seconds:02.0f}'
else: else:
ret = f'{time.seconds}' ret = f'{time.seconds:.0f}'
return f'{ret}.{time.milliseconds:03d}' if msec else ret return f'{ret}.{time.milliseconds:03.0f}' if msec else ret
def bug_reports_message(before=';'): def bug_reports_message(before=';'):
@ -3380,12 +3380,12 @@ def parse_dfxp_time_expr(time_expr):
def srt_subtitles_timecode(seconds): def srt_subtitles_timecode(seconds):
return '{:02d}:{:02d}:{:02d},{:03d}'.format(*map(int, timetuple_from_msec(seconds * 1000))) return '{:02.0f}:{:02.0f}:{:02.0f},{:03.0f}'.format(*timetuple_from_msec(seconds * 1000))
def ass_subtitles_timecode(seconds): def ass_subtitles_timecode(seconds):
time = timetuple_from_msec(seconds * 1000) time = timetuple_from_msec(seconds * 1000)
return '{:01d}:{:02d}:{:02d}.{:02d}'.format(*map(int, time[:-1]), int(time.milliseconds / 10)) return '{:01.0f}:{:02.0f}:{:02.0f}.{:02.0f}'.format(*time[:-1], time.milliseconds / 10)
def dfxp2srt(dfxp_data): def dfxp2srt(dfxp_data):

View file

@ -111,7 +111,7 @@ def _format_ts(ts):
Convert an MPEG PES timestamp into a WebVTT timestamp. Convert an MPEG PES timestamp into a WebVTT timestamp.
This will lose sub-millisecond precision. This will lose sub-millisecond precision.
""" """
return '{:02d}:{:02d}:{:02d}.{:03d}'.format(*timetuple_from_msec(int((ts + 45) // 90))) return '{:02.0f}:{:02.0f}:{:02.0f}.{:03.0f}'.format(*timetuple_from_msec(int((ts + 45) // 90)))
class Block: class Block: