twitch.tv chapters (#810): print out start and end time
authorPhilipp Hagemeister <phihag@phihag.de>
Sat, 4 May 2013 10:02:18 +0000 (12:02 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Sat, 4 May 2013 10:02:18 +0000 (12:02 +0200)
youtube_dl/InfoExtractors.py
youtube_dl/utils.py

index 96c5973962c47cb0cab1b224288a8b84f859bdb4..36343882bb19d4afefe4828a7aa2285093a61c29 100755 (executable)
@@ -3389,11 +3389,15 @@ class JustinTVIE(InfoExtractor):
                                    errnote='Download of chapter metadata failed')
             chapter_info = json.loads(chapter_info_json)
 
+            bracket_start = int(doc.find('.//bracket_start').text)
+            bracket_end = int(doc.find('.//bracket_end').text)
 
             # TODO determine start (and probably fix up file)
             #  youtube-dl -v http://www.twitch.tv/firmbelief/c/1757457
-            #video_url += u'?start=' + a.find('./start_timestamp').text
-            self._downloader.report_warning(u'Chapter detected, but we do not know how to calculate start position. Downloading the whole file ... (See https://github.com/rg3/youtube-dl/issues/810 )')
+            #video_url += u'?start=' + TODO:start_timestamp
+            # bracket_start is 13290, but we want 51670615
+            self._downloader.report_warning(u'Chapter detected, but we can just download the whole file. '
+                                            u'Chapter starts at %s and ends at %s' % (formatSeconds(bracket_start), formatSeconds(bracket_end)))
 
             info = {
                 'id': u'c' + chapter_id,
index 6c5b5df4cc138254e0d7680ef7477fc0f11e6ed0..4ec0ebfe10e4f96c56723e2dd2bdc67e16dcb11c 100644 (file)
@@ -430,6 +430,14 @@ def decodeOption(optval):
     assert isinstance(optval, compat_str)
     return optval
 
+def formatSeconds(secs):
+    if secs > 3600:
+        return '%d:%02d:%02d' % (secs // 3600, (secs % 3600) // 60, secs % 60)
+    elif secs > 60:
+        return '%d:%02d' % (secs // 60, secs % 60)
+    else:
+        return '%d' % secs
+
 class ExtractorError(Exception):
     """Error during info extraction."""
     def __init__(self, msg, tb=None):