Fix error in setting comment
This commit is contained in:
@@ -391,19 +391,22 @@ def check_spotify_album_and_save(spotify, audio,x: str) -> bool:
|
|||||||
querystring = "artist:{0} album:{1}".format(str(audio["TPE2"]),str(audio["TALB"]))
|
querystring = "artist:{0} album:{1}".format(str(audio["TPE2"]),str(audio["TALB"]))
|
||||||
|
|
||||||
logging.info("query string: " + querystring)
|
logging.info("query string: " + querystring)
|
||||||
try:
|
tries = 0
|
||||||
results = spotify.search(q=querystring,type='album')
|
found = False
|
||||||
except Exception as err:
|
while (tries < 5 and found == False):
|
||||||
logging.error("could not search on spotify")
|
|
||||||
logging.error(err)
|
|
||||||
logging.info("waiting 30 seconds before trying again")
|
|
||||||
time.sleep(30)
|
|
||||||
try:
|
try:
|
||||||
results = spotify.search(q=querystring,type='album')
|
results = spotify.search(q=querystring,type='album')
|
||||||
|
found = True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.error("could not search on spotify again")
|
logging.error("could not search on spotify")
|
||||||
logging.error(err)
|
logging.error(err)
|
||||||
return found
|
logging.info("waiting 30 seconds before trying again")
|
||||||
|
time.sleep(30)
|
||||||
|
tries += 1
|
||||||
|
|
||||||
|
if (found == False):
|
||||||
|
logging.error("could not search on spotify after 5 tries, aborting")
|
||||||
|
return False
|
||||||
|
|
||||||
if (len(results["albums"]["items"]) > 0):
|
if (len(results["albums"]["items"]) > 0):
|
||||||
logging.info("album found on spotify!")
|
logging.info("album found on spotify!")
|
||||||
@@ -506,7 +509,7 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
|||||||
track = str(audio["title"])
|
track = str(audio["title"])
|
||||||
else:
|
else:
|
||||||
if audio["TPE2"] is not str:
|
if audio["TPE2"] is not str:
|
||||||
logging.info("TPE2 is not str")
|
logging.info("TPE2 tag is not a str but a " + str(type(audio["TPE2"])) + " of value " + str(audio["TPE2"]) + ". Setting artist to " + str(audio["TPE2"][0]))
|
||||||
artist = str(audio["TPE2"][0])
|
artist = str(audio["TPE2"][0])
|
||||||
else:
|
else:
|
||||||
artist = str(audio["TPE2"])
|
artist = str(audio["TPE2"])
|
||||||
@@ -519,6 +522,7 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
|||||||
querystring = "artist:{0} track:{1}".format(artist.split("\00")[0],track)
|
querystring = "artist:{0} track:{1}".format(artist.split("\00")[0],track)
|
||||||
logging.info("query string: " + querystring)
|
logging.info("query string: " + querystring)
|
||||||
results = spotify.search(q=querystring,type='track')
|
results = spotify.search(q=querystring,type='track')
|
||||||
|
|
||||||
if (len(results['tracks']['items']) > 0):
|
if (len(results['tracks']['items']) > 0):
|
||||||
logging.info("track found on spotify!")
|
logging.info("track found on spotify!")
|
||||||
found = True
|
found = True
|
||||||
@@ -531,18 +535,20 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
|||||||
else:
|
else:
|
||||||
audio["TPE2"] = TPE2(encoding=3,text=found_artist)
|
audio["TPE2"] = TPE2(encoding=3,text=found_artist)
|
||||||
found_album = album["name"]
|
found_album = album["name"]
|
||||||
|
logging.info("found album name: " + found_album)
|
||||||
if (len(found_album) > 0):
|
if (len(found_album) > 0):
|
||||||
if x.endswith(".flac"):
|
if x.endswith(".flac"):
|
||||||
audio["album"] = found_album
|
audio["album"] = found_album
|
||||||
else:
|
else:
|
||||||
audio["TALB"] = TALB(encoding=3,text=found_album)
|
audio["TALB"] = TALB(encoding=3,text=found_album)
|
||||||
else:
|
else:
|
||||||
|
# set album to title if no album found
|
||||||
if (x.endswith(".flac")):
|
if (x.endswith(".flac")):
|
||||||
audio["album"] = audio["title"][0]
|
audio["album"] = audio["title"][0]
|
||||||
else:
|
else:
|
||||||
audio["TALB"] = TALB(encoding=3,text=str(audio["TIT2"]))
|
audio["TALB"] = TALB(encoding=3,text=str(audio["TIT2"]))
|
||||||
|
|
||||||
comment ="Spotify ID: {0}. Release date precision: {1}, total tracks in album: {2}. This album has {3} version(s)".format(album["id"],album["release_date_precision"], album["total_tracks"],len(results["albums"]["items"]))
|
comment ="Spotify ID: {0}. This album was released on: {1}, total tracks in album: {2}. This album has {3} version(s)".format(album["id"],album["release_date"], album["total_tracks"],len(results["tracks"]["items"]))
|
||||||
logging.info("Comment: " + comment)
|
logging.info("Comment: " + comment)
|
||||||
if x.endswith(".flac"):
|
if x.endswith(".flac"):
|
||||||
audio["comment"] = comment
|
audio["comment"] = comment
|
||||||
@@ -627,7 +633,6 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
|||||||
logging.info("now setting cover art..")
|
logging.info("now setting cover art..")
|
||||||
embed_music_file(join(songpath,x),join(songpath,"Cover.jpg"))
|
embed_music_file(join(songpath,x),join(songpath,"Cover.jpg"))
|
||||||
|
|
||||||
|
|
||||||
return found
|
return found
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -735,6 +740,7 @@ def main():
|
|||||||
found = check_spotify_and_save(spotify, audio,x)
|
found = check_spotify_and_save(spotify, audio,x)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.error("could not find track on spotify: " + str(err))
|
logging.error("could not find track on spotify: " + str(err))
|
||||||
|
logging.error(err.with_traceback)
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
if (found == False):
|
if (found == False):
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ source .env/bin/activate
|
|||||||
python3 make_folders.py
|
python3 make_folders.py
|
||||||
for f in ./*.mp3; do ffprobe "$f"; done
|
for f in ./*.mp3; do ffprobe "$f"; done
|
||||||
for f in ./*.flac; do ffprobe "$f"; done
|
for f in ./*.flac; do ffprobe "$f"; done
|
||||||
|
|
||||||
mkdir ../temp
|
mkdir ../temp
|
||||||
rm -r ../temp/*
|
rm -r ../temp/*
|
||||||
mv ./*/ ../temp #move all directories
|
mv ./*/ ../temp #move all directories
|
||||||
|
|||||||
5
requirements.txt
Executable file
5
requirements.txt
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
mutagen
|
||||||
|
eyed3
|
||||||
|
icrawler
|
||||||
|
spotipy
|
||||||
|
requests
|
||||||
Reference in New Issue
Block a user