Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

YouTube API lists offline Livestreams as video

$
0
0

I need a list of all videos from a YouTube channel using the YouTube Data API. I used the Upload-Playlist to get this list. But I discovered, that this list contains offline livestreams as well. Does anyone know how to detect, if the type of the item is a video or livestream? In the JSON from the request is a type argument, but this says e.g.: 'resourceId': {'kind': 'youtube#video', 'videoId': 'Rul7Z2pkH1w'}.

I'm working with Python and here is my code:

import pandas as pdimport requestschannel = 'UC192SEGl9dAng9GwredMSww'api_key = '...'# build dataframedf = pd.DataFrame(columns=['channel_id','video_id','video_title','published_date','type'])playlist_id = channel[:1] +'U'+ channel[2:]url = 'https://youtube.googleapis.com/youtube/v3/playlistItems?part=id&part=snippet&part=status&playlistId='+ playlist_id +'&maxResults=50&key='+ api_keyresponse = requests.get(url=url).json()# save the channel_id and video_id in a dataframefor i in response['items']:    channel_id = i['snippet']['channelId']    video_id = i['snippet']['resourceId']['videoId']    published_date = i['snippet']['publishedAt']    video_title = i['snippet']['title']    vid_type = i['snippet']['resourceId']['kind']    df = pd.concat([df, pd.DataFrame([{'channel_id': channel_id,'video_id': video_id,'video_title': video_title,'published_date': published_date,'type': vid_type    }])], ignore_index=True)    url2 = 'https://youtube.googleapis.com/youtube/v3/videos?part=snippet&part=id&part=statistics&part=localizations&part=status&part=contentDetails&part=liveStreamingDetails&part=topicDetails&id='+ video_id +'&maxResults=50&key='+ api_key    response2 = requests.get(url=url).json()    print(response2)

Thank you in advance!


Viewing all articles
Browse latest Browse all 3638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>