def cleanup(TRACK_INFO, index, datatype): """Move the song from temp to $HOME/Music dir.""" try: SONG = glob.glob( os.path.join(defaults.DEFAULT.SONG_TEMP_DIR, '*{}'.format(datatype))) SONG = SONG[0] SONG_NAME = os.path.basename(SONG) DIR = defaults.DEFAULT.SONG_DIR # Check if DIR has $ in its path # If it does then make those folders accordingly if '$' in DIR: DIR, name = make_custom_dir(DIR, TRACK_INFO[index]) if name is not None: os.rename(SONG, name + '.mp3') SONG_NAME = name + '.mp3' SONG = SONG_NAME shutil.move(SONG, os.path.join(DIR, SONG_NAME)) _delete_cached_songs(datatype) logger.info('Moved to {}...'.format(DIR)) return True except Exception as e: logger.critical("Failed while moving with error: {}".format(e)) return False
def dwCover(song): """Download the song cover img from itunes.""" # Try to download the cover art as cover.jpg in temp logger.info("Preparing the album cover") try: imgURL = song.artwork_url_100 # Check if the passed imgURL is a local file # this is possible if the metadata was entered manually. imgURL = os.path.expanduser(imgURL) if os.path.exists(imgURL): # Probably a file, read it in binary and extract the data # then return. content = open(imgURL, "rb").read() with open(defaults.DEFAULT.COVER_IMG, 'wb') as f: f.write(content) return True # Else might be an URL try: # Try to get 512 cover art imgURL = imgURL.replace('100x100', '2048x2048') except Exception: pass r = requests.get(imgURL) with open(defaults.DEFAULT.COVER_IMG, 'wb') as f: f.write(r.content) return True except TimeoutError: prepend.PREPEND(2) print('Could not get album cover. Are you connected to internet?\a') return False except Exception as e: logger.warning( "Error while trying to download image, skipping!: {}".format(e)) return False else: return False
def dry_cleanup(current_path, passed_name): """ Move the song from the current path to the song dir and change the name to the passed_name. This is only for when the meta-skip option is passed, in which case the song needs to be moved from the cache to the user directory. """ try: extension = os.path.basename(current_path).split(".")[-1] logger.debug("ext: {}".format(extension)) new_basename = "{}.{}".format(passed_name, extension) DEST = defaults.DEFAULT.SONG_DIR logger.debug("Moving to: {}".format(DEST)) shutil.move(current_path, os.path.join(DEST, new_basename)) logger.info('Moved to {}...'.format(DEST)) return True except Exception as e: logger.critical("{}".format(e)) return False