How can I parse the youtube duration format which I believe is ISO 8601
This request
https://www.googleapis.com/youtube/v3/videos?id=Kdgt1ZHkvnM&part=contentDetails&key={API_KEY}
Returns
{
"kind": "youtube#videoListResponse",
"etag": "\"QVyS2yjpsZ-tKkk4JvgYeO_YkzY/Do26Zx0a-KfdN4FPvoMAgqiFNRA\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"QVyS2yjpsZ-tKkk4JvgYeO_YkzY/yZ-09PZbpkEHSEcQeekJuGOCbJY\"",
"id": "Kdgt1ZHkvnM",
"contentDetails": {
"duration": "PT20M1S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false
}
}
]
}
Is there a library that parses this format "PT20M1S" for .Net?
Yes, YouTube uses ISO 8601 duration format, for more you can check it here Wiki ISO 8601 duration.
So what you need to do is to use the following code (of course in a proper context, when you will parse the XML), but you can get the idea:
TimeSpan youTubeDuration = XmlConvert.ToTimeSpan("PT20M1S");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With