/yt-music-dl

Easily download and tag music from a YouTube playlist

Primary LanguagePython

yt-music-dl

This is a command-line program to easily download and tag music from a YouTube playlist.

Installation

  1. Clone the repo, preferably onto a system that is running most of the time.

  2. Install the dependencies.

  3. Open the Google Cloud Console and log in to a Google account. If you're not already there, go to IAM & Admin --> All projects. Click 'Create project', give it a name, such as yt-music-dl, and click 'Create'.

  4. Go to API Manager --> Library and click on YouTube Data API. Click the 'Enable' button at the top-left.

  5. In the left-hand menu, go to Credentials. Click 'Create credentials' and select 'OAuth client ID'. Click 'Configure consent screen' and fill in a name you like. Save, select application type 'Other' and enter a name for the device the yt-music-dl will be running on. Click the Create button.
    You will now be presented with a client ID and a client secret. Open the config.ini file from the repo and copy these strings to their respective places in the AUTHENTICATION section.

  6. Create a playlist on YouTube and copy the ID, which is the part after ?list= in the URL. Paste this ID to PlaylistID in the config.ini file. Fill in an output directory and configure the program however you like.

  7. Run the first-time setup by typing sudo python3 yt-music-dl --setup.
    You must log in to the same Google account you use for YouTube, but that does not have to be the same account as used in step 3.

Whenever you run yt-music-dl.py, the program will download any video you put in your playlist as MP3, tag it, and then remove it from the playlist. To automatically download video's without user intervention, see Scheduling.

Scheduling

You can schedule the program to run periodically, by using cron. This way songs added to your playlist will be downloaded without any manual intervention.

Run sudo crontab -e and add a line such as this:

*/15 * * * * /path/to/python3 /path/to/yt-music-dl.py

Check out this how-to if you want to learn more about cron.

Dependencies

This program requires the following Python libraries to run:

  • httplib2
  • mutagen
  • youtube-dl

Install these dependencies by typing sudo pip3 install <package name>. The program will not function correctly without them.

The Python library youtube-dl uses ffmpeg or avconv to convert the video to audio. You will need to install at least one of these. On Raspbian, installing libav-tools will do the job.

Usage

yt-music-dl.py [-h] [-d] [--setup]

Optional arguments:

  -h, --help   Show this help message and exit
  -d, --debug  Write debug info to stdout and log file
  --setup      Perform first-time setup so that the program can run autonomously

Credits

Thanks to Guy Carpenter, for sharing his knowledge about OAuth for devices.

Author

Nimo Beeren (nimobeeren@gmail.com)

License

MIT License

Copyright (c) 2016 Nimo Beeren

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.