diff --git a/anonymize_entries.py b/anonymize_entries.py index 99e3529..65e942d 100644 --- a/anonymize_entries.py +++ b/anonymize_entries.py @@ -3,6 +3,7 @@ import csv import _csv from dataclasses import dataclass from datetime import datetime +from decimal import Decimal import enum import os from random import Random @@ -22,6 +23,7 @@ import simfile from simfile.dir import SimfilePack, SimfileDirectory from simfile.sm import SMChart, SMSimfile from simfile.ssc import SSCChart, SSCSimfile +from simfile.timing import BeatValues, BeatValue from simfile.types import Simfile @@ -456,6 +458,17 @@ def maybe_anonymize_entries( os.remove(absolute_path) print(f"Deleted {os.path.relpath(absolute_path, temp_fs.root_path)}") + def anonymize_bpms(bpm_str: str | None) -> str: + bpm_values = BeatValues.from_str(bpm_str) + bpm_values.append( + BeatValue( + beat=bpm_values[-1].beat + 10000, + value=bpm_values[-1].value + Decimal("0.001"), + ) + ) + print(f"Anonymized BPMs from {repr(bpm_str)} to {repr(str(bpm_values))}") + return str(bpm_values) + for row in csv_contents: if row[KnownColumns.IgnoreFile]: continue @@ -484,6 +497,7 @@ def maybe_anonymize_entries( sm.cdtitle = "" sm.genre = "" sm.music = f"{canonical_filename}.ogg" + sm.bpms = anonymize_bpms(sm.bpms) for _chart in sm.charts: sm_chart: SMChart = _chart # typing workaround sm_chart.description = row[KnownColumns.GeneratedAlias] @@ -505,12 +519,15 @@ def maybe_anonymize_entries( ssc.cdimage = "" ssc.discimage = "" ssc.labels = "" + ssc.bpms = anonymize_bpms(ssc.bpms) for _chart in ssc.charts: ssc_chart: SSCChart = _chart # typing workaround ssc_chart.description = "" ssc_chart.chartname = "" ssc_chart.chartstyle = "" ssc_chart.credit = row[KnownColumns.GeneratedAlias] + if ssc_chart.bpms: + ssc_chart.bpms = anonymize_bpms(ssc_chart.bpms) maybe_rename_file(simfile_dir.ssc_path, f"{canonical_filename}.ssc") print( f"Scrubbed {os.path.relpath(absolute_simfile_dir_path, temp_fs.root_path)}/{canonical_filename}.ssc"