Git Product home page Git Product logo

song-downloader's Introduction

Song downloader

Downloads an entire youtube playlist (or single videos) in mp3 format, deducing and saving artist, name, remixer, tracknumber... If the song has already been downloaded updates only its metadata.

Only the audio data is downloaded.

I downloaded a ~150 songs playlist and it worked fine. I also developed an mp3-player, that can play playlists in order and save favourites.

ID3 metadata and title parsing

Imagine a playlist (id 1234567890abcdefghijklmnopqrstuvwx) whose second video (id 0a1b2c3d4e5) is titled
ArtistName feat. Ft1 | SongName [Rel release](Remixer ft. Ft2 remix). The filename would be ArtistName feat. Ft1 | SongName [Rel release](Remixer ft. Ft2 remix)_0a1b2c3d4e5.mp3 and the song's ID3 metadata would be:

artist: "Remixer (original by ArtistName)"
title: "SongName (remix)"
tracknumber: "1"
album: "1234567890abcdefghijklmnopqrstuvwx"

"tracknumber" is 1 because the video is the second one of the playlist

Usage

Choose some videos and playlists to download (for example this video and this playlist) and extract their ids (in this case "z-teFykRk0Y" and "PLR0fgOhCSN8ilC2GWuPkipy8FRNp-m-7C").

Then there are two ways to provide the script with those ids: using a file or using command line arguments (all parameters between [square brackets] are to be considered optional; | means or):

Saving ids in file

In the directory the script is executed in create a file named song-downloader-ids.txt. In that file you can insert the videos/playlists to be downloaded this way:

OPTIONS
ID [DIRECTORY]
ID [DIRECTORY]
...

"OPTIONS" are some options for the script, such as --delete to delete songs that have been removed from the playlists; learn more about them by running in the terminal python3 FILENAME --help. "ID" represents the playlist or video id/url; "DIRECTORY" is optional, represents the directory in which to save the song(s), and defaults to ./ for videos and ./ID/ for playlists. Save the file and run the script. In this case the file could be:

--delete
z-teFykRk0Y ./my_songs/
PLR0fgOhCSN8ilC2GWuPkipy8FRNp-m-7C

Passing ids as command line arguments

Open a terminal and navigate to the "DIRECTORY" the python script is in (run cd DIRECTORY). Then run python3 FILENAME OPTIONS ARGUMENTS (*) replacing "FILENAME" with the name of the script. "OPTIONS" are some options for the script, such as --delete to delete songs that have been removed from the playlists; learn more about them by running in the terminal python3 FILENAME --help. "ARGUMENTS" is the list of videos/playlists to be downloaded and must be formatted this way:

ID [DIRECTORY] - ID [DIRECTORY] - ... - ID [DIRECTORY]

Here "ID" represents the playlist or video id/url; "DIRECTORY" is optional, represents the directory in which to save the song(s), and defaults to ./ for videos and ./ID/ for playlists. If a path contains spaces, you have to sorround it with ". For example (command line commands):

> cd C:/song-downloader/
> python3 song-downloader.py --delete z-teFykRk0Y ./my_songs/ - PLR0fgOhCSN8ilC2GWuPkipy8FRNp-m-7C

(*) Note that the command used for Python is not always python3: it could be py, python, python3.6 or others too.

Result

After the process finishes the folders my_songs (containing Jim Yosef - Smile [Fairytale]_z-teFykRk0Y.mp3) and PLR0fgOhCSN8ilC2GWuPkipy8FRNp-m-7C (containing the playlist) should be in the directory the script is executed in.

Dependencies

  • Requires either Python 3.6+ (older versions have not been tested).
  • Install dependencies from requirements.txt using this command: python3 -m pip install -r requirements.txt
    It will install the following pip modules: yt-dlp; mutagen.

Notes and known issues

  • The songs are downloaded at the highest possible quality. yt_dlp.YoutubeDL is set up to download the best format that Youtube provides ("bestaudio/best")
  • To check if a song has already been downloaded uses the video id saved at the end of the filename, not its file name.
  • Automatically renames files whose corresponding video changed name.
  • Video ids and playlist ids are automatically distinguished, but if an id refers both to a playlist and to a video only the playlist is downloaded.
  • When downloading more videos with the exact same name only the first one is going to be downloaded, and it's going to be saved using the metadata of the last one.
  • Videos from platforms other than Youtube may work, but playlists won't. If two videos/playlists from different platforms are downloaded in the same folder, the id contained in their titles may generate conflicts.
  • Control characters and '<>:\"/\|?*' are automatically removed from filenames to prevent any problem with filesystems.

song-downloader's People

Contributors

stypox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

song-downloader's Issues

Handle multiple artists

When there are multiple artists they are sometimes written with "&", ",", "and", ";" as separators. Those should be recognized and the artist tag should contain all the artists in a way that they can be recognized by music players.

On a side note, should "original by .." be shown for remixed songs? They create problems with not-unique artist names in music players. Maybe they could be considered as secondary artists and added to the artist list pointed out above?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.