Ga verder naar de inhoud

Archiving YouTube comments with youtube-comment-downloader

As part of the project Best practices for social media archiving in Flanders and Brussels, various tools were tested to archive different social media platforms. This publication describes the open source tool youtube-comment-downloader to archive YouTube comments. The code of websites and the code of the tools changes constantly, it is therefore possible that at a certain point some workflows no longer work.

Youtube-comment-downloader is a command line interface tool to archive YouTube comments without using the YouTube API and its limitations. The system requirements are an installation of Python.

Install Python

Open your command line (Powershell or cmd.exe on Windows, Terminal on macOS). Type python -V or python3 -V in the window and press Enter. If you do not receive the version of your python installation as a result, then you need to install python.

Follow this guide on CEST to install python on Windows (NL), this guide to install python on macOS (NL) or this one to install on Linux (NL).

Installing on Windows

  • Download the file to a logical place, for example /User/Documents/tools/ and unpack the zip archive.
  • There is now a folder "youtube-comment-downloader" in the folder "tools", open the folder "youtube-comment-downloader".
  • Right click at the top right in Explorer and select "Open Windows Powershell"
  • Copy and paste this command python.exe -m pip install --upgrade pip into the new Windows Powershell window. It will upgrade the package manager of python.
  • Subsequently, the dependencies of youtube-comment-downloader need to be downloaded, copy and paste this command in the Windows Powershell window pip install -r requirements.txt
  • Youtube-comment-downloader is now installed!

Add youtube-comment-downloader to Windows PATH

The youtube-comment-downloader script "downloader.py" is located in this example under C:\Users\username\Documents\tools\youtube-comment-downloader\downloader.py\ which means that every time the path to the script must be passed along with the options of the tool. Or the user must first navigate to the folder of the script to start the script from there.

It is possible to avoid this by adding the script to the Windows PATH. "PATH is the system variable used by your operating system to search for necessary executables from the command line or from a terminal window", https://java.com/en/download/help/path_en.html.

This step is optional but is used in this guide, keep in mind that if you do not perform this step you must enter the full path to the script to use it.

  • Press windows key + r

  • In the "Run" or "Execute" window, enter systempropertiesadvanced and press Enter.

  • Click on "Environment Variables" in the following window, "System Properties".

  • In the top window scroll until you find the entry "Path" select the line and click the button Edit.
  • If all goes well, the "Modify environment variable" window will open, first click on New and then on Browse.

  • Navigate to the installation folder of youtube-comment-downloader, click ok when the folder is selected.

  • The python script of youtube-comment-downloader, downloader.py can now be executed from any folder in the command line on Windows.

Installing on macOS

  • Go to https://github.com/egbertbouman/youtube-comment-downloader and click the green button at the top right "Code". Download the code as a ZIP file to Documents/tools/ and create the folder if it doesn't exist.
  • Double-click the zip archive. A new subfolder will be created with "youtube-comment-downloader" as its name.
  • Open a new terminal window. CMD + SPACE, search for "Terminal" and press ENTER.
  • Copy and paste this command and execute it: cd ~/Documents/tools/youtube-comment-downloader/
  • Install the dependencies of youtube-comment-downloader with pip install -r requirements.txt
  • Youtube-comment-downoader is now installed and ready to use.

Add youtube-comment-downloader to $PATH environment variable (Optional)

This is useful but optional, and will ensure that downloader.py can be executed without specifying the full path.

Assuming the Python script is located at /Users/username/Documents/tools/youtube-comment-downloader/. This is the case if you have cloned the repository to the "tools" folder.

Adjust the commands depending on the installation location, replace username with your own username. (The username can be found with whoami, followed by Enter.

  • Open a new terminal window and paste this which python3 followed by Enter. The response is normally a path to the python3 binary.
  • Change the shebang in the python script so that it refers to the Python3 binary, copy and paste this command sed -i '' "s/python/python3/g" ~/Documents/tools/youtube-comment-downloader/downloader.py.
  • Execute the following command to create a bash_profile file, nothing will be changed if the file already exists. touch ~/.bash_profile
  • Add the youtube-comment-downloader folder to the environment variable, with the following command: sudo echo 'export PATH="~/Documents/tools/youtube-comment-downloader:$PATH"' >> ~/.bash_profile && source ~/.bash_profile.
  • Copy and paste the following command to make the script executable sudo chmod +x ~/Documents/tools/youtube-comment-downloader/downloader.py
  • The "downloader.py" script can now be used from any location in the terminal. Test this with cd && downloader.py -h. The response should display the help section of the tool.

Installing on Linux

Install youtube-comment-downloader

  • Open a new terminal window with ctrl + alt + t.
  • Navigate to the folder where you want to install the tool, for example ~/home/yourusername/bin/ create and navigate to the following folder this command mkdir ~/home/yourusername/bin/ && cd ~/home/yourusername/bin/.
  • Execute git clone https://github.com/egbertbouman/youtube-comment-downloader to retrieve the code of youtube-comment-downloader.
  • Navigate to the new subfolder with cd youtube-comment-downoader followed by Enter.
  • Execute pip install -r requirements.txt or pip3 -r requirements.txt to install the tool.
  • Youtube-comment-downloader is now installed.

Add youtube-comment-downloader to $PATH environment variable (Optional)

The python script of the youtube-comment-downloader project is now located in the folder /home/yourusername/bin/youtube-comment-downloader/downloader.py.

To avoid having to enter this path every time you use it, the script can be added to the environment variable.

This means that a line must be added to the bashrc file and the first line (shebang) of the script is modified.

All commands assume that the youtube-comment-downloader repository is cloned in /home/username/bin/, so replace "username" with your username.

  • Open a new terminal window with ctrl + alt + t
  • Execute this command which python3 followed by Enter. The response is normally a path to the python3 binary.
  • Modify the shebang in the python script so that it refers to the Python3 binary, copy and paste this command sed -i 's/python/python3/g' /home/yourusername/bin/youtube-comment-downloader/downloader.py
  • Subsequently, sudo echo 'export PATH="/home/yourusername/bin/youtube-comment-downloader:$PATH"' >> ~/.bashrc && source ~/.bashrc
  • And finally, sudo chmod +x ~/bin/youtube-comment-downloader/downloader.py.

Usage

The Youtube-comment-downloader project consists of a python script, downloader.py, usage proceeds according to the following pattern:

downloader.py [--youtubeid YOUTUBEID] [--output OUTPUT]
. Opening the "help" menu goes with downloader.py -h.

The original documentation can be found here: https://github.com/egbertbouman/youtube-comment-downloader

The YouTube ID is always the last part of the YouTube video url.

--youtubeid YOUTUBEID or -y YOUTUBEID: Replace "YOUTUBEID" with the id of the youtube video. --output OUTPUT.jsonl or -o OUTPUT.jsonl: Replace OUTPUT here with the desired title of the .jsonl file.

When a YouTube video ID starts with a "/", use the option -y=-idwithdash or --youtubeid=-

Examples:

Download comments from this YouTube video https://www.youtube.com/watch?v=75yKT3OuE44, the ID in this case is 75yKT3OuE44.

downloader.py -y 75yKT3OuE44 -o computerphile.jsonl

A portion of the archived comments in jsonl format.
{"cid": "Ugx0Gyc00tbk7QNizCF4AaABAg", "text": "I like this man, please more!", "time": "6 days ago", "author": "Linus Man", "channel": "UC_kqGlIF3qwvRD8_HGXnCVA", "votes": "5", "photo": "https://yt3.ggpht.com/ytc/AAUvwnh_hWZPQHlZcF7jBwg6_erzkVqlg1_XOuH4lQ=s48-c-k-c0xffffffff-no-rj-mo", "heart": false}

{"cid": "UgzLL-SbcthoKRXuO0d4AaABAg", "text": "I've been using traceroute for 20 years and never actually knew how it worked, fascinating!", "time": "1 day ago", "author": "Rational Raven", "channel": "UC4dZG3D71TVakPRWWvx5QUw", "votes": "1", "photo": "https://yt3.ggpht.com/ytc/AAUvwnj1FA10zwNJ_GsZKMYJ5NjcTd85VXxoeAFhB3Mi=s48-c-k-c0xffffffff-no-rj-mo", "heart": false}

{"cid": "Ugwoi6c_LceonkXjMud4AaABAg", "text": "Speaking of traceroute, hello from Lawrence Berkeley National Laboratory!", "time": "6 days ago (edited)", "author": "Michael Smitasin", "channel": "UCQostpfeegpBE8ouw13uYUw", "votes": "4", "photo": "https://yt3.ggpht.com/ytc/AAUvwnhJhfvoRieSdvqE0o1lD-MVIT2bAC2p51o7KP7STg=s48-c-k-c0xffffffff-no-rj-mo", "heart": false}

{"cid": "Ugx6ydRpgB_-ia1D05V4AaABAg", "text": "Can we get the python code?", "time": "6 days ago", "author": "Eddy Bames", "channel": "UC7eZDo5sriiluRpx6UhIV8g", "votes": "25", "photo": "https://yt3.ggpht.com/ytc/AAUvwnhUDBmcBdyNIZbr4OVH2rXbk7wrfzKwN131Rg=s48-c-k-c0xffffffff-no-rj-mo", "heart": false}

{"cid": "UgwVBRfCH7j3xPSomJV4AaABAg", "text": "Regarding the paths going through the US: there's almost certainly more and higher bandwidth cables running across the Atlantic, across the US and then across the Pacific than across Russia & China or Egypt/Suez & the Indian Ocean.", "time": "6 days ago", "author": "RonJohn63", "channel": "UCTMNOSp7-nzuK2f8LK0SAww", "votes": "11", "photo": "https://yt3.ggpht.com/ytc/AAUvwnjYk1_CQOP6wej1gxI84LFh58QrsuiBzMkekfcU=s48-c-k-c0xffffffff-no-rj-mo", "heart": false}

{"cid": "UgwXbuL_Il1uiLlcyi94AaABAg", "text": "That classic 2D map scene really reminds me one of my favorite game ever .. uplink from introversion software ..", "time": "6 days ago", "author": "Andre Amorim", "channel": "UCilprwYUC_btSGxybDMNM7g", "votes": "17", "photo": "https://yt3.ggpht.com/ytc/AAUvwnil2V959n7mEYV3KCAVzr7_M3djHvoDx1h8ZsVNeq8=s48-c-k-c0xffffffff-no-rj-mo", "heart": false}

Deze pagina is laatst aangepast op 04 oktober 2025

Deze pagina aanvullen of corrigeren?

Foutje gespot? Of heb je aanvullende inzichten? Deel je ervaringen via onderstaande knop.