philbot9 / youtube-info

Fetch meta information about YouTube videos
ISC License
43 stars 19 forks source link

Expand video duration parsing #11

Open philbot9 opened 5 years ago

philbot9 commented 5 years ago

Videos that are longer than 1 hour will not be parsed correctly (seems to be a new change).

YouTube API docs:

The length of the video. The property value is an ISO 8601 duration. For example, for a video that is at least one minute long and less than one hour long, the duration is in the format PT#M#S, in which the letters PT indicate that the value specifies a period of time, and the letters M and S refer to length in minutes and seconds, respectively. The # characters preceding the M and S letters are both integers that specify the number of minutes (or seconds) of the video. For example, a value of PT15M33S indicates that the video is 15 minutes and 33 seconds long.

If the video is at least one hour long, the duration is in the format PT#H#M#S, in which the # preceding the letter H specifies the length of the video in hours and all of the other details are the same as described above. If the video is at least one day long, the letters P and T are separated, and the value's format is P#DT#H#M#S. Please refer to the ISO 8601 specification for complete details.

https://developers.google.com/youtube/v3/docs/videos#resource

philbot9 commented 5 years ago

Solution: Use this npm package to parse the duration. https://www.npmjs.com/package/iso8601-duration