]> jfr.im git - yt-dlp.git/commitdiff
Add `duration_string` to info_dict
authorpukkandan <redacted>
Wed, 6 Jan 2021 17:07:55 +0000 (22:37 +0530)
committerpukkandan <redacted>
Wed, 6 Jan 2021 17:07:55 +0000 (22:37 +0530)
README.md
youtube_dlc/YoutubeDL.py
youtube_dlc/utils.py

index 61ab388c364d9b5201a631863ed3efee05fb510e..2ab8d2de9f3ef897d3e503244f6920b86398de3b 100644 (file)
--- 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
index e632ba708fa42a09cef5faae1800d011c4f3d7fd..19666d0ad1f2247af1a73072d75d528ed181ce67 100644 (file)
@@ -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(),
         })
index 6ed8629a7a8cd58b7b00cc3678e2a26f32909763..21e3481a0f29b772cd1d72acafb7a48fef34592c 100644 (file)
@@ -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