Skip to content
 
 

Repository files navigation

Python YouTube API

A basic Python YouTube v3 API to fetch data from YouTube using public API-Key without OAuth.

It can fetch video comments for a given video URL, keyword based search (returns videos, playlist, channel) and return videos data for a given channelId. It store the data into output directory in CSV files.

You are required to get the API key from Google API console in order to use this script

How to use

  • Pass --c after file name for fetching comments from videos
  • Pass --s after file name for fetching results based on search keyword
  • Pass --sc after file name for fetching videos based on YouTube ChannelId

It is mandatory to pass any of the above argument after file name

Video Comments

  • --max argument for defining the maximum result to return (default=20, acceptable values between 1 and 100) Optional
  • --videourl argument for defining the youtube URL Mandatory
  • --search_terms argument for defining the comment search terms Optional
  • --key argument for defining API key Mandatory
  • --save_folder argument for defining a save folder Optional
Example: python3 main.py --c --max 20 --videourl https://www.youtube.com/watch?v=y_j-r8x1FtI --key AAAAAAA

Search by Keyword

  • --max argument for defining the maximum result to return (default=5, acceptable values between 0 and 50) Optional
  • --search argument for giving the keyword Mandatory
  • --region argument for defining region (Country) For ex. --region="US" (Argument should be a country code) Optional
  • --location argument for geo-located search For ex. --location="(37.42307,-122.08427)" (Argument should be string coordinate pair) Optional
  • --radius argument for defining radius of geo-located search For ex. --radius=="20mi" (Argument should be number with measurement unit of m, km, ft, or mi and less than 1000km) Optional
  • --before argument for defining period before which videos should be pulled For ex. --before="1970-01-01T00:00:00Z" (Argument should be datetime) Optional
  • --after argument for defining period after which videos should be pulled For ex. --after="1970-01-01T00:00:00Z" (Argument should be datetime) Optional
  • --language argument for defining video language For ex. --language="en" (Argument should be two-letter string) Optional
  • --key argument for defining your developer API key Mandatory
  • --save_folder argument for defining a save folder Optional
Example: python3 main.py --s --search "srce cde" --max 20 --key AAAAAAA

Search Videos by YouTube ChannelId

  • --max argument for defining the maximum result to return (default=5, acceptable values between 0 and 50) Optional
  • --channelid argument for defining channel id Mandatory (restricted to 500 videos)
  • --key argument for defining your developer API key Mandatory
  • --save_folder argument for defining a save folder Optional
Example: python3 main.py --sc --channelid UCwDlyuX3Fkg5WNBufLnH6dw --max 20 --key AAAAAAA

YouTube_Comment_Collection Notebook

Use this notebook to collect comments from all videos returned by search

YouTube API v3

About

A basic Python YouTube v3 API to fetch data from YouTube using public API-Key without OAuth

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages