Comments (1)
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)
- Tweet Link Thumbnails: Compose Multiple Images into Collage HOT 1
- Youtube Shorts support HOT 3
- Add support for imgur.com subdomain imgur.io HOT 3
- Serve Link Info for PDFs HOT 2
- Migrate to Twitter API v2
- Twitch clips resolver crashes when no twitch token is set
- Allow hosters to blocklist domains HOT 9
- Remove Windows-specific support HOT 1
- Make cache timeout values configurable HOT 2
- Additional prometheus metrics
- Reddit previews do not work HOT 3
- Twitter link resolver end of life HOT 2
- Alt text support HOT 1
- Include actual version in the user agent in network requests we send HOT 2
- Block private network requests HOT 1
- Ignore `?feature=share` at the end of youtube links HOT 2
- Some documentation and example config values are missing HOT 2
- Port link resolver responses to JSON HOT 5
- Twitter: Use OG resolver by default HOT 2
- No previews for images uploaded from certain Samsung phones HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api.