DEV Community

Josh Ghent
Josh Ghent

Posted on • Originally published at joshghent.com on

Downloading your Favorite YouTube Playlist Automatically

In light of Youtube-DL being taken down from GitHub, I decided to give it a go with a use case I happened to have.

Lately, I’ve been listening to lots of concerts/festival sets that are not available for traditional purchase. Although I have listened to them on youtube, I didn’t want to have the webpage open and the auto-play/queuing features are not as fledged out as a proper music player.

I decided to write a quick script that I could run in a cron to pull down the latest version of the playlist I maintain. To keep an eye on it, I included a Slack webhook notification that let’s me know when the playlist has been downloaded.

My first version worked but I quickly realised that the script did not handle updates, only a complete re-download. To resolve this, youtube-dl has a --download-archive flag that keeps track of downloaded videos.

Check out the code below and hopefully you find it useful.

#!/bin/bash

playlist_url="https://www.youtube.com/playlist?list=ZZZ"

cd ~/Projects/music

youtube-dl --embed-thumbnail --download-archive downloaded.txt --no-post-overwrites --extract-audio --audio-quality 0 --format bestaudio --audio-format mp3 --yes-playlist --output "%(title)s-%(id)s.%(ext)s" $playlist_url

curl -X POST --data-urlencode "payload={\"username\": \"youtubeb0t\", \"text\": \"Completed download of all Music playlist.\", \"icon_emoji\": \":tv:\"}" https://hooks.slack.com/services/ZZZ/YYY
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay