implement improve file name function

pull/1/head
Yash Agarwal 2017-06-15 18:36:24 +05:30
parent 5928c632ab
commit 0795e9fdba
1 changed files with 20 additions and 17 deletions

View File

@ -12,6 +12,7 @@ def improve_song_names(songs):
blacklistWords = text_file.read().splitlines() blacklistWords = text_file.read().splitlines()
blacklistWords = [word.lower() for word in blacklistWords] blacklistWords = [word.lower() for word in blacklistWords]
improved_names = []
for song in songs: for song in songs:
searchText = song[0:-4] searchText = song[0:-4]
remove_digits = searchText.maketrans('', '', digits) remove_digits = searchText.maketrans('', '', digits)
@ -19,10 +20,14 @@ def improve_song_names(songs):
for word in song[0:-4].split(' '): for word in song[0:-4].split(' '):
if word.lower() in blacklistWords: if word.lower() in blacklistWords:
searchText = searchText.replace(word, '') searchText = searchText.replace(word, '')
print(searchText)
improved_names.append(searchText)
return improved_names
def get_metadata_acoustid(song): def get_metadata_acoustid(song):
API_KEY = 'GkQibmzT1u' API_KEY = 'GkQibmzT1u'
try: try:
results = acoustid.match(API_KEY, song) results = acoustid.match(API_KEY, song)
@ -35,20 +40,18 @@ def get_metadata_acoustid(song):
except acoustid.WebServiceError as exc: except acoustid.WebServiceError as exc:
print("web service request failed:", exc.message, file=sys.stderr) print("web service request failed:", exc.message, file=sys.stderr)
sys.exit(1) sys.exit(1)
except acoustid.FingerprintSubmissionError:
print("Error")
# for result in results:
# print(result)
first = True first = True
for score, rid, title, artist in results: for result in results:
if first: if first:
first = False first = False
else: else:
return title, artist print(result)
# print()
# print('%s - %s' % (artist, title)) if first is True:
# print('http://musicbrainz.org/recording/%s' % rid) print("No Data found for " + song + " .... Skipping it")
# print('Score: %i%%' % (int(score * 100)))
# break
def get_metadata_musicbrainz(song): def get_metadata_musicbrainz(song):
@ -68,29 +71,29 @@ def get_metadata_discogs(song_name):
d = discogs.Client('ExampleApplication/0.1', d = discogs.Client('ExampleApplication/0.1',
user_token="mbNSnSrqdyJOKorCDBXjzzeYNhgulysWNJbwgBmk") user_token="mbNSnSrqdyJOKorCDBXjzzeYNhgulysWNJbwgBmk")
results = d.search(song_name, type="release") results = d.search(song_name, type="release")
# print(results.page(1))
first_result = results.page(1)[0] first_result = results.page(1)[0]
# artist = first_result.artists[0].name
title = first_result.title title = first_result.title
print(dir(first_result.artists[0])) print(dir(first_result.artists[0]))
print(title) print(title)
print(first_result.artists[0].name) print(first_result.artists[0].name)
# print(title, artist)
def main(): def main():
files = list_files() files = list_files()
# title, artist = get_metadata_acoustid(
# "21. Jonas Blue - By Your Side (Feat Raye).mp3")
# title, artist = # title, artist =
# get_metadata_discogs( # get_metadata_discogs(
# "Jonas Blue - By Your Side (Feat Raye)") # "Jonas Blue - By Your Side (Feat Raye)")
improve_song_names(files) # files = improve_song_names(files)
# print(title, artist) for file in files:
print("-------------" + file + "------------------")
print()
get_metadata_acoustid(file)
print()
print(files)
if __name__ == "__main__": if __name__ == "__main__":