diff --git a/.gitignore b/.gitignore index 3b1733d..0c1e7fe 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json -!.vscode/extensions.json \ No newline at end of file +!.vscode/ +*.mp3 \ No newline at end of file diff --git a/addMetadata.py b/addMetadata.py index 14175ee..b472193 100644 --- a/addMetadata.py +++ b/addMetadata.py @@ -1,36 +1,59 @@ import musicbrainzngs as m -import sys, eyed3 +import sys +from mutagen.id3 import ID3 +from mutagen import File +import os +import mutagen +from os.path import basename +import spotipy + +def improve_song_name(song): + return song + + +def get_metadata(song): + spotify = spotipy.Spotify() + results = spotify.search(song_name, limit=1) + + results = results['tracks']['items'][0] # Find top result + album = results['album']['name'] # Parse json dictionary + artist = results['album']['artists'][0]['name'] + song_title = results['name'] + album_art = results['album']['images'][0]['url'] + + return artist, album, song_title, album_art + +def add_metadata(files): + # tags = File("/home/yash/Desktop/music-tagger/sample_songs/02. DJ Snake - Let Me Love You (Feat. Justin Bieber).mp3") + # 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(): + files = [] + return [f for f in os.listdir('.') if f.endswith('.mp3')] def main(): m.set_useragent( "RepairMusicMetadata", "0.1", "https://yashagarwal.me") - music_path = "/home/yash/bf.mp3" - file = eyed3.load(music_path) - - artist_name = file.tag.artist - title = file.tag.title - album = file.tag.album - - result = m.search_recordings(recording=title, country="IN", artist=artist_name, release=album) + files = list_files() + get_metadata("36. Galantis - No Money") + # add_metadata(files) + # result = m.search_releases("36. Galantis - No Money") # print(result) - - for query in result['recording-list']: - if(query['ext:score'] == "100"): - # print(query['release-list'][0]['title']) - # area = query['release-list'][0]['release-event-list'][0]['area']['name'] - # print(area) - if(query['release-list'][0]['title'] == album): - id = query['release-list'][0]['medium-list'][0]['track-list'][0]['id'] - print(id) - else: - print("Not Found") - # print(id) - # x = m.get_recording_by_id(id) - # print(x) - # break - # print(release) + # for rel in result['release-list']: + # print("{}, by {}".format(rel['title'], rel["artist-credit-phrase"])) + # if 'date' in rel: + # print("Released {} ({})".format(rel['date'], rel['status'])) + # print("MusicBrainz ID: {}".format(rel['id'])) if __name__ == "__main__": diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..529bebe --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +from distutils.core import setup + +setup( + name='music-tagger', + version='1.0.0', + packages=[''], + url='https://github.com/yash2696/MP3Repair', + license='MIT', + author='Yash Agarwal', + author_email='yashagarwaljpr@gmail.com', + description='' +)