Using a Python script to extract data from YouTube using the YouTube Data API V3 and extract the results to a .csv file.
To use the script, you'll require access to the YouTube API. Go to
YouTube Data API and follow the
steps to enable you access the Data API with your own API_KEY
To install the packages used in this project and you would require conda
(miniconda or anaconda).
After cloning the repository run the following commands:
cd youtube-data-extractor
then
conda env create -f environment.yml
Now run the command conda activate youtube-data-env
to activate the conda environment
with the required packages.
You can run conda deactivate
to deactivate the environment.
After activating the environment, run python youtube-data-extractor.py
to run the
script with it's default values.
You can specify your arguments for the search by using one of the following methods:
python youtube-data-extractor.py -q fraud -r 20 -t long -d 2021
or
python youtube-data-extractor.py --query fraud --results 20 --duration long --date 2021
-q, --query
: Specify the search query. The default value is '#endsars'.
-r, --results
: Specify how many items to include the search results. The allowed input
should be an integer from 0 to 50. The default value is 10.
-t, --duration
: Specify how long the videos from the search results should be.
Options:
- any: Any video length.
- short: Videos length between 0 and 4 minutes.
- medium: Video length between 4 and 20 minutes (inclusive).
- long: Video length greater than 20 minutes.
The default value is medium.
-d, --date
: Specify a date to filter the search results from. The default value is
01-01-2020.