Add duration_string to info_dict

This commit is contained in:
pukkandan 2021-01-06 22:37:55 +05:30
parent 7fd86ce1a9
commit dbbbe555d7
3 changed files with 8 additions and 3 deletions

View file

@ -741,6 +741,7 @@ The basic usage is not to set any template arguments when downloading a single f
- `channel_id` (string): Id of the channel - `channel_id` (string): Id of the channel
- `location` (string): Physical location where the video was filmed - `location` (string): Physical location where the video was filmed
- `duration` (numeric): Length of the video in seconds - `duration` (numeric): Length of the video in seconds
- `duration_string` (string): Length of the video (HH-mm-ss)
- `view_count` (numeric): How many users have watched the video on the platform - `view_count` (numeric): How many users have watched the video on the platform
- `like_count` (numeric): Number of positive ratings of the video - `like_count` (numeric): Number of positive ratings of the video
- `dislike_count` (numeric): Number of negative ratings of the video - `dislike_count` (numeric): Number of negative ratings of the video

View file

@ -908,6 +908,10 @@ class YoutubeDL(object):
self.add_extra_info(ie_result, { self.add_extra_info(ie_result, {
'extractor': ie.IE_NAME, 'extractor': ie.IE_NAME,
'webpage_url': url, 'webpage_url': url,
'duration_string': (
formatSeconds(ie_result['duration'], '-')
if ie_result.get('duration', None) is not None
else None),
'webpage_url_basename': url_basename(url), 'webpage_url_basename': url_basename(url),
'extractor_key': ie.ie_key(), 'extractor_key': ie.ie_key(),
}) })

View file

@ -2285,11 +2285,11 @@ def decodeOption(optval):
return optval return optval
def formatSeconds(secs): def formatSeconds(secs, delim=':'):
if secs > 3600: if secs > 3600:
return '%d:%02d:%02d' % (secs // 3600, (secs % 3600) // 60, secs % 60) return '%d%s%02d%s%02d' % (secs // 3600, delim, (secs % 3600) // 60, delim, secs % 60)
elif secs > 60: elif secs > 60:
return '%d:%02d' % (secs // 60, secs % 60) return '%d%s%02d' % (secs // 60, delim, secs % 60)
else: else:
return '%d' % secs return '%d' % secs