Ejemplo n.º 1
0
def create_test_release(artists=None,
                        release_artists=None,
                        release_title="Mezzanine",
                        date="1998-04-17",
                        track_titles=None,
                        genres=None) -> Release:

    if not artists:
        artists = ["Massive Attack"]
    if not release_artists:
        release_artists = ["Massive Attack"]
    if not track_titles:
        track_titles = [
            "Angel", "Risingson", "Teardrop", "Inertia Creeps", "Exchange",
            "Dissolved Girl", "Man Next Door", "Black Milk", "Mezzanine",
            "Group Four", "(Exchange)"
        ]
    if not genres:
        genres = [
            'Trip-hop', 'Electronic', 'Chillout', 'Electronica', 'Downtempo',
            '90s', 'Alternative', 'Ambient', 'British', 'Dark',
            'Bristol Sound', 'Atmospheric', 'Hypnotic', 'UK',
            'Alternative Dance', 'Bristol', 'Chill', 'Dub', 'Experimental',
            'Indie', 'Leftfield', 'Lounge', 'Nocturnal', '1990s', 'Bass',
            'Electro', 'Intense', 'Relax', 'Sophisticated'
        ]

    tracks = OrderedDict()

    base_track = Track(artists=artists,
                       release_artists=release_artists,
                       date=date,
                       release_title=release_title,
                       track_number=1,
                       total_tracks=len(track_titles),
                       disc_number=1,
                       total_discs=1,
                       genres=genres,
                       stream_info=StreamInfo(tag_type=TagType.ID3,
                                              mp3_method=Mp3Method.CBR,
                                              length=100.123,
                                              bitrate=128000,
                                              xing=Xing()))

    for i in range(1, len(track_titles) + 1):
        curr_track = copy.deepcopy(base_track)
        curr_track.track_title = track_titles[i - 1]
        curr_track.track_number = i
        tracks["{0} - {1}.mp3".format(str(i).zfill(2),
                                      curr_track.track_title)] = curr_track

    return Release(tracks)
Ejemplo n.º 2
0
def validate_releases(validator: ReleaseValidator, release_dirs: List[str],
                      args: argparse.Namespace) -> None:
    """Validate releases found in the scan directory"""

    # assemble_discs(release_dirs, False)

    for curr_dir in release_dirs:
        audio, non_audio, unreadable = load_directory(curr_dir)
        release = Release(audio, guess_category_from_path(curr_dir),
                          guess_source_from_path(curr_dir))

        codec_short = not args.full_codec_names
        violations = validator.validate(release)
        validate_folder_name(release, violations,
                             os.path.split(curr_dir)[1], False, codec_short)
        add_unreadable_files(violations, unreadable)

        print("{0} violations: {1}".format(format_violations_str(violations),
                                           curr_dir))

        if args.show_violations:
            print_list(violations)
Ejemplo n.º 3
0
def fix_releases(validator: ReleaseValidator, release_dirs: Iterator[str],
                 args: argparse.Namespace, dest_folder: str,
                 invalid_folder: str, duplicate_folder: str) -> None:
    """Fix releases found in the scan directory"""

    unique_releases = set()

    for curr_dir in release_dirs:
        if not can_lock_path(curr_dir):
            logging.getLogger(__name__).error(
                "Could not lock directory {0}".format(curr_dir))
            continue

        audio, non_audio, unreadable = load_directory(curr_dir)

        release = Release(audio, guess_category_from_path(curr_dir),
                          guess_source_from_path(curr_dir))

        fixed = validator.fix(release, os.path.split(curr_dir)[1])

        if not args.dry_run:
            for x in fixed.tracks:
                if fixed.tracks[x] != release.tracks[x] or fixed.tracks[
                        x].always_write:
                    cleartag.write_tags(os.path.join(curr_dir, x),
                                        fixed.tracks[x])

        # rename files
        rename_files(fixed, curr_dir, args.dry_run)

        new_tracks = OrderedDict()
        for x in fixed.tracks:
            correct_filename = fixed.tracks[x].get_filename(fixed.is_va())
            if correct_filename:
                new_tracks[correct_filename] = fixed.tracks[x]
            else:
                new_tracks[x] = fixed.tracks[x]
        fixed.tracks = new_tracks

        # calculate violations before and after fixing
        codec_short = not args.full_codec_names
        old_violations = validator.validate(release)
        validate_folder_name(release, old_violations,
                             os.path.split(curr_dir)[1], False,
                             args.group_by_category, codec_short)
        add_unreadable_files(old_violations, unreadable)

        violations = validator.validate(fixed)
        validate_folder_name(fixed, violations,
                             os.path.split(curr_dir)[1], True,
                             args.group_by_category, codec_short)
        add_unreadable_files(violations, unreadable)

        if len(violations) == 0:
            moved_dir = move_rename_folder(fixed, unique_releases, curr_dir,
                                           dest_folder, duplicate_folder, args)
        else:
            moved_dir = move_invalid_folder(curr_dir, invalid_folder,
                                            violations, args.move_invalid)

        enforce_max_path(moved_dir)

        print("{0} violations: {1}".format(
            format_violations_str(old_violations, violations), moved_dir))

        if args.show_violations:
            if old_violations:
                print("Before")
                print_list(old_violations)

            if violations:
                print("After:")
                print_list(violations)