Skip to content

Instantly share code, notes, and snippets.

@Axel-Erfurt
Last active November 3, 2020 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Axel-Erfurt/fef4cf115fa05717092ddd1c8ea7922e to your computer and use it in GitHub Desktop.
Save Axel-Erfurt/fef4cf115fa05717092ddd1c8ea7922e to your computer and use it in GitHub Desktop.
get tracklist of album using musicbrainzngs
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
import musicbrainzngs
import sys
musicbrainzngs.set_useragent(
"python-musicbrainzngs-example",
"0.1",
"https://github.com/alastair/python-musicbrainzngs/",
)
def get_tracklist(artist, album):
result = musicbrainzngs.search_releases(artist=artist, release=album, limit=1, primarytype = 'Album')
id = result["release-list"][0]["id"]
print(f'{artist} - {album} ({result["release-list"][0]["date"][:4]})\nTracks:')
#### get tracklist
new_result = musicbrainzngs.get_release_by_id(id, includes=["recordings"])
t = (new_result["release"]["medium-list"][0]["track-list"])
for x in range(len(t)):
line = (t[x])
tracknumber = line["number"]
title = line["recording"]["title"]
print(f'{tracknumber}. {title}')
if __name__ == '__main__':
### get first release
if len(sys.argv) > 1:
artist, album = [sys.argv[1], sys.argv[2]]
get_tracklist(artist, album)
else:
artist = input("Artist: ")
album = input("Album: ")
if not artist == "" and not album == "":
get_tracklist(artist, album)
else:
print("Artist or Album missing")
@Axel-Erfurt
Copy link
Author

Usage:

python3 album_get_tracklist.py "rolling stones" "beggars banquet"

or

python3 album_get_tracklist.py

it will ask for Artist and Album

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment