implement discogs-search
parent
0795e9fdba
commit
64dca80273
|
@ -4,4 +4,6 @@
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
!.vscode/
|
!.vscode/
|
||||||
*.mp3
|
*.mp3
|
||||||
aidmatch.py
|
aidmatch.py
|
||||||
|
data.json
|
||||||
|
.idea/*
|
|
@ -1,10 +1,13 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import mutagen
|
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
import acoustid
|
import acoustid
|
||||||
import discogs_client as discogs
|
import discogs_client as discogs
|
||||||
from string import digits
|
from string import digits
|
||||||
|
import musicbrainzngs as m
|
||||||
|
from mutagen.id3 import ID3, APIC, _util
|
||||||
|
from mutagen.mp3 import EasyMP3
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
def improve_song_names(songs):
|
def improve_song_names(songs):
|
||||||
|
@ -15,19 +18,18 @@ def improve_song_names(songs):
|
||||||
improved_names = []
|
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)
|
||||||
searchText = searchText.translate(remove_digits)
|
# searchText = searchText.translate(remove_digits)
|
||||||
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, '')
|
||||||
|
|
||||||
improved_names.append(searchText)
|
improved_names.append(searchText.strip())
|
||||||
|
|
||||||
return improved_names
|
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)
|
||||||
|
@ -49,16 +51,32 @@ def get_metadata_acoustid(song):
|
||||||
first = False
|
first = False
|
||||||
else:
|
else:
|
||||||
print(result)
|
print(result)
|
||||||
|
score, rid, title, artist = result[0], result[1], result[2], result[3]
|
||||||
|
valid = True
|
||||||
|
|
||||||
if first is True:
|
if first is True:
|
||||||
print("No Data found for " + song + " .... Skipping it")
|
print("No Data found for " + song + " .... Skipping it")
|
||||||
|
valid = False
|
||||||
|
score, rid, title, artist = None, None, None, None
|
||||||
|
|
||||||
|
return valid, score, rid, title, artist
|
||||||
|
|
||||||
|
|
||||||
def get_metadata_musicbrainz(song):
|
def get_metadata_musicbrainz(rid, artist, title):
|
||||||
return
|
d = m.set_useragent(
|
||||||
|
"MetadataRepair",
|
||||||
|
"0.1",
|
||||||
|
"https://github.com/yash2696/python-musicbrainzngs/",
|
||||||
|
)
|
||||||
|
|
||||||
|
result = m.search_recordings(
|
||||||
|
artist=artist, recording=title, rid=rid, limit=5)
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
def add_metadata(files):
|
def add_metadata(file_name, rid, title, artist):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,14 +88,17 @@ def list_files():
|
||||||
def get_metadata_discogs(song_name):
|
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")
|
||||||
first_result = results.page(1)[0]
|
first_result = results.page(1)[0]
|
||||||
|
|
||||||
|
# print(first_result)
|
||||||
title = first_result.title
|
title = first_result.title
|
||||||
|
|
||||||
print(dir(first_result.artists[0]))
|
# print(dir(first_result))
|
||||||
print(title)
|
print(title)
|
||||||
print(first_result.artists[0].name)
|
print(first_result.artists[0].name)
|
||||||
|
print(first_result.images[0])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -87,13 +108,34 @@ def main():
|
||||||
# get_metadata_discogs(
|
# get_metadata_discogs(
|
||||||
# "Jonas Blue - By Your Side (Feat Raye)")
|
# "Jonas Blue - By Your Side (Feat Raye)")
|
||||||
|
|
||||||
# files = improve_song_names(files)
|
# get_metadata_discogs(
|
||||||
for file in files:
|
# "Maroon 5-Animals")
|
||||||
print("-------------" + file + "------------------")
|
# valid, score, rid, title, artist = get_metadata_acoustid(
|
||||||
|
# "18. Justin Timberlake - CAN'T STOP THE FEELING!.mp3")
|
||||||
|
# print(valid)
|
||||||
|
# print(score)
|
||||||
|
# print(files)
|
||||||
|
# for file_name in files:
|
||||||
|
# print("-------------" + file_name + "------------------")
|
||||||
|
# print()
|
||||||
|
# valid, score, rid, title, artist = get_metadata_acoustid(file_name)
|
||||||
|
# if valid == True:
|
||||||
|
# get_metadata_musicbrainz(rid, artist, title)
|
||||||
|
# add_metadata(file_name, rid, title, artist)
|
||||||
|
# print()
|
||||||
|
# break
|
||||||
|
|
||||||
|
files = improve_song_names(files)
|
||||||
|
# print(files)
|
||||||
|
count = 0
|
||||||
|
for file_name in files:
|
||||||
|
print("-------------" + file_name + "------------------")
|
||||||
print()
|
print()
|
||||||
get_metadata_acoustid(file)
|
get_metadata_discogs(file_name)
|
||||||
|
count += 1
|
||||||
|
if count > 5:
|
||||||
|
break
|
||||||
print()
|
print()
|
||||||
print(files)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue