Last active
November 3, 2020 22:48
-
-
Save Axel-Erfurt/fef4cf115fa05717092ddd1c8ea7922e to your computer and use it in GitHub Desktop.
get tracklist of album using musicbrainzngs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
or
it will ask for Artist and Album