Skip to content

Instantly share code, notes, and snippets.

View C2N14's full-sized avatar
📚
At school

C2N14 C2N14

📚
At school
View GitHub Profile
@C2N14
C2N14 / GetDuration.ps1
Last active April 16, 2022 08:04
[YouTube API V3] New simple Powershell script to get the duration of a YouTube video
#Powershell 4+
#Fix of ShinNoNoir's script that broke with the new API
#https://gist.github.com/ShinNoNoir/d59ca5da3cd5c554a832
function Get-VideoSeconds ([string]$VideoID){
$gdata_uri = "https://www.googleapis.com/youtube/v3/videos?id=$VideoId&key=<APIKEY>&part=contentDetails" #Replace <APIKEY>
$metadata = irm $gdata_uri
$duration = $metadata.items.contentDetails.duration;
$ts = [Xml.XmlConvert]::ToTimeSpan("$duration")