Пример #1
0
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
Пример #2
0
def SEARCH_SONG(q="Tera Buzz", filters=[]):
    """Do the task by calling other functions."""
    to_be_sorted = []
    rest = []

    metadata_providers = defaults.DEFAULT.METADATA_PROVIDERS

    GET_METADATA_ACTIONS = {
        'itunes': get_from_itunes,
        'gaana': get_from_gaana,
        'deezer': get_from_deezer,
        'saavn': get_from_saavn,
        'lastfm': get_from_lastfm
    }

    broken_provider_counter = 0

    for provider in metadata_providers:
        if provider in GET_METADATA_ACTIONS:
            data_provider = GET_METADATA_ACTIONS.get(
                provider, lambda _: None)(q)
            if data_provider:
                _extend_to_be_sorted_and_rest(
                    data_provider, to_be_sorted, rest, filters)
        else:
            logger.warning(
                '"{}" isn\'t implemented. Skipping!'.format(provider)
            )
            broken_provider_counter += 1

    # to_be_sorted will be empty and it will return None anyway, no need
    # to do it here as well
    if broken_provider_counter == len(metadata_providers):
        logger.critical("{}".format(
            'No metadata provider in the configuration is '
            'implemented. Please change it to something \
                            available or use the --skip-meta flag'))

    if not to_be_sorted:
        return None

    # Send the data to get sorted
    sorted_data = _search_tokens(q, to_be_sorted)

    # Add the unsorted data
    sorted_data += rest

    return sorted_data
Пример #3
0
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