From dbbbe555d7a64ff65de5f8a78cc276a848c2e227 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 6 Jan 2021 22:37:55 +0530 Subject: [PATCH] Add `duration_string` to info_dict --- README.md | 1 + youtube_dlc/YoutubeDL.py | 4 ++++ youtube_dlc/utils.py | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 61ab388c3..2ab8d2de9 100644 --- a/README.md +++ b/README.md @@ -741,6 +741,7 @@ # OUTPUT TEMPLATE - `channel_id` (string): Id of the channel - `location` (string): Physical location where the video was filmed - `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 - `like_count` (numeric): Number of positive ratings of the video - `dislike_count` (numeric): Number of negative ratings of the video diff --git a/youtube_dlc/YoutubeDL.py b/youtube_dlc/YoutubeDL.py index e632ba708..19666d0ad 100644 --- a/youtube_dlc/YoutubeDL.py +++ b/youtube_dlc/YoutubeDL.py @@ -908,6 +908,10 @@ def add_default_extra_info(self, ie_result, ie, url): self.add_extra_info(ie_result, { 'extractor': ie.IE_NAME, '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), 'extractor_key': ie.ie_key(), }) diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 6ed8629a7..21e3481a0 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -2285,11 +2285,11 @@ def decodeOption(optval): return optval -def formatSeconds(secs): +def formatSeconds(secs, delim=':'): 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: - return '%d:%02d' % (secs // 60, secs % 60) + return '%d%s%02d' % (secs // 60, delim, secs % 60) else: return '%d' % secs