This script downloads your YouTube Music history and saves the result on your local disk.
This script uses the following packages :
- ytmusicapi to get the history
- yt-dlp to download the musics
Before installing the script, you need to create a Google API key:
- Go to the Google API Console.
- Create a new project or select an existing one.
- Enable the "YouTube Data API v3" for your project.
- Go to "Credentials" and create an OAuth 2.0 Client ID.
- Download the client secret JSON file and save it as
client_secret.jsonin theconfig/directory of this project.
-
Install the required packages:
poetry install
-
Install ffmpeg:
sudo apt install ffmpeg
-
Init the credentials (see Init credentials) then run the command
ytmusicapi oauth --file config/oauth.jsonand follow the instructions (client ID and secret are in theclient_secret.jsonfile). -
Start the script with the following command:
poetry run python youtube_music_history_downloader/download_history.py
-
Init the credentials (see Init credentials)
-
Build the image:
docker build -t youtube-music-history-downloader . -
Run the container:
docker run -it \ -v "$(pwd)/config:/app/config" \ -v "$(pwd)/output:/app/output" \ -e SCHEDULE_MINUTES=240 \ -e SLEEP_SECONDS=60 \ youtube-music-history-downloader
On first use, a message will appear to activate your Google account.
-
Init the credentials (see Init credentials)
-
Copy this to your
docker-compose.ymlfile:services: youtube-music-history-downloader: image: youtube-music-history-downloader container_name: youtube-music-history-downloader environment: SCHEDULE_MINUTES: "240" SLEEP_SECONDS: "60" volumes: - ./config:/app/config - ./output:/app/output stdin_open: true tty: true
-
Then run:
docker-compose up
On first use, a message will appear to activate your Google account.
By default, the script download musics in m4a format with the best quality available, with thumbnail and metadata.
You can update the config by copying the file config/ydl_options.default.json to config/ydl_options.custom.json.
Keep in mind that the output directory (attribute outtmpl) is handled by the script itself.
The script keeps in memory the downloaded musics to avoid downloading them again, in the file config/download_history.jsonl.