benfmiller / audalign

Package for aligning audio files through audio fingerprinting
MIT License
84 stars 2 forks source link

target_file never fingerprinting #22

Closed pursuk closed 2 years ago

pursuk commented 2 years ago
def prelim_fingerprint_checks(ada_obj, target_file, directory_path):
    all_against_files = audalign.filehandler.find_files(directory_path)
    all_against_files_full = [x[0] for x in all_against_files]
    all_against_files_base = [os.path.basename(x) for x in all_against_files_full]
    if (
        os.path.basename(target_file) in all_against_files_base
        # if the target file is outside directory_path the above line makes it never fingerprint, shouldnt it look like:
        os.path.basename(target_file) not in all_against_files_base
        and target_file not in all_against_files_full
    ):
        ada_obj.fingerprint_file(target_file)

Could be me being bad at programming but this change seems to solve the issue i had with target_align

benfmiller commented 2 years ago

Thanks for the tip! I changed it to this

def prelim_fingerprint_checks(ada_obj, target_file, directory_path):
    all_against_files = audalign.filehandler.find_files(directory_path)
    all_against_files_full = [x[0] for x in all_against_files]
    all_against_files_base = [os.path.basename(x) for x in all_against_files_full]
    if (
        os.path.basename(target_file) in all_against_files_base
        and target_file not in all_against_files_full
    ):
        for i, x in enumerate(all_against_files_full):
            if os.path.basename(target_file) == os.path.basename(x):
                all_against_files_full.pop(i)
                break
        all_against_files_full.append(target_file)
    elif os.path.basename(target_file) not in all_against_files_base:
        all_against_files_full.append(target_file)
    return all_against_files_full

And I reworked the function that calls it a little bit too. I'll have the new release out in a couple of hours