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

How to filter out shorts from a response of youtube videos

$
0
0

I'm trying to datascrape videos from a youtube channel but I don't want shorts, and I haven't seen anything in the meta data to get rid of shorts.

They are all listed as youtube#video, not youtube#short or something of the likes.

Here is my code:

import requestsimport jsondef details(channel_id):    PLAYLIST_ID = 'UU'+ channel_id[2:]    API_KEY = '...'    URL = f'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={PLAYLIST_ID}&maxResults=50&key={API_KEY}'    pageToken = ''    while True:        pageUrl = URL        if pageToken != '':            pageUrl += f'&pageToken={pageToken}'        response = json.loads(requests.get(pageUrl).text)        if 'items' in response and response['items'] is not None:            print(response['items'])            with open('j.json', 'w') as json_file:                json.dump(response['items'], json_file)            return response['items']        else:            break        if 'nextPageToken' in response:            pageToken = response['nextPageToken']        else:            break

Viewing all articles
Browse latest Browse all 3831

Trending Articles



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