From 7fdb28d9658df066428b0ff7c2dd44a9972010d6 Mon Sep 17 00:00:00 2001 From: grglcy Date: Sat, 12 Jul 2025 13:44:24 +0100 Subject: [PATCH] implement basic pruning based on dir name --- src/layers/dedupe.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/layers/dedupe.py b/src/layers/dedupe.py index 14ed09a..e29b353 100644 --- a/src/layers/dedupe.py +++ b/src/layers/dedupe.py @@ -1,13 +1,31 @@ -from pathlib import Path +from log import Log from dir import Root -from layer import Layer +from . import Layer +from dir import Artist class Dedupe(Layer): - def __init__(self, other: Root, log_path: Path): - super().__init__(log_path, "TCD") + def __init__(self, other: Root, log: Log): + super().__init__(log, "TCD") self.other = other + def _process(self, left: Root): + right = self.other + existing_artists = right.by_name() + for artist in left: + artist_name = artist.name + if artist_name in existing_artists: + self.prune_artist(artist, right[artist_name]) + if len(artist.contents) == 0: + left.prune(artist_name) + self.log.info('PRN', f"Pruned artist: {artist_name}") + else: + continue # todo: fuzzy matching - def __process(self, root: Root): - pass + def prune_artist(self, left: Artist, right: Artist): + existing_albums = right.by_name() + for album in left: + album_name = album.name + if album_name in existing_albums: + left.prune(album_name) + self.log.info('PRN', f"Pruned album: {album_name}")