New GitHub thing, YT Playlist to text file 📺

  • YT Playlist to text file

❌ Discontinued ❌

Check out my much better solution using Tampermonkey here: YT-URL-Extractor

Original Post:

Over time scraping a YouTube playlist for it's urls has become more of a challenge, for my own needs I wanted to easily and quickly grab a list of these. This Python script allows you to bulk grab a YouTube playlist page, strip out the urls and save them to a text file. It's a little non straight forward but it does work and gives you a working list to use for whatever reason you need a scraped channel list of video urls, yt-dlp batch downloads for example.

I wrote this as the yt-dlp method for getting a playlist to bulk download was not working for me (kept downloading/accessing a standard consent page), I know I could play around and tie my session ID to everything but I want to keep everything seperate to my accounts.

The script accepts the following arguments and abbreviations:

Strip YT video links from html to new file
Visit https://github.com/NebularNerd/ytplaylisttofile for more information

optional arguments:
  -h, --help            show this help message and exit
  --infile INFILE, -i INFILE
                        Path to input raw html from YT Playlist page
  --outfile OUTFILE, -o OUTFILE
                        Path to output processed file

Usage:

Using this is slightly awkward, but equally once you know very easy, this is based on Chrome, Edge and FireFox should be able to do similar:

Step One:

  • Head to a playlist page, hover over the first video, right click and use select Inspect
  • Once you can see the code look above your inspected element for a div with id="contents", left click that div, the playlist should highlight similar to the image below
  • Right click that div and select Copy > Copy Element to grab the whole div with all the video urls. Paste this into a blank text file and save it.
  • Click to enlarge 🔍

Step Two:

Open a console/command prompt and run something similar to python C:\python\ytplgrab.py -i R:\ytin.txt -o R:\ytdone.txt, adjust dirs and drives as required. It will chew through the input file, find any vids, remove duplicates, finally, create the output file with one video url to a line. This can then be used for what ever purpose you needed that list of url's for. For example, this command might be handy for some: yt-dlp.exe --ffmpeg-location "C:\FFMpeg\bin" --user-agent "Chrome/89" -o "R:\Video\%%(title)s.%%(ext)s" -f "bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b" --verbose --batch-file R:\ytdone.txt

Future plans:

  • Tidy code and add file exists check/override (either as y/n or commandline arg or both)
  • PyGUI based GUI to make it more point and click, this would skip the need for the input file at least
  • Suggestions?

Help fuel my caffine habbit

If you fancy buying me a ☕ to say thanks, please visit my Ko-Fi page by hitting the button below.

Comments