Giter Site home page Giter Site logo

Support for YouTube live streams about api HOT 1 OPEN

chatterino avatar chatterino commented on July 17, 2024 1
Support for YouTube live streams

from api.

Comments (1)

Wissididom avatar Wissididom commented on July 17, 2024

I just noticed this issue existing. I once made a script for GreaseMonkey (Jan 3, 2021), that did exactly that, so I thought I'd share the Infos I have...

I use https://www.googleapis.com/youtube/v3/videos?part=snippet,liveStreamingDetails,contentDetails,localizations,player,statistics,status&key=API_KEY there.

Here https://www.googleapis.com/youtube/v3/videos?part=statistics,snippet,contentDetails,liveStreamingDetails&key=API_KEY would be enough I think.

For the liveStreamingDetails it states the following in the documentation:
The `liveStreamingDetails` object contains metadata about a live video broadcast. The object will only be present in a video resource if the video is an upcoming, live, or completed live broadcast. (https://developers.google.com/youtube/v3/docs/videos#liveStreamingDetails)

In my script I used the player API with the InnerTube API-Key, but I think that is probably no option for here as I don't think the API is intended for use outside the Player SDK. Here is a snippet from my code:

let payload = {
  context: {
    client: {
      clientName: 'WEB',
      clientVersion: '2.20210614.06.00',
      originalUrl: window.location.href,
      platform: 'DESKTOP',
      clientFormFactor: 'UNKNOWN_FORM_FACTOR',
      mainAppWebInfo: {
        graftUrl: '/watch?v=' + currentVideoId,
        webDisplayMode: 'WEB_DISPLAY_MODE_BROWSER',
        isWebNativeShareAvailable: false
      }
    },
    user: {
      lockedSafetyMode: false
    },
    request: {
      useSsl: true
    }
  },
  videoId: currentVideoId,
  racyCheckOk: false,
  contentCheckOk: false
};
fetch('https://www.youtube.com/youtubei/v1/player?key=YouTube's own API-Key', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(payload)
}).then(function(response) {
  return response.text();
}).then(function(video_info) {
  try {
    let player_response = JSON.parse(video_info);
    var premiere = !isUndefinedOrNull(player_response) && !player_response.videoDetails.isLiveContent;
    premiere = premiere && !isUndefinedOrNull(data.items[0].liveStreamingDetails);
    var livestream = !isUndefinedOrNull(player_response) && player_response.videoDetails.isLiveContent;
    // ...
  } catch (ex) {
    console.error(ex);
  }
}).catch(error => console.error(error, "\nget_video_info doesn't seem to work"));

If data.items[0].liveStreamingDetails.actualStartTime is not set, I assume, that it is a planned livestream or premiere. If it is set, it is ongoing or ended.
Then I check if data.items[0].liveStreamingDetails.actualEndTime is set and if not it is ongoing.
Maybe snippet.liveBroadcastContent can help for detecting if it is upcoming, live or something else.

Sadly, I haven't found an option to find out if it is a livestream or premiere without the player API.

Maybe I'll look into the structure myself at some point, but I'd first need to learn Go. I just wanted to leave the infos here already.

from api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.