implement search by acoustid
parent
84d6a9d59e
commit
5928c632ab
|
@ -3,4 +3,5 @@
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
!.vscode/
|
!.vscode/
|
||||||
*.mp3
|
*.mp3
|
||||||
|
aidmatch.py
|
111
addMetadata.py
111
addMetadata.py
|
@ -1,38 +1,62 @@
|
||||||
import musicbrainzngs as m
|
|
||||||
import sys
|
import sys
|
||||||
from mutagen.id3 import ID3
|
|
||||||
from mutagen import File
|
|
||||||
import os
|
import os
|
||||||
import mutagen
|
import mutagen
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
import spotipy
|
import acoustid
|
||||||
|
import discogs_client as discogs
|
||||||
def improve_song_name(song):
|
from string import digits
|
||||||
return song
|
|
||||||
|
|
||||||
|
|
||||||
def get_metadata(song):
|
def improve_song_names(songs):
|
||||||
spotify = spotipy.Spotify()
|
text_file = open("blacklist.txt", "r")
|
||||||
results = spotify.search(song_name, limit=1)
|
blacklistWords = text_file.read().splitlines()
|
||||||
|
blacklistWords = [word.lower() for word in blacklistWords]
|
||||||
|
|
||||||
results = results['tracks']['items'][0] # Find top result
|
for song in songs:
|
||||||
album = results['album']['name'] # Parse json dictionary
|
searchText = song[0:-4]
|
||||||
artist = results['album']['artists'][0]['name']
|
remove_digits = searchText.maketrans('', '', digits)
|
||||||
song_title = results['name']
|
searchText = searchText.translate(remove_digits)
|
||||||
album_art = results['album']['images'][0]['url']
|
for word in song[0:-4].split(' '):
|
||||||
|
if word.lower() in blacklistWords:
|
||||||
|
searchText = searchText.replace(word, '')
|
||||||
|
print(searchText)
|
||||||
|
|
||||||
|
|
||||||
|
def get_metadata_acoustid(song):
|
||||||
|
API_KEY = 'GkQibmzT1u'
|
||||||
|
try:
|
||||||
|
results = acoustid.match(API_KEY, song)
|
||||||
|
except acoustid.NoBackendError:
|
||||||
|
print("chromaprint library/tool not found", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
except acoustid.FingerprintGenerationError:
|
||||||
|
print("fingerprint could not be calculated", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
except acoustid.WebServiceError as exc:
|
||||||
|
print("web service request failed:", exc.message, file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# for result in results:
|
||||||
|
# print(result)
|
||||||
|
first = True
|
||||||
|
for score, rid, title, artist in results:
|
||||||
|
if first:
|
||||||
|
first = False
|
||||||
|
else:
|
||||||
|
return title, artist
|
||||||
|
# print()
|
||||||
|
# print('%s - %s' % (artist, title))
|
||||||
|
# print('http://musicbrainz.org/recording/%s' % rid)
|
||||||
|
# print('Score: %i%%' % (int(score * 100)))
|
||||||
|
# break
|
||||||
|
|
||||||
|
|
||||||
|
def get_metadata_musicbrainz(song):
|
||||||
|
return
|
||||||
|
|
||||||
return artist, album, song_title, album_art
|
|
||||||
|
|
||||||
def add_metadata(files):
|
def add_metadata(files):
|
||||||
# tags = File("/home/yash/Desktop/music-tagger/sample_songs/02. DJ Snake - Let Me Love You (Feat. Justin Bieber).mp3")
|
return
|
||||||
# print(tags)
|
|
||||||
for file in files:
|
|
||||||
print(file)
|
|
||||||
tags = File(file)
|
|
||||||
song_name = basename(file[:-4])
|
|
||||||
song_name = improve_song_name(song_name)
|
|
||||||
|
|
||||||
title, artist, album, cover_art = get_metadata(song_name)
|
|
||||||
|
|
||||||
|
|
||||||
def list_files():
|
def list_files():
|
||||||
|
@ -40,20 +64,33 @@ def list_files():
|
||||||
return [f for f in os.listdir('.') if f.endswith('.mp3')]
|
return [f for f in os.listdir('.') if f.endswith('.mp3')]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def get_metadata_discogs(song_name):
|
||||||
m.set_useragent(
|
d = discogs.Client('ExampleApplication/0.1',
|
||||||
"RepairMusicMetadata", "0.1", "https://yashagarwal.me")
|
user_token="mbNSnSrqdyJOKorCDBXjzzeYNhgulysWNJbwgBmk")
|
||||||
|
results = d.search(song_name, type="release")
|
||||||
|
# print(results.page(1))
|
||||||
|
first_result = results.page(1)[0]
|
||||||
|
|
||||||
|
# artist = first_result.artists[0].name
|
||||||
|
title = first_result.title
|
||||||
|
|
||||||
|
print(dir(first_result.artists[0]))
|
||||||
|
print(title)
|
||||||
|
print(first_result.artists[0].name)
|
||||||
|
# print(title, artist)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
files = list_files()
|
files = list_files()
|
||||||
get_metadata("36. Galantis - No Money")
|
# title, artist = get_metadata_acoustid(
|
||||||
# add_metadata(files)
|
# "21. Jonas Blue - By Your Side (Feat Raye).mp3")
|
||||||
# result = m.search_releases("36. Galantis - No Money")
|
|
||||||
# print(result)
|
# title, artist =
|
||||||
# for rel in result['release-list']:
|
# get_metadata_discogs(
|
||||||
# print("{}, by {}".format(rel['title'], rel["artist-credit-phrase"]))
|
# "Jonas Blue - By Your Side (Feat Raye)")
|
||||||
# if 'date' in rel:
|
|
||||||
# print("Released {} ({})".format(rel['date'], rel['status']))
|
improve_song_names(files)
|
||||||
# print("MusicBrainz ID: {}".format(rel['id']))
|
# print(title, artist)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue