Use the YouTube API to check if a video is embeddable - javascript

I'm trying to figure out if a YouTube video is embeddable using the YouTube Data API v3, from answers to similar questions I noticed the status.embeddable property of videos, for a request like this:
https://www.googleapis.com/youtube/v3/videos?id=63flkf3S1bE&part=contentDetails,status&key={MY_API_KEY}
The response is the following
{
"kind": "youtube#videoListResponse",
"etag": "\"ksCrgYQhtFrXgbHAhi9Fo5t0C2I/ctZQYtBcOuMdnQXh8-Fv1EbS_VA\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"ksCrgYQhtFrXgbHAhi9Fo5t0C2I/Cd8aGZD09NPuGYNumIEozZs2S90\"",
"id": "63flkf3S1bE",
"contentDetails": {
"duration": "PT8M23S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"projection": "rectangular"
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true,
"madeForKids": false
}
}
]
}
The embeddable parameter under status is returned as true, HOWEVER this video is not actually embeddable, as can be seen here.
When actually embedding the video using the iframe API, there is a more detailed error message as well:
Video unavailable
This video contains content from International Olympic Committee, who has blocked it from display on this website or application.
Watch on YouTube
I don't see how it is possible to detect this case from the YouTube Data API - can anyone help out?

Other option is used in this answer:
Here, you can use the following URL:
https://www.youtube.com/get_video_info?video_id=<VIDEO_ID>
Where VIDEO_ID is the YouTube video_id you want retrieve the information.
In this case, once you get the response, you'll see a property called "playabilityStatus.status".
Here is a extract of the response:
"playabilityStatus": {
"status": "UNPLAYABLE",
"reason": "The video is not available",
"errorScreen": {
"playerErrorMessageRenderer": {
"reason": {
"simpleText": "The video is not available"
},
Additional to johnh10's answer, some of the results saw in the YouTube webpage is not always shown/available in the APIs.

I have the answer. The file that outputs from the https://www.youtube.com/get_video_info?video_id=
is nothing more than a standard text file that is URLENCODED.
To see it properly you first have to DECODE it using a URLDECODER and then you have to separate the json part from the URL querystring part. To take a look at the JSON part you can use a json formatted and to look at the URL part you can use PrettyPrint URL.
Once you do this you will notice that the tag you are looking for to validate weather the video is playable or not is the one mentioned by the other user here. It sits on the URL parameter named "player_response", after you DECODE the file you will find it easily. This parameter holds a longer JSON file that has the playability status under playabilityStatus.Status.
To manipulate it on Javascript simply parse this part of the file as a JSON file and access your node of choice, or parse it as a text and search for the playabilityStatus node that must be unencoded if you dont care to decode it (nothing to fear, only some %2D and %7B instead of spaces and curly brackets).
Good luck!

Unfortunately, this 'copyright check' happens directly from the player. This data is not available through the API.

Related

Dropbox api gets direct file url for streaming

I am using dropbox api to lest files in public folder with endpoint https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
https://api.dropboxapi.com/2/files/list_folder
Response is something like this:
{
"entries": [
{
".tag": "file",
"name": "01.mp4",
"path_lower": "/video/01.mp4",
"path_display": "/video/01.mp4",
"parent_shared_folder_id": "3022865105",
"id": "id:FDeU6KOzmRUAAAAAAAAABw",
"client_modified": "2022-09-14T15:54:42Z",
"server_modified": "2022-09-14T16:06:36Z",
"rev": "5e8a55037c991b42d42d1",
"size": 12347528,
"sharing_info": {
"read_only": false,
"parent_shared_folder_id": "3022865105",
"modified_by": "dbid:AACtZetM6hKYpGsPZvtNDZUFRldH8r35OSk"
},
"is_downloadable": true,
"content_hash": "7e6d5e0d1947523808762a6fc34fec7651393ef9d4f4ea2a64fb71acaf3a1240"
},
{
".tag": "file",
"name": "02.mp4",
"path_lower": "/video/02.mp4",
"path_display": "/video/02.mp4",
"parent_shared_folder_id": "3022865105",
"id": "id:FDeU6KOzmRUAAAAAAAAACA",
"client_modified": "2022-09-14T15:54:42Z",
"server_modified": "2022-09-14T16:06:36Z",
"rev": "5e8a55037c992b42d42d1",
"size": 18791452,
"sharing_info": {
"read_only": false,
"parent_shared_folder_id": "3022865105",
"modified_by": "dbid:AACtZetM6hKYpGsPZvtNDZUFRldH8r35OSk"
},
"is_downloadable": true,
"content_hash": "93d33bf10fa4e5c340dac84ebafb54d0b2759cc6e801da8ab03ae14783365fac"
}
],
"cursor": "AAGUGbHG7ju_3pegzOTPruYbexWxEXYyJGNt5Rt1Frj8QAj_JFDTwppfDTneAq-pMfGEbX4i-aDRndn8j-MrAiLy4mCUDc8-GU_XsUdAoShGXtzWKDsDaQwWCHFmhOo0bBuXElarr3Rdil9pTMqkMcfG2hSZPeepDL_omI0Oo0a-_suATq_zoBrH-o2zNKe9-udR2UrsgPuMl9toei-Tt19FCLHX4uzyT6xAXJjFKnWdfj7y3lgyoxrJqtQPVBc1WT0",
"has_more": false
}
My question is how do I get a direct url link to each file in such a way that I can use it in (let's say) an html5 video tag?
When I right click on a file inside a dropbox folder, the url is something like this:
https://www.dropbox.com/s/305pjdhly2w948y/01.mp4?dl=0
How do I get a direct url like this from this response?
The Dropbox API doesn't offer a way to get such links in bulk. You'll need to make a call to make a link for each file.
To get temporary direct link for a file, you would call /2/files/get_temporary_link:
https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link
The Dropbox API doesn't offer a non-temporary version of that exactly, but you can create a shared link via /2/sharing/create_shared_link_with_settings:
https://www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_settings
Or to retrieve existing shared links, use /2/sharing/list_shared_links:
https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_shared_links
That's the same kind of link as returned by the Dropbox web site.
Note that these shared links don't link directly to the file data though. They link to the HTML preview page for the file. You can modify them for direct or raw file access instead though as documented here:
https://help.dropbox.com/share/force-download

What paramater am I missing for YouTube Data API Insert method

I'm using Google's Apps Script for this project. I'm using the YouTube data API V3 and of that API I am using the PlaylistItems class. I'm trying to insert a video into a playlist and I've pieced together what I can from the documentation that they have given.
YouTube.PlaylistItems.insert({
"part": [
"snippet"
],
"resource": {
"snippet": {
"playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": testVidId
// testVidId is the ID of the video I'm trying to insert
}
}
}
});
When I run this though, I get an error of
Exception: Invalid number of arguments provided. Expected 2-3 only
My question is: what argument am I missing?
I believe your goal as follows.
You want to insert an item to the play list using Google Apps Script.
Modification point:
When YouTube.PlaylistItems.insert(resource, part) is used, the arguments are resource, part which are an object and an array of string, respectively.
When your script is modified, it becomes as follows.
Modified script:
YouTube.PlaylistItems.insert(
{
"snippet": {
"playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": testVidId
}
}
},
["snippet"]
);
Note:
Before you use this, please confirm whether YouTube Data API v3 is enabled at Advanced Google services, again.
Reference:
PlaylistItems: insert

Youtube Data API V3 Javascript

I'm working right now on uploading youtube videos from a web client to Youtube.
I want to use Javascript to upload video and show the uploaded video before post the url uploaded to my server database.
So the first thing i did is to create an account in Youtube console. and activating Youtube Data Api and then i created an ID clients OAuth 2.0 with the type : Web application and id client has this form : 000000-x1x1x1.apps.googleusercontent.com i have also add an authorized referrer : http://127.0.0.1:3300 since i work in localhost.
So it seems that all is well configured, I've followed the official tutorial youtube gives but when i try to upload a video i had this error :
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for: is not a valid value"
}
],
"code": 400,
"message": "Invalid value for: is not a valid value"
}
}
Does any one had this error?
Thanks
I figured it out why i couldn't upload a video the tutorial Youtube gives is not complete Youtube Javascript upload, there is some parameters that i must send and the params i needed are title, description and finally and the most wanted privacyStatus, what i did is adding two text fields with ids #description and #title and fill those text fields with correct data And at last fill the privacyStatus with (private|public) this mean how you want your video to be uploaded.
You can update the upload js file given by Youtube like so :
var metadata = {
snippet: {
title: $('#title').val(),
description: $('#description').text(),
tags: this.tags,
categoryId: this.categoryId
},
status: {
privacyStatus: "public"
}
};

Parsing this JSON data with JavaScript

We have a working PHP function that grabs specific YouTube video information using YouTube API v3.
We're trying to use JavaScript (jQuery) to do the same thing. The issue is that using our PHP function causes the page to load very slowly while it's retrieving the data. We're hoping that using JavaScript will allow our page to load before (or during) the data requests from YouTube.
First of all, this is an example url for one of our videos (you will need an API key to see the returned information yourself):
https://www.googleapis.com/youtube/v3/videos?part=statistics&id=ce5KbCTfHoA&key={YOUR_API_KEY}
That specific url will return this information:
{
"kind": "youtube#videoListResponse",
"etag": "\"jOXstHOM20qemPbHbyzf7ztZ7rI/qRFx1vTFF-k7dkRzNB5rGQ-dqiQ\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"jOXstHOM20qemPbHbyzf7ztZ7rI/2yn7rCfXCu0o-GNVtMEQqYssSpE\"",
"id": "ce5KbCTfHoA",
"statistics": {
"viewCount": "33169",
"likeCount": "281",
"dislikeCount": "3",
"favoriteCount": "0",
"commentCount": "85"
}
}
]
}
We are trying to retrieve the likeCount and dislikeCount of this video using JavaScript.
We can achieve this using PHP in the following manner:
function getVideoRatings() {
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id={VIDEO_ID}&key={YOUR_API_KEY}");
$json_data = json_decode($JSON, true);
$likes = $json_data['items'][0]['statistics']['likeCount'];
$dislikes = $json_data['items'][0]['statistics']['dislikeCount'];
/* some other code... */
}
This successfully parses the json information returned by google and returns the likes (likeCount) and dislikes (dislikeCount) for the video.
We'd like to do this using JavaScript (jQuery). Can anyone please help me figure this out?
I really appreciate any help or bump in the right direction.
Thanks
$.getJSON("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=ce5KbCTfHoA&key={YOUR_API_KEY}", function( data ) {
var likes = data['items'][0]['statistics']['likeCount'];
});
This should work. Use jQuery documentation.

How to get youtube video description with video id?

I am currently using the Javascript API by youtube to display a video on my web page however now I want to also retrieve the youtube description from the video id? How would I go about doing this?
I only want description and title:
ex:
"kind": "youtube#video",
"etag": etag,
"id": string,
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"thumbnails": {
(key): {
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
https://developers.google.com/youtube/v3/docs/videos
If anyone could post a link or either show me an example of code on how I can accomplish this?
The developer documentation you linked to has some excellent code examples -- that'll be the best place to start. Use the "list" reference menu for videos.
If you're saying that you just want the title and description without the other fields, you can use the fields parameter in your request ... something like this:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={VIDEO_ID}&fields=items/snippet/title,items/snippet/description&key={YOUR_API_KEY}

Categories

Resources