I'm getting the duration value from youtube's v3 api.
I then want to pass that value to isodate function that turns the iso format into seconds.
ytContentDetails = requests.get("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=%s&key=%s"%(ytID, ytAPIkey)).json()
ytDUR = ytContentDetails['items'][0]['contentDetails']['duration']
print ytDUR
ytTime = isodate.parse_duration('%f') ytDUR
But I keep getting an error.
ytTime = isodate.parse_duration('%r')% ytDUR
File "/Library/Python/2.7/site-packages/isodate/isoduration.py", line 99, in parse_duration
raise ISO8601Error("Unable to parse duration string %r" % datestring)
ISO8601Error: Unable to parse duration string '%f'
Where am I going wrong?
I've tried changing %f to different conversions, to no avail.
I think this is a clue...
parse_duration:
parses an ISO 8601 duration string into a timedelta or Duration object.
the ytDUR value outputs something like ....
PT6M19S
Why not just ytTime = isodate.parse_duration(ytDUR)
? It worked for me, i.e. isodate.parse_duration('PT6M19S')
.