Files
obsidian-vault/personal/tech/scripts/find_aa_hijack.py
T

57 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Детектор класса «albumartist размножен от чужого файла в корне папки».
Сессия 6, 2026-09-27. Нашёл 7 испорченных папок из 11 подозреваемых
(The Prodigy->DJ Feel, Банд Эрос->VIP77, Дискотека Авария, Жуки,
Потап & Каменских, Король и Шут, Ленинград).
ПРИЗНАК ПОРЧИ:
для папки, где new_albumartist ОДИН на всю папку:
он не совпадает с top-артистом папки
И не совпадает с именем папки
И совпадает с МИНОРИТАРНЫМ артистом папки
-> ПОДОЗРЕВАЕМЫЙ
ЗАПУСК: python3 find_aa_hijack.py
Не меняет файлы. Только печатает.
"""
import csv
import collections
import os
P = '/Users/admin/Downloads/music-tags/APPLY-PLAN.csv'
rows = list(csv.DictReader(open(P, encoding='utf-8-sig', newline='')))
def s(v):
return (v or '').strip()
by_folder = collections.defaultdict(list)
for r in rows:
by_folder[r['folder']].append(r)
suspects = []
for folder, rs in sorted(by_folder.items()):
aa_vals = collections.Counter(s(r['new_albumartist']) for r in rs if s(r['new_albumartist']))
if len(aa_vals) != 1:
continue # смешанные папки — отдельный случай
aa = next(iter(aa_vals))
art = collections.Counter(s(r['new_artist']) for r in rs if s(r['new_artist']))
if not art:
continue
top_artist, top_n = art.most_common(1)[0]
folder_name = os.path.basename(folder)
if aa != top_artist and aa != folder_name and aa in art:
minority = art[aa]
if minority < top_n:
suspects.append((folder, aa, top_artist, top_n, minority, len(rs)))
print(f"ПОДОЗРЕВАЕМЫХ ПАПОК: {len(suspects)}")
print()
for folder, aa, top, tn, mn, tot in suspects:
print(f" albumartist={aa!r} (у {mn} из {tot})")
print(f" должен быть {top!r} (у {tn})")
print(f" {folder}")