Ejemplo n.º 1
0
    def _has_metadata(self, song):
        # check if the already downloaded song has correct metadata
        # if not, remove it and download again without prompt
        already_tagged = metadata.compare(os.path.join(self.filepath, song),
                                          self.meta_tags)
        log.debug("Checking if it is already tagged correctly? {}",
                  already_tagged)
        if not already_tagged:
            os.remove(os.path.join(self.filepath, song))
            return False

        return True
Ejemplo n.º 2
0
def check_exists(music_file, raw_song, meta_tags):
    """ Check if the input song already exists in the given folder. """
    log.debug(
        "Cleaning any temp files and checking "
        'if "{}" already exists'.format(music_file)
    )
    songs = os.listdir(const.args.folder)
    for song in songs:
        if song.endswith(".temp"):
            os.remove(os.path.join(const.args.folder, song))
            continue
        # check if a song with the same name is already present in the given folder
        if os.path.splitext(song)[0] == music_file:
            log.debug('Found an already existing song: "{}"'.format(song))
            if internals.is_spotify(raw_song):
                # check if the already downloaded song has correct metadata
                # if not, remove it and download again without prompt
                already_tagged = metadata.compare(
                    os.path.join(const.args.folder, song), meta_tags
                )
                log.debug(
                    "Checking if it is already tagged correctly? {}", already_tagged
                )
                if not already_tagged:
                    os.remove(os.path.join(const.args.folder, song))
                    return False

            log.warning('"{}" already exists'.format(song))
            if const.args.overwrite == "prompt":
                log.info(
                    '"{}" has already been downloaded. '
                    "Re-download? (y/N): ".format(song)
                )
                prompt = input("> ")
                if prompt.lower() == "y":
                    os.remove(os.path.join(const.args.folder, song))
                    return False
                else:
                    return True
            elif const.args.overwrite == "force":
                os.remove(os.path.join(const.args.folder, song))
                log.info('Overwriting "{}"'.format(song))
                return False
            elif const.args.overwrite == "skip":
                log.info('Skipping "{}"'.format(song))
                return True
    return False