Can't get endAt on videos when calling - youtube-api

I'm using GET https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails%2Csnippet&maxResults=50&playlistId=PLFs4vir_WsTwwb2zqmtE2WTEFdc7AQHnc&key={YOUR_API_KEY}
This returns all data, but only videoId in each video contentDetails. Maybe I'm missing something here?

YouTube has removed the features that set start and end times to playlist items: here's a product forum post that details this (and indicates an official response from Google account reps):
https://productforums.google.com/forum/#!topic/youtube/Gipu_cCDScI
Since playlists can no longer set start/end times on its items, the API no longer delivers them.

Not an answer, but a workaround. You can retrieve a playlist and use videos list with up to 50 videoIds in the URL to retrieve each video duration.

Related

How can I exclude shorts from YouTube API Data v3

I currently use something like https://www.googleapis.com/youtube/v3/search?part=id&order=date&channelId=CHANNELID&maxResults=1&type=video&key=KEY and I want to be able to retrieve only the latest video and to totally exclude shorts.
How can I achieve this? 🤔
The Youtube search method
Will allow you to search for things like keyword, location, events, your own videos and related videos.
There is no way to filter or limit videos returned. Your only hope would be to sort them out locally when you get the results.
You may want to add a feature request here there is this one but it's really old Search API: More flexible/logical videoDuration requests
(sorry its my 1st time answering at stackoverflow, so might not be descriptive)
if you you use youtube serch method
then you'll realise that shorts description are assigned as empty string "" where as the videos have some description . so with an if condition like below can slove your problem (js)
if(!(video.snippet.description == ""))

Tracking down URLs of deleted videos in a youtube playlist

I've recently made a Python program using the Youtube api v3 where, given a playlist id, it fetches certain information from every video in the playlist. However, through both the output of this code and this post on Google, it's pretty clear that information on videos that were either privated or deleted is not available through the Youtube api.
Is there an alternative program or resource that I can use to extract information from these unavailable videos, in particular their video ids?
The only solution I can think of now is to access the HTML of the display Youtube and search through it for certain strings (like "[deleted video]") and to then extract the id corresponding to that string. But, I've never dealt with HTML and, if I understand HTML correctly, I'd have to load a new page for every 50 videos in the playlist, which for playlists with thousands of videos, becomes rather inefficient and laborious.
I was hoping to use something like PyTube, but that couldn't handle unavailable videos either.
Edit
Here is the code that extracts the video ids:
from googleapiclient.discovery import build
api_key = "AI~~~" #get from yt (private key)
yt = build("youtube", "v3", developerKey = api_key)
plst_id = "PLorw3mfu-J0ipF4Ss0XgR8IxcwP-JzNKC" #unique yt playlist id
plst_req = yt.playlistItems().list( #request for info from yt api
part = "contentDetails",
playlistId = plst_id,
maxResults = 50
)
plst = plst_req.execute()
vid_ids = [] #available video ids taken from current playlist
for vid in plst['items']:
vid_ids.append(vid['contentDetails']['videoId'])
print(vid_ids)
print(plst['pageInfo']['totalResults'])
The first line printed contains the video ids of every available video in the playlist. The second line printed gives the number of videos in the playlist, including available and unavailable ones.
The playlist used in the code above is given here. It contains 10 total videos, of which one of them is unavailable.
In this case, the output is (with a valid api key)
['bv_cEeDlop0', 'mRKTOZmX2cE', '5ACvKdx1nns', 'wSNhP8b_Avo', 's56cHgokPlE', 'E4IHMWnQiMw', 'sCDkPShADSc', 'EVwgeUVVDYU', 'Z8Mqw0b9ADs']
10
Youtube still treats unavailable videos as an element of the playlist, but does not give out it's video id. In this particular instance, the video id of the unavailable video is "t83zUmjr05I", which is not hard to find manually: copy the link address of the deleted video and extract the part after the "v=".
But, on a larger scale manual extraction becomes tedious.
Here's a permanent fix to that!
You can try tube_dl.
pip install tube_dl
It uses modular approach and is up to date
More about this can be found at : https://github.com/shekharchander/tube_dl/
Maybe, the playlist module can help you with that. It uses regex to grab all video IDs not JSON. Please let me know if the problem is fixed or not, I will update module accordingly.
Edit
Here's the working code
from tube_dl import Playlist
p = Playlist('https://youtube.com/playlist?list=PLorw3mfu-J0ipF4Ss0XgR8IxcwP-JzNKC').videos
print(p)

How list all videos from a YouTube channel?

https://www.googleapis.com/youtube/v3/channels?id=UC_x5XG1OV2P6uZZ5FSM9Ttw&part=snippet%2CcontentDetails%2Cstatistics&key={YOUR_API_KEY}
Using this API link, I get a list of videos from start but not all videos. I only get 300 to 500 videos.
This is a bit complicated. You have to make a few calls instead.
find the channel ID of the channel you want.
list playlists (youtube.channels.list set id to channelId and set part to contentDetails)
find the ID of the playlist with name uploads
list playlist items (youtube.playlistItems.list set playlistId and set part to snippet optionally set maxResults to 50)
Page through results using nextPageToken
Found this from here https://stackoverflow.com/a/27872244/975887
Hope this helps.

YouTube API - get tags for all videos with playlist query

I'm querying YouTube channels to retrieve playlist metadata like this:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=5&playlistId={PLAYLIST_ID}&key={API_KEY}
This query returns an array of all of the videos on the channel. Each object in that array includes various fields that provide metadata on each video, but none of these fields include the tags associated with the video. I can get that data using a query like this:
https://www.googleapis.com/youtube/v3/videos?key={API_KEY}&fields=items(snippet(title,description,tags))&part=snippet&id={VIDEO_ID}
The problem with that is that now I need to issue a separate query for every single video that comes back in the first query.
So, my question is, is there a way that I can get these tags included as part of the initial JSON object from the first query? Can I add any parameters that will request this data be included with that response?
Thanks for any help!
Short answer: No.
The PlaylistItems: list documentation does not show a way to get video tags from the playlistItems endpoint. The only parts available are id, snippet, status and contentDetails and neither of those contain tags.
However!
You do not have to make a request for each video in the playlist! The documentation states:
The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's ID. (string)
That means you can supply multiple, comma-separated video ids to the videos endpoint.
Example:
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=kOkQ4T5WO9E,a59gmGkq_pw,Io0fBr1XBUA&key={YOUR_API_KEY}
So in total, it will cost you two requests to get the tags of all videos in a playlist.*
*In practice, you might have to make more than two requests. If I remember correctly, YouTube limits the returned items to 50 per request. Thus, if the playlist contains more than 50 videos, you will have to make another request with the pageToken parameter set.

youtube v3 api : get all live streaming playlist ids of a channel

I have two "Live streaming/live broadcast saved playlists" in following youtube channel --> https://www.youtube.com/user/swaminarayanlive.
I am trying to retrieve all the "live streaming / live broadcast playlists" of a channel using new youtube v3 api by using the below link-->
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}
here i can get the info of playlists which are not live streams or live broadcast. and not able to get the same for the live one.
Please help me how can i get that for live one using youtube v3 api
I was researching another issue with the API when finding this, and when I saw that this was never resolved, I decided to look into it. It turns out that this is related to that other issue.
The YouTube API v3 lacks support for saved playlists. The channel swaminarayanlive did not create the playlists, only saved them from the channel BhujMandir.
The workaround in your case would be to retrieve the playlists of BhujMandir and extract the response snippets with "title" parameters containing the word "Live".
You would need to go through the pages and search each one for this, since there is a limit to how many results an API response can show at once. Currently it's 50.
So, you would use the following to get the first page of playlistItems:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&key={YOUR_API_KEY}
This will return an API response containing the properties "kind" (which will have the value "youtube#playlistListResponse") and "etag". If there are more than 50 results, there will also be a "nextPageToken" property. (On a page that is not the first, there would also be a "prevPageToken" property.)
After these properties, there are two blocks. One called "pageInfo", containing info about how many results (playlists) there are and how many are shown per page, and one block called "items", containing the resulting playlistItems.
You would look through the items block for any playlistItem with a title property (which is a string) containing the substring "Live" and get the id properties of those. You would then look on the next page by using the nextPageToken's value in a new HTTP request, like so:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&pageToken=[nextPageToken_value_here]&key={YOUR_API_KEY}
As of now, the two playlists you're looking for are on the pages with tokens CJYBEAA and CMgBEAA.
I think that where is the {YOUR_API_KEY} you should change this code and insert the name of your application program interface

Resources