I want to convert the duration variable from YouTube Data api?
PT1M6S --> 1:06
PT38S --> 0:38
PT58M4 --> 58:04
Here is my codes:
p['duration'] is the value from json data
duration = re.sub(r'^PT',r'',p['duration'])
duration = re.sub(r'M',r':',duration)
if (len(p['duration']) > 5 ):
duration = re.sub(r'S',r'',duration)
else:
duration = "0:" + re.sub(r'S',r'',duration)
Is there a simple way to do in one regex statement?
Thanks!