Skip to main content

A CLI for "borrowing" music from YouTube. DJ use only, and also, you know the deal, DJs, right?

Project description

Pythief DJ

PyPI version

A semi-simple tool for... "borrowing"... audio from YouTube videos.

Here's why I do this

It's common DJ etiquette (or really just like, person-etiquette) to purchase songs that you use for your craft. I wholeheartedly endorse this ideal and do it myself. However, I'm also a bedroom DJ who mixes a lot of stuff that people never hear, and very often, I want to try mixing a song before I use it in one of my patented adorable newbie videos. YouTube is a great source for use cases like this, despite the moral dubiousness of yoinking audio from it.

However, I also found YouTube ripping a very tedious process. You search, find your video, go to one of a million "YouTube to Mp3 FAST!" sites, click multiple times, download, save, and so on, so I wrote this tool to automate some of it. I don't have the search thing figured out yet (it can be tricky to identify the right video for a song - for example, some music videos edit the original audio for dramatic effect), but right now, you can use this to download audio from multiple YouTube videos by URL, which is a step up for my workflow, anyway.

Getting started

  1. Install Python 3.9+
  2. Install FFmpeg and make sure it's in your system path by opening a command line/terminal and typing "ffmpeg"
  3. Install this tool by opening a command prompt/terminal and typing pip install pythief-dj.
  4. Download your first video by running pythief-dj [VIDEO URL] (replace [VIDEO URL] with the URL of the YouTube video of your choice.)

Note

Pythief DJ automatically tries to download the highest-quality audio stream available, but most videos encode audio at a maximum of 128kbps. This is obviously far short of the 320kbps minimum that we shoot for as DJs, but it's sufficient for trying a song out at home. Want better quality? Buy the song on a service like iTunes, Amazon Music, Beatport, etc.

Advanced tricks for turbocharged music borrowing

As a general note, you can type pythief-dj without any arguments to see options you can supply to Pythief DJ that change its behavior. It looks like this right now:

Usage: pythief-dj [OPTIONS] [VIDEOS]...

Download audio for the videos specified in VIDEOS, in --txt, or both.

Options:
  -d, --dry-run / --do-it-live  If enabled, dry run treats your input as
                                search terms rather than specific videos and
                                opens a browser tab for each term on YouTube.
                                It doesn't download anything.
  -k, --keep-raw BOOLEAN        Keep the raw MP4 files downloaded from YouTube
                                that this tool converts to MP3 for use (false
                                by default).
  -f, --format TEXT             The format into which you wish to convert the
                                audio data from the video (mp3 by default).
  -o, --out-dir DIRECTORY       The directory into which you want to save the
                                files downloaded
  -t, --txt PATH                Path to a text file containing the videos to
                                download. One per line.
  --help                        Show this message and exit.

Also...

Specifying videos

  • Video URLs can be specified either with a complete URL (e.g. https://www.youtube.com/watch?v=F7cihvwCXes) OR with the YouTube video ID, which is the part of the URL after "v" (e.g. F7cihvwCXes.)
  • You can download multiple songs at a time by adding a space between each URL, e.g. pythief-dj [VIDEO 1] [VIDEO 2] (etc.)
  • You can also create a text file of video URLs to make entry easier. Just place each URL or video ID on one line.
    • This is pretty brittle - if you enter anything but the URL on the line, stuff will probably break. Sorry.
    • This doesn't actually have to be a .txt file - anything text-encoded will do.
    • This method can be combined with URLs supplied as arguments to Pythief DJ. So if you have a text file with a few videos and a URL of another you want to add, you can enter pythief-dj --txt myfile.txt https://youtube.com/watch?v=somevideoid to download all of them at once.

Output

  • By default, Pythief DJ spits everything into a folder called pythief-dj-output in the same folder you ran the command. You can control this using the --out-dir argument.
  • The audio downloaded from YouTube come down as MP4 audio, which is massive and doesn't have dramatically better quality than MP3. Pythief DJ stores these in an intermediate directory in the output directory and then throws them away when it's done. If you want to keep them, just specify --keep-raw.

Things I'll add eventually

I'm a grad student, so my disposable time is not in high quantities. On the other hand, you never know when I'll want to avoid work. Look for these to come eventually, and if you have ideas, open an issue.

  • Configurable verbosity: Right now, it just kind of burbles at random times as it does its thing, but I'll eventually add levels of verbosity you can ask for as you run the command.
  • Entry of videos by CSV: The use case I'm thinking of here is that you might want to pre-specify the artist/title in advance, along additional ID3 tags like genre.
  • Magical automatic YouTube search: I'm currently tussling with YouTube's OAuth API, but when I'm done, I can at least try to find a song's video if you don't have the URL.

Acknowledgments

You can see requirements.txt for all of my dependencies, but I'm relying heavily on pytube, pydub, and FFMpeg, all of which are doing an incredible amount of heavy lifting in this script. Thanks to those projects.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pythief-dj-0.3.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

pythief_dj-0.3.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file pythief-dj-0.3.2.tar.gz.

File metadata

  • Download URL: pythief-dj-0.3.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pythief-dj-0.3.2.tar.gz
Algorithm Hash digest
SHA256 9983b59317068a60faa259000db15419e7879ae76df82a86384c8d1def1a18fe
MD5 4fa30432391af55655e27fe9ee5abf15
BLAKE2b-256 c440e067b6d3d534f025426a42d43fdeb2f3d30d11d51090a05d59333fec9bf1

See more details on using hashes here.

File details

Details for the file pythief_dj-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: pythief_dj-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pythief_dj-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a1d50e5506d378bca1135a8e8e948295299d14212429269cc278b7d68f4ee92b
MD5 a1b6a6d7bba24e783f3d00ad1246d7e9
BLAKE2b-256 64ca43badb7a742c70ca2373bbd9a2f4bfbf468f9be209197251d991d728987f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page