YouTube Session Duration ISO 8601

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 " PT20M1S " format for .Net?

+4
source share
1 answer

Yes, YouTube uses the ISO 8601 duration format, for more details you can check it here Wiki ISO 8601 duration .

So, you need to use the following code (of course, in the right context when you parse the XML), but you can get the idea:

TimeSpan youTubeDuration = XmlConvert.ToTimeSpan("PT20M1S");
+11
source

Source: https://habr.com/ru/post/1545996/


All Articles