Created
June 1, 2015 18:09
-
-
Save brynedwards/8bf4c494cb2d2b512ddb to your computer and use it in GitHub Desktop.
Get date for single tracks from discogs, not always accurate
This file contains hidden or 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/python2 | |
import sys | |
import discogs_client | |
from beets import mediafile | |
USER_TOKEN = '' | |
def write_date(track, client): | |
artist = track.artist.encode('ascii', 'ignore') | |
title = track.title.encode('ascii', 'ignore') | |
q = "{} {}".format(artist, title) | |
results = client.search(q, type='master') | |
first = results[0] | |
if hasattr(first, 'main_release'): | |
year = first.main_release.year | |
else: | |
year = first.year | |
if year: | |
print('Setting {} - {} year to {}'.format(artist, title, year)) | |
track.year = year | |
track.save() | |
return | |
def main(): | |
d = discogs_client.Client('SingleTagger/0.1', user_token=USER_TOKEN) | |
files = sys.argv[1:] | |
for f in files: | |
track = mediafile.MediaFile(f) | |
if track.year is None: | |
write_date(track, d) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment