Fix error in setting comment
This commit is contained in:
@@ -391,20 +391,23 @@ def check_spotify_album_and_save(spotify, audio,x: str) -> bool:
|
||||
querystring = "artist:{0} album:{1}".format(str(audio["TPE2"]),str(audio["TALB"]))
|
||||
|
||||
logging.info("query string: " + querystring)
|
||||
try:
|
||||
results = spotify.search(q=querystring,type='album')
|
||||
except Exception as err:
|
||||
logging.error("could not search on spotify")
|
||||
logging.error(err)
|
||||
logging.info("waiting 30 seconds before trying again")
|
||||
time.sleep(30)
|
||||
tries = 0
|
||||
found = False
|
||||
while (tries < 5 and found == False):
|
||||
try:
|
||||
results = spotify.search(q=querystring,type='album')
|
||||
found = True
|
||||
except Exception as err:
|
||||
logging.error("could not search on spotify again")
|
||||
logging.error("could not search on spotify")
|
||||
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):
|
||||
logging.info("album found on spotify!")
|
||||
found = True
|
||||
@@ -506,7 +509,7 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
||||
track = str(audio["title"])
|
||||
else:
|
||||
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])
|
||||
else:
|
||||
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)
|
||||
logging.info("query string: " + querystring)
|
||||
results = spotify.search(q=querystring,type='track')
|
||||
|
||||
if (len(results['tracks']['items']) > 0):
|
||||
logging.info("track found on spotify!")
|
||||
found = True
|
||||
@@ -531,18 +535,20 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
||||
else:
|
||||
audio["TPE2"] = TPE2(encoding=3,text=found_artist)
|
||||
found_album = album["name"]
|
||||
logging.info("found album name: " + found_album)
|
||||
if (len(found_album) > 0):
|
||||
if x.endswith(".flac"):
|
||||
audio["album"] = found_album
|
||||
else:
|
||||
audio["TALB"] = TALB(encoding=3,text=found_album)
|
||||
else:
|
||||
# set album to title if no album found
|
||||
if (x.endswith(".flac")):
|
||||
audio["album"] = audio["title"][0]
|
||||
else:
|
||||
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)
|
||||
if x.endswith(".flac"):
|
||||
audio["comment"] = comment
|
||||
@@ -626,8 +632,7 @@ def check_spotify_and_save(spotify, audio,x: str) -> bool:
|
||||
|
||||
logging.info("now setting cover art..")
|
||||
embed_music_file(join(songpath,x),join(songpath,"Cover.jpg"))
|
||||
|
||||
|
||||
|
||||
return found
|
||||
|
||||
def main():
|
||||
@@ -734,7 +739,8 @@ def main():
|
||||
try:
|
||||
found = check_spotify_and_save(spotify, audio,x)
|
||||
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
|
||||
|
||||
if (found == False):
|
||||
|
||||
@@ -2,6 +2,7 @@ source .env/bin/activate
|
||||
python3 make_folders.py
|
||||
for f in ./*.mp3; do ffprobe "$f"; done
|
||||
for f in ./*.flac; do ffprobe "$f"; done
|
||||
|
||||
mkdir ../temp
|
||||
rm -r ../temp/*
|
||||
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