MCPcopy
hub / github.com/hellerve/programming-talks / get_duration

Function get_duration

scripts/add_youtube_durations.py:25–43  ·  view source on GitHub ↗
(json_video)

Source from the content-addressed store, hash-verified

23 return len([l for l in f])
24
25def get_duration(json_video):
26 hours = 0
27 minutes = 0
28 seconds = 0
29 s = json_video['items'][0]['contentDetails']['duration']
30 match = re.match(r'PT([0-5]?[\d])M([0-5]?[\d]?)S?', s)
31 if match:
32 items = match.groups()
33 minutes = items[0]
34 seconds = items[1]
35 else:
36 match_with_hours = re.match(r'PT([\d]?[\d])H([0-5]?[\d]?)M?([0-5]?[\d]?)S?', s)
37 if match_with_hours:
38 items = match_with_hours.groups()
39 hours = items[0]
40 minutes = items[1]
41 seconds = items[2]
42
43 return hours, minutes, seconds
44
45def print_duration(duration):
46 hours = duration[0] or 0

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected