mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-02 11:26:41 +00:00
Apply suggestions from code review
Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
parent
8ed7a5343c
commit
0a88e784c2
|
@ -1654,7 +1654,7 @@ def _wait_for_video(self, ie_result={}):
|
|||
or ie_result.get('formats') or ie_result.get('url')):
|
||||
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 = ''
|
||||
|
||||
def progress(msg):
|
||||
|
@ -3817,7 +3817,7 @@ def _format_note(self, fdict):
|
|||
if fdict.get('tbr') is not None:
|
||||
if res:
|
||||
res += ', '
|
||||
res += '{:4d}k'.format(fdict['tbr'])
|
||||
res += '{:4.0f}k'.format(fdict['tbr'])
|
||||
if fdict.get('container') is not None:
|
||||
if 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:
|
||||
res += 'video@'
|
||||
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 res:
|
||||
res += ', '
|
||||
|
@ -3849,9 +3849,9 @@ def _format_note(self, fdict):
|
|||
res += ', '
|
||||
res += 'audio'
|
||||
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:
|
||||
res += ' ({:5d}Hz)'.format(fdict['asr'])
|
||||
res += ' ({:5.0f}Hz)'.format(fdict['asr'])
|
||||
if fdict.get('filesize') is not None:
|
||||
if res:
|
||||
res += ', '
|
||||
|
|
|
@ -125,7 +125,7 @@ def format_seconds(seconds):
|
|||
time = timetuple_from_msec(seconds * 1000)
|
||||
if time.hours > 99:
|
||||
return '--:--:--'
|
||||
return '{:02d}:{:02d}:{:02d}'.format(*map(int, time[:-1]))
|
||||
return '{:02.0f}:{:02.0f}:{:02.0f}'.format(*time[:-1])
|
||||
|
||||
@classmethod
|
||||
def format_eta(cls, seconds):
|
||||
|
|
|
@ -134,7 +134,7 @@ def _get_subtitles(self, sub_url, video_id):
|
|||
ssa += os.linesep + 'Dialogue: Marked=0,{},{},Default,,0,0,0,,{}{}'.format(
|
||||
ass_subtitles_timecode(start),
|
||||
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}'))
|
||||
|
||||
if sub_lang == 'vostf':
|
||||
|
|
|
@ -118,7 +118,7 @@ def _real_extract(self, url):
|
|||
if isinstance(f['tbr'], float):
|
||||
f['vbr'] = f['tbr'] * 1000
|
||||
del f['tbr']
|
||||
f['format_id'] = 'rtmp-{}'.format(f['vbr'])
|
||||
f['format_id'] = 'rtmp-{:.0f}'.format(f['vbr'])
|
||||
formats.extend(smil_formats)
|
||||
elif stream_type in ('ts', 'hls'):
|
||||
m3u8_formats = self._extract_m3u8_formats(
|
||||
|
|
|
@ -2469,7 +2469,7 @@ def _parse_smil_formats_and_subtitles(
|
|||
'url': streamer,
|
||||
'play_path': src,
|
||||
'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,
|
||||
'filesize': filesize,
|
||||
'width': width,
|
||||
|
@ -2493,7 +2493,7 @@ def _parse_smil_formats_and_subtitles(
|
|||
if len(m3u8_formats) == 1:
|
||||
m3u8_count += 1
|
||||
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,
|
||||
'width': width,
|
||||
'height': height,
|
||||
|
@ -2524,7 +2524,7 @@ def _parse_smil_formats_and_subtitles(
|
|||
formats.append({
|
||||
'url': src_url,
|
||||
'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,
|
||||
'filesize': filesize,
|
||||
'width': width,
|
||||
|
|
|
@ -100,7 +100,7 @@ def _parse_smil_formats_and_subtitles(
|
|||
furl += '&ssek=' + vn.attrib['clipBegin']
|
||||
formats.append({
|
||||
'url': furl,
|
||||
'format_id': f'smil_{tbr}',
|
||||
'format_id': f'smil_{tbr:.0f}',
|
||||
'ext': 'flv',
|
||||
'tbr': tbr,
|
||||
'preference': -1000, # Strictly inferior than all other formats?
|
||||
|
|
|
@ -204,7 +204,7 @@ def extract_bitrate(url):
|
|||
ext = media.get('ext') or determine_ext(media_url, 'mp4')
|
||||
format_id = ext
|
||||
if rate:
|
||||
format_id += f'-{rate}k'
|
||||
format_id += f'-{rate:.0f}k'
|
||||
formats.append({
|
||||
'format_id': format_id,
|
||||
'url': urljoin(download_base, media_url),
|
||||
|
|
|
@ -61,7 +61,7 @@ def _real_extract(self, url):
|
|||
'encoded data')
|
||||
h = time.time() / 3600
|
||||
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 {
|
||||
'id': video_id,
|
||||
|
|
|
@ -74,7 +74,7 @@ def _extract_video_info(self, partner_id, video_id):
|
|||
'app': mobj.group('app'),
|
||||
'ext': 'flv',
|
||||
'tbr': tbr,
|
||||
'format_id': f'rtmp-{tbr}',
|
||||
'format_id': f'rtmp-{tbr:.0f}',
|
||||
})
|
||||
else:
|
||||
formats.append({
|
||||
|
|
|
@ -927,12 +927,12 @@ def timetuple_from_msec(msec):
|
|||
def formatSeconds(secs, delim=':', msec=False):
|
||||
time = timetuple_from_msec(secs * 1000)
|
||||
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:
|
||||
ret = f'{time.minutes}{delim}{time.seconds:02d}'
|
||||
ret = f'{time.minutes:.0f}{delim}{time.seconds:02.0f}'
|
||||
else:
|
||||
ret = f'{time.seconds}'
|
||||
return f'{ret}.{time.milliseconds:03d}' if msec else ret
|
||||
ret = f'{time.seconds:.0f}'
|
||||
return f'{ret}.{time.milliseconds:03.0f}' if msec else ret
|
||||
|
||||
|
||||
def bug_reports_message(before=';'):
|
||||
|
@ -3380,12 +3380,12 @@ def parse_dfxp_time_expr(time_expr):
|
|||
|
||||
|
||||
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):
|
||||
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):
|
||||
|
|
|
@ -111,7 +111,7 @@ def _format_ts(ts):
|
|||
Convert an MPEG PES timestamp into a WebVTT timestamp.
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue