from django.core.management.base import BaseCommand
from vrobbler.apps.music.utils import deduplicate_tracks


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument(
            "--commit",
            action="store_true",
            help="Commit changes",
        )

    def handle(self, *args, **options):
        commit = False
        if options["commit"]:
            commit = True
        else:
            print("No changes will be saved, use --commit to save")
        dups = deduplicate_tracks(commit=commit)
        print(f"Deduplicated {dups} music tracks")
