I've been playing around with the YouTube live chat API to look render a YouTube live stream chat, but I'm stuck on how to handle emotes.
The YouTube API for live chat messages seems to only ever return the message in plain text, not metadata about emotes. This itself is fine, as there is standard syntax for emotes within the plain text, but I'm struggling with how to convert those into images.
If I look at the response I get from the YouTube API, I can see no information about the emotes beyond what is in the plain text message:
{
"kind": "youtube#liveChatMessage",
"etag": "UaRmhczzavJeCA9S1_s8J_4MHD0",
"id": "LCC.CjgKDQoLd1VwYUIzYTdkVW8qJwoYVUNEWExPVjNTMEdUd21EOFY4R1A2dzlREgt3VXBhQjNhN2RVbxJFChpDT25vOHN6SW92VUNGZUFJMWdBZE85b1BfZxInQ1BhdG12UEhvdlVDRlhzNFRBb2RVSE1BeVExNjQxNjU5MDY5OTU3",
"snippet": {
"type": "textMessageEvent",
"liveChatId": "Cg0KC3dVcGFCM2E3ZFVvKicKGFVDRFhMT1YzUzBHVHdtRDhWOEdQNnc5URILd1VwYUIzYTdkVW8",
"authorChannelId": "UC_MMOdc84fer50_SIPiPX1Q",
"publishedAt": "2022-01-08T16:24:28.363Z",
"hasDisplayContent": true,
"displayMessage": ":yougotthis::elbowcough:",
"textMessageDetails": {
"messageText": ":yougotthis::elbowcough:"
}
},
"authorDetails": {
"channelId": "UC_MMOdc84fer50_SIPiPX1Q",
"channelUrl": "http://www.youtube.com/channel/UC_MMOdc84fer50_SIPiPX1Q",
"displayName": "Blake Nolan",
"profileImageUrl": "https://yt3.ggpht.com/ytc/AKedOLSVNcUaOuoH49GXdG1Zlam0uBMJYJXUI5h_pHtMr-rOVr5hDnjzspewBUVqgKyw=s88-c-k-c0x00ffffff-no-rj",
"isVerified": false,
"isChatOwner": false,
"isChatSponsor": false,
"isChatModerator": false
}
}
But if I look at how this message shows up in YouTube chat, the emotes are rendered:
What am I missing to perform this lookup and conversion myself so that I can render the emotes from the chat messages?
Cheers.
To complete my answer from your other question on this precise question:
By running step 1. you'll get live messages sent in HTML format before your request with emotes in the format :emote: but then come the URL of the emote image.
By running all steps, you'll get live messages sent in real time in JSON format, in the same way you'll get live chat messages with emotes in the format :emote: but then come the URL of the emote image.
I let you understand both HTML and JSON format.
Note: I also found while reverse-engineering the URLs https://www.gstatic.com/youtube/img/emojis/emojis-svg-N.json with N between 0 and 8, that return a bunch of emotes codes linked to their image URL however some emotes like both you stated aren't in these files I don't know why.
Related
I want a way to get YouTube shorts for a specific channel from YouTube API. I looked every where and I couldn't find anything.
Currently I can get a playlist ID for all channel videos with this endpoint:
request = youtube.channels().list(
part="contentDetails",
id=id
)
I also tried these parameters:
request = youtube.channels().list(
part="snippet,contentDetails,statistics,brandingSettings",
id=id
)
So is there a way to get YouTube shorts from a specific channel from YouTube API or any other source if it's available.
One way of detecting if a YouTube video ID is a Short without even using the API is to try a HEAD HTTP request to the /shorts/ version of the URL and see if it redirects you.
https://www.youtube.com/shorts/hKwrn5-7FjQ is a Short and if you visit that URL, you'll get an HTTP status code of 200 and the URL won't change.
https://www.youtube.com/watch?v=B-s71n0dHUk is not a Short, and if you visit https://www.youtube.com/shorts/B-s71n0dHUk, you get a 303 redirect back to the original URL.
Keep in mind, that this behavior might change down the line, but it works as of May 2022.
It seems that once again YouTube Data API v3 doesn't provide a basic feature.
For checking if a given video is a short:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/videos?part=short&id=VIDEO_ID containing item["short"]["available"] boolean, your problem is solved.
Example of short id: ydPkyvWtmg4
For listing shorts of a channel:
I would recommend you to use my open-source YouTube operational API. Indeed by requesting the JSON document https://yt.lemnoslife.com/channels?part=shorts&id=CHANNEL_ID. The entry item["shorts"] contains the data you are looking for. Note that the pagination works as the one of YouTube Data API v3.
Example of result for channel UC5O114-PQNYkurlTg6hekZw:
{
"kind": "youtube#channelListResponse",
"etag": "NotImplemented",
"items": [
{
"kind": "youtube#channel",
"etag": "NotImplemented",
"id": "UC5O114-PQNYkurlTg6hekZw",
"shorts": [
{
"videoId": "fP8nKVauFwc",
"title": "India: United Nations Counter Terrorism Committee Watch LIVE #shorts",
"thumbnails": [
{
"url": "https:\/\/i.ytimg.com\/vi\/fP8nKVauFwc\/hq720_2.jpg?sqp=-oaymwEYCNAFENAFSFryq4qpAwoIARUAAIhC0AEB&rs=AOn4CLCgJEYgv_msT5pkfWeEEN3VBt4wjg",
"width": 720,
"height": 720
}
],
"viewCount": 3700
},
...
],
"nextPageToken": "4qmFsgLlARIYVUM1TzExNC1QUU5Za3VybFRnNmhla1p3GsgBOGdhU0FScVBBVktNQVFxSEFRcGZRME00VVVGU2IyWnZaMWxqUTJob1ZsRjZWbEJOVkVVd1RGWkNVbFJzYkhKa1dFcHpWa2RqTW1GSFZuSlhibU5SUVZOSlVrTm5PSGhQYWtVeVRtcGplVTE2VlRST2FrVXdUbXBCY1VSUmIweFhWRUl5VGtab1dGSllSbGRNVmtVU0pEWXpOakJoTkRVNUxUQXdNREF0TWpKaE15MDRObUV6TFdRMFpqVTBOMlZqWVRSbFl4Z0I=,CgtuNjFmZlJlR0QxcyiVgICbBg=="
}
]
}
Below is a sample python code to send the HEAD HTTP request.
import requests
def is_short(vid):
url = 'https://www.youtube.com/shorts/' + vid
ret = requests.head(url)
if ret.status_code == 200:
return True
else: # whether 303 or other values, it's not short
return False
I don't know why but I don't get status code 303 whether it's a short or not with axios. So this is another way of checking if it's a short or not.
const isShort = async (videoId) => {
const url = "https://www.youtube.com/shorts/" + videoId
const res = await axios.head(url)
console.log(res.request.res.responseUrl)
// if it's a short it ends with "/shorts/videoId"
// if it's NOT a short it ends "/watch?=videoId"
}
Maybe axios automatically redirects?
You can use the new dimension called 'creatorContentType' from Youtube Analytics and Reports API.
// You can get IDs from PlaylistItems or Search API
const IDs = ["videoID1", "videoID2", "videoID3"];
// Get the analytics data of selected videos based on their IDs
const { data: analyticsData } = await youtubeAnalytics.reports.query({
ids: "channel==MINE",
startDate: "2019-01-01",
// Today's date
endDate: new Date().toISOString().split("T")[0],
metrics: "views",
dimensions: "video,creatorContentType",
filters: `video==${IDs.join(",")}`,
access_token,
});
It basically returns values listed below:
Value
Description
LIVE_STREAM
The viewed content was a YouTube live stream.
SHORTS
The viewed content was a YouTube Short.
STORY
The viewed content was a YouTube Story.
VIDEO_ON_DEMAND
The viewed content was a YouTube video that does not fall under one of the other dimension values.
UNSPECIFIED
The content type of the viewed content is unknown.
Notes:
Don't forget it returns values just for the videos uploaded after 01.01.2019.
Don't forget to add analytics scopes and enable Analytics and Reports API.
I am aware of similar questions being asked before, but not this exact one, so please bear with me...
I want to reproduce a channel's uploaded videos list as they appear on YouTube's web page (broken into pages and sorted by publish date).
To do this, I am trying to get a list of VideoIDs from a YouTube channel that's sorted by publish date (by YouTube, not my code since there could be 1000's of videos in a playlist and YouTube limits to 50 results per query which can add up when I only want to show the user the first 25 entries).
Initially, I was using this YouTube Data API v3 Search query:
https://www.googleapis.com/youtube/v3/search?key=[APIKey]&channelId=[ChannelID]&part=snippet,id&order=date&type=video&maxResults=25
However, as some of the previous posts on stackoverflow mentioned (YouTube API v3 Search not returning all videos), this method does not guarantee to return all videos and indeed, some videos are missing from the result, making use of this query problematic.
I then saw this google video in some of the posts:
https://www.youtube.com/watch?v=RjUlmco7v2M
In the video, it is explained that you must first get the 'uploads' playlist for a channel (I'm also grabbing the channel's title and thumbnail in this query), which I do using:
https://www.googleapis.com/youtube/v3/channels?key=[APIKEY]&part=snippet,contentDetails&id=[ChannelID]
And once I have the 'uploads' playlist ID, I query:
https://www.googleapis.com/youtube/v3/playlistItems?key=[APIKey]&playlistId=[PlaylistID]&part=snippet,id&order=date&type=video&maxResults=25
However, the returned entries are not sorted by the publish date and according to the documentation (https://developers.google.com/youtube/v3/docs/playlistItems/list), there is no optional "order" parameter associated with this query.
With all these issues in mind, how do I get the first 25 entries of the 'uploads' playlist sorted by publish date without downloading the entire playlist so I can faithfully recreate how the YouTube website is listing videos.
After making some tests and thanks to this answer (and the next answers too) I was able to retrieve the information you need using the YouTube Data API v3 and here is how I made it:
First, in your question you're using the "search" API - since I don't know which criteria you're using in the search request, I omitted it for get direct to get the "upload" playlist id from a given channel_id.
Using the channel_id = UCT2rZIAL-zNqeK1OmLLUa6g (which belongs to "Microsoft HoloLens"), I use the "channels" API for retrieve the uploads playlist id.
Here is the URL request for retrieve the "upload" playlist id from the channel_id previously mentioned:
https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet%2CcontentDetails&fields=items(contentDetails%2FrelatedPlaylists%2Fuploads%2Csnippet%2Flocalized)&id=UCT2rZIAL-zNqeK1OmLLUa6g&key=<YOUR_API_KEY>
Explanation:
part: set the snippet and contentDetails parts for retrieve the following:
fields: from the snippet part: (localized, description and title) and from the contentDetails part: (relatedPlayLists and uploads).
id: channel_id used in this request.
Here are the results from this request:
{
"items": [
{
"snippet": {
"localized": {
"title": "Microsoft HoloLens",
"description": "The official YouTube channel of Microsoft HoloLens. Transform your world with holograms. Visit HoloLens.com for more info."
}
},
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUT2rZIAL-zNqeK1OmLLUa6g"
}
}
}
]
}
Check the value of the uploads property in the
contentDetails section. This value will be used in the next API request.
You can also check these results in the Google API Explorer demo I prepared for make this request.
Once retrieved the uploads value (as specified in previous lines), now it's time to use the "playlistItems" API for build the following URL:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&playlistId=UUT2rZIAL-zNqeK1OmLLUa6g&fields=items(contentDetails(videoId%2CvideoPublishedAt)%2Csnippet%2Ftitle%2Cstatus)&maxResults=25&key=<YOUR_API_KEY>
Explanation:
part: set the snippet and contentDetails parts for retrieve the following:
fields: from the snippet part: (title and status) and from the contentDetails part: (videoId and videoPublishedAt).
playlistId: is the playlistId used in this request - (that is, the uploads value).
maxResults: set to 25.
Here are the results from this request:
{
"items": [
{
"snippet": {
"title": "Microsoft Windows Mixed Reality update | October 2018"
},
"contentDetails": {
"videoId": "00vnln25HBg",
"videoPublishedAt": "2019-01-04T17:43:47.000Z"
}
},
{
"snippet": {
"title": "How to use Spectator View for mobile devices"
},
"contentDetails": {
"videoId": "3fXlPw_FGLg",
"videoPublishedAt": "2018-10-15T17:13:42.000Z"
}
},
{
"snippet": {
"title": "Microsoft HoloLens: Visualizing the next mission to Mars."
},
"contentDetails": {
"videoId": "XVBbJ4EtAQY",
"videoPublishedAt": "2018-07-02T16:30:26.000Z"
}
},
{
"snippet": {
"title": "Microsoft HoloLens: Making mixed reality plug and play."
},
"contentDetails": {
"videoId": "QwXcSekZKWE",
"videoPublishedAt": "2018-06-25T23:25:55.000Z"
}
},
{
"snippet": {
"title": "Microsoft HoloLens | Windows Mixed Reality HMD Exerciser"
},
"contentDetails": {
"videoId": "RU3OMjq_Yic",
"videoPublishedAt": "2018-05-14T16:58:43.000Z"
}
}
]
}
I check the order of the items and they are in sorted by videoPublishedAt value (new to old).
You can also check these results in the try-it funcionality found in the YouTube Data API v3 - official documentation.1
1 For this case, I was unable to use the Google API Explorer (as I used in the first request) because I always got a "backend Error".
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 500,
"message": "Backend Error"
}
}
I think this is because the Google API explorer is outdated.
If anyone want to check it out, here is the demo.
I'm also using the playlist ID to get a list of videos, however mine do seem to be sorted by date from newest to oldest. Note that Youtube returns a page token that you can use to get the next 25 (or in my case 50) videos. I'm querying the API this way:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&pageToken= not_used_for_first_query&fields=nextPageToken,items(snippet(publishedAt,title,desc ription,thumbnails(default(url)),resourceId(videoId)))&playlistId=uploads_playlist_id&maxResults=50&order=date&key=your_api_key
This gets back in JSON response:
The video title
Publish date
Video description
Youtube URL for video
Video unique ID
Video thumbnail
You can see my working example at https://www.scriptbarrel.com
I am using MusicBrainz to get a track's meta data. I want to get the track's album's mbid. I am doing the following lookup using ISRC code.
https://musicbrainz.org/ws/2/isrc/USRC11600201?fmt=json
But in response I don't get any metadata related to the album of the track. I get the following response:
{
"isrc": "USRC11600201",
"recordings": [
{
"disambiguation": "single remix",
"title": "Cheap Thrills",
"id": "92e27a47-3546-4bc2-a9f7-b19e43d7a531",
"length": 223000,
"video": false
},
{
"length": 218540,
"video": false,
"title": "Cheap Thrills",
"disambiguation": "",
"id": "5845e975-33b4-4b0d-8e74-8f57d128b3d1"
}
]
}
I have tried various combinations of the "inc" sub query parameter as well but nothing works. Please help me out. I am really stuck at this.
Using inc=releases in the URL parameters should be enough to get you the information that you want. However, it seems like there's a bug with MusicBrainz's JSON web service (which is still officially in beta), as you can see in the difference between the XML and JSON end points' output:
https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases&fmt=json (JSON) vs. https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases (XML).
One obvious solution/work-around here would be to switch to using the more mature XML endpoint. If that is not an option, you can use the Recording MBIDs given in the JSON output to look up releases associated with those Recordings, e.g., https://musicbrainz.org/ws/2/recording/5845e975-33b4-4b0d-8e74-8f57d128b3d1?inc=releases&fmt=json (note that inc=releases is also needed here to get the information about the releases, and it actually works when looking up recordings).
So to get the details of the album of a track when I have the ISRC of the track, we need to do the following get request:
https://musicbrainz.org/ws/2/isrc/GBUM71604605?inc=releases
It will give a response in xml. The xml api is more stable click for more details on this
As I need the response in json, we can use a library like xml to json and vice-versa library
As much as I have seen the xml response from the MusicBrainz api is more accurate and gives a lot of information.
Im here to ask if it's possible to fully use youtube data api v3 with angular 2+, the documentation just have examples from javascript like authentication, playlist videos, insert a playlist and search of videos (samples)
I'm trying to upload a video, using parameter like:
(gapi.client as any).youtube.videos.insert({
"resource": {
// Video title and description
"snippet": {
"title": "Test",
"description": "Test video upload via YouTube API"
},
"status": {
"privacyStatus": "private"
}
},
"part": "snippet,status,id",
"media": {
"body": video
})
My problem is that even like this, it always return error 404 : "The request does not include the video content.", documentation says the videos needs to be video/* or application/octet-stream, and my video object is a File extended from Blob.
What could i'm possibly doing wrong?
If it's the video file, what I have to do to work?
PS: "(gapi.client as any).youtube" has this any, because youtube is not a property from the interface, its loaded.
Solved
I'm brazilian then I was searching portuguese documentation, that is quite poor, when changed to English, I found 2 archives cors_upload.js and upload_video.js JS samples in the documentation, converted then to typescript and now it works.
Via the Youtube API, how can I detect if a video Youtube is unavailable (ex : https://www.youtube.com/watch?v=5nRZlcB2jPY) ?
Thanks
This is also partially possible without API. Let's say you want to see if the following video is available:
https://www.youtube.com/watch?v=esDJPiGu5x0
The ID of the video is shown as the GET parameter v. Use this one to request the following thumbnail:
https://img.youtube.com/vi/esDJPiGu5x0/0.jpg
If the content of the response has a length of 0 and/or the http response code by youtube.com is 404, then the video is not available anymore.
You would make an API call for the video status.
https://www.googleapis.com/youtube/v3/videos?id=VIDEOID&part=status&key=APIKEY
Then check the uploadStatus in the json result:
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}