def test_validate_invalid_track_numbers(self):
        validator = ReleaseValidator(get_lastfmcache())

        release = create_test_release()
        next(iter(release.tracks.values())).track_number = 2

        violations = validator.validate(release)
        assert len(violations) == 1

        mockito.unstub()
    def test_validate_missing_total_tracks(self):
        validator = ReleaseValidator(get_lastfmcache())

        release = create_test_release()
        next(iter(release.tracks.values())).total_tracks = None

        violations = validator.validate(release)
        assert len(violations) == 1

        mockito.unstub()
    def test_validate_release_artists(self):
        validator = ReleaseValidator(get_lastfmcache())

        release = create_test_release()
        next(iter(release.tracks.values())).release_artists = []

        violations = validator.validate(release)
        assert len(violations) == 1

        mockito.unstub()
Пример #4
0
def main():
    args = parse_args()

    src_folder = os.path.abspath(args.path)
    if not os.path.isdir(src_folder):
        raise ValueError("Invalid source folder: {0}".format(src_folder))

    dest_folder = None
    if args.move_fixed:
        dest_folder = os.path.abspath(src_folder)
    elif args.move_fixed_to:
        dest_folder = os.path.abspath(args.move_fixed_to)
        if not os.path.isdir(dest_folder):
            raise ValueError(
                "Invalid destination folder: {0}".format(dest_folder))

    invalid_folder = None
    if args.move_invalid:
        if args.move_invalid not in [v.value for v in ViolationType]:
            raise ValueError(
                "Invalid violation type '{0}', must be one of {1}".format(
                    args.move_invalid,
                    ", ".join([v.value for v in ViolationType])))
        if not args.move_invalid_to:
            raise ValueError(
                "--move-invalid must be accompanied by --move-invalid-to")
        invalid_folder = os.path.abspath(args.move_invalid_to)
        if not os.path.isdir(invalid_folder):
            raise ValueError(
                "Destination folder for invalid releases does not exist")

    duplicate_folder = None
    if args.move_duplicate_to:
        duplicate_folder = os.path.abspath(args.move_duplicate_to)
        if not os.path.isdir(duplicate_folder):
            raise ValueError(
                "Invalid duplicates folder: {0}".format(duplicate_folder))

    # guess group_by_category, if it was not set, using the contents of the destination folder
    if not args.group_by_category:
        args.group_by_category = guess_group_by_category(
            src_folder, dest_folder)

    if args.mode == "releases":
        list_releases(get_release_dirs(src_folder))

    elif args.mode in ["validate", "fix"]:
        lastfm = LastfmCache(lastfmcache_api_url=get_lastfmcache_api_url())
        lastfm.enable_file_cache(86400 * 365 * 5)

        validator = ReleaseValidator(lastfm)
        validator.disable_lastfm_track_title_validation()

        if args.expunge_comments_with_substring:
            validator.add_forbidden_comment_substring(
                args.expunge_comments_with_substring)

        if args.mode == "validate":
            validate_releases(validator, get_release_dirs(src_folder), args)

        elif args.mode == "fix":
            assemble_discs(get_release_dirs(src_folder), True)
            fix_releases(validator, get_release_dirs(src_folder), args,
                         dest_folder, invalid_folder, duplicate_folder)