coolapso / prometheus-youtube-exporter

A Prometheus exporter to scrape metrics from the YouTube API
MIT License
0 stars 0 forks source link

LiveContentBroadcast Broken #19

Open coolapso opened 3 weeks ago

coolapso commented 3 weeks ago

Seems that youtube API stopped marking the videos as LiveBroadCast content and the VideoSnippet now returns active broadcast videos as "none"

Sample listing all channel videos:

package main

import (
    "fmt"
    "log"
    "os"
    "context"

    "google.golang.org/api/youtube/v3"
    "google.golang.org/api/option"

)

const developerKey = "*****"

func main() {

    client, err := youtube.NewService(context.Background(), option.WithAPIKey(developerKey))
    if err != nil {
        log.Fatalf("Error creating new YouTube client: %v", err)
    }

    // Make the API call to YouTube.

    // response, err := call.Do()
    // if err != nil { 
    //  fmt.Println("Failed to get response", err)
    //  os.Exit(1)
    // }

    var nextPageToken string

    for { 
        call := client.Search.List([]string{"snippet"}).Type("video").ChannelId("UCRQkojTvYhnBt6D3ELwfINQ").Order("date")

        if nextPageToken != "" {
            call = call.PageToken(nextPageToken)
        }

        response, err := call.Do()
        if err != nil { 
            fmt.Println("Failed to get response", err)
            os.Exit(1)
        }
        fmt.Println(response.NextPageToken)
        fmt.Println(response.PageInfo.TotalResults)

        for _, video := range response.Items {
            fmt.Println("Video Title:", video.Snippet.Title, video.Snippet.PublishedAt, video.Snippet.LiveBroadcastContent)
        }

        if response.NextPageToken == "" {
            break
        }

        nextPageToken = response.NextPageToken
    }
}
9
Video Title: ArcticSkies Northern Lights 10 31 2024, 9 50 13pm GMT+1   11 1 2024, 1 30 00am GMT+1 2024-11-01T20:22:18Z none
Video Title: The Arctic Skies 24/7 2024-10-29T20:27:45Z none   <==== This should be "live" as its the current active broadcast
Video Title: Kiruna, Swedish lapland Northern Lights: October 26th 2024-10-27T16:31:54Z none
Video Title: Kiruna, Swedish lapland Northern Lights: October 23rd 2024-10-26T11:00:12Z none
Video Title: Kiruna, Swedish lapland Northern Lights: October 14th 2024 2024-10-15T19:26:37Z none

9
Video Title: Kiruna, Swedish lapland Northern Lights: October 12th 2024 2024-10-13T18:00:35Z none
Video Title: Kiruna, Swedish lapland Northern Lights: October 12th 2024 2024-10-12T11:48:40Z none
Video Title: ArcticSkies Northern Lights Time Lapse 10 7 2024, 8 25 00pm GMT+2   10 7 2024, 9 15 00pm GMT+2 2024-10-07T20:57:16Z none
Video Title: Little Aurora 2024-09-28T22:19:21Z none

Maybe should investigate changing the authentication method to OAUTH and use the LiveBroadcast api:https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list

coolapso commented 3 weeks ago

seems to be an issue with the channel in particular, same code sames to return correct result:

☸ virt01 ❯go run main.go

Video Title: acoustic show prep + horror score | ORLANDO SHOW NOVEMBER 8TH!! | !bfmvtrv !charityevent !jtcsale 2024-11-04T14:02:24Z live
Video Title: Steel 2024-11-03T14:05:52Z none
Video Title: @matthewkheafy - @trivium- &#39;The Heart From Your Hate&#39; Acoustic Cover 2024-11-02T14:45:00Z none
Video Title: The Immortal 2024-11-02T14:32:25Z none
Video Title: Let’s talk lights 2024-10-29T15:31:13Z none

Video Title: Metal Musician Reacts - &#39;Watch The World Burn&#39; Acoustic Cover by @LeaMoonchild 2024-10-19T14:30:31Z none
Video Title: I’m back 2024-10-14T13:19:50Z none
Video Title: Life lately am I right? 2024-10-12T15:17:58Z none
Video Title: Remnant 2 x Matt Heafy I Spire Of The Hellspawn 2024-10-10T16:00:39Z none
Video Title: Brave this rain 2024-10-09T13:23:54Z none

Video Title: Brrr brrr brrrrr 2024-09-29T12:24:52Z none
Video Title: Tree pose downpick 2024-09-23T12:21:45Z none
Video Title: PLANKTON - DYING IN YOUR ARMS (Trivium Cover) 2024-09-21T16:00:17Z none
Video Title: Stream deck studio 2024-09-20T12:05:23Z none
Video Title: Scream like dad 2024-09-12T13:10:32Z none

Suspect this may be caused by the livestream not being the most recent video.

coolapso commented 3 weeks ago

This seems to be caused by the "Unlist live replay once stream ends"

If turned on while stream is active, makes the output return to "none" If turned on when starting the stream, makes the output return "upcoming"

"unlist live replay once stream ends" needs to be turned of for the exporter to properly get the stream status.