From 0b3eb479ae60ae1f035807e7e4df51fdcd4a7df9 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Thu, 4 Dec 2025 09:13:37 +0100 Subject: files --- .gitignore | 4 +++ dl-artist.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 .gitignore create mode 100644 dl-artist.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c59f32b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +my-venv/ +output/ +yt-dlp_linux +~ \ No newline at end of file diff --git a/dl-artist.py b/dl-artist.py new file mode 100644 index 0000000..78fd3fc --- /dev/null +++ b/dl-artist.py @@ -0,0 +1,82 @@ +from ytmusicapi import YTMusic +import sys +import os +import subprocess +from subprocess import Popen, PIPE, STDOUT + +try: + from subprocess import DEVNULL # py3k +except ImportError: + import os + DEVNULL = open(os.devnull, 'wb') + +ytmusic = YTMusic() + +artist_result = ytmusic.get_artist(sys.argv[1]) +artist_name = artist_result['name'] + +#print(artist_result['albums']['browseId']) + +albums = [] +singles = [] + +if 'albums' in artist_result: + albums = artist_result['albums']['results'] + if artist_result['albums']['browseId'] != None: + albums = ytmusic.get_artist_albums(artist_result["albums"]["browseId"], artist_result["albums"]["params"]) + +if 'singles' in artist_result: + singles = artist_result['singles']['results'] + if artist_result['singles']['browseId'] != None: + singles = ytmusic.get_artist_albums(artist_result["singles"]["browseId"], artist_result["singles"]["params"]) + +print('Artist "' + artist_name + '" has ' + str(len(albums)) + ' albums...') +for album in albums: + albumdata = ytmusic.get_album(album['browseId']) + album_name = albumdata['title'] + + print('Downloading "' + album_name + '"') + + # Construct the command as a list + command = [ + './yt-dlp_linux', + f"https://music.youtube.com/playlist?list={albumdata['audioPlaylistId']}", + '-o', + 'output/'+artist_name+'/'+album_name+'/%(title)s.%(ext)s', # Adjust the path as needed + '-x', + '--audio-format', + 'mp3', + '--embed-thumbnail', + '--add-metadata' + ] + + p = subprocess.Popen(command, stdin=PIPE, stdout=DEVNULL, stderr=STDOUT) + (output, err) = p.communicate() + p_status = p.wait() + print('done') + + +print('Artist "' + artist_name + '" has ' + str(len(singles)) + ' singles...') +for single in singles: + singledata = ytmusic.get_album(single['browseId']) + single_name = singledata['title'] + + print('Downloading "' + single_name + '"') + + # Construct the command as a list + command = [ + './yt-dlp_linux', + f"https://music.youtube.com/playlist?list={singledata['audioPlaylistId']}", + '-o', + 'output/'+artist_name+'/Singles/%(title)s.%(ext)s', # Adjust the path as needed + '-x', + '--audio-format', + 'mp3', + '--embed-thumbnail', + '--add-metadata' + ] + + p = subprocess.Popen(command, stdin=PIPE, stdout=DEVNULL, stderr=STDOUT) + (output, err) = p.communicate() + p_status = p.wait() + print('done') -- cgit v1.2.3-70-g09d2