Compare commits

..

3 Commits

Author SHA1 Message Date
7fdb28d965 implement basic pruning based on dir name 2025-07-12 13:44:24 +01:00
a44d6f034a allow retrieval and pruning of contents by name 2025-07-12 13:43:51 +01:00
1c42269f92 iterate contents directly
- provide list of names
2025-07-12 13:21:10 +01:00
2 changed files with 46 additions and 6 deletions

View File

@ -11,10 +11,32 @@ class Directory(ABC):
self.contents = self.populate(log) self.contents = self.populate(log)
def __iter__(self):
return self.contents.__iter__()
def __getitem__(self, name):
for e in self:
if e.name == name:
return e
raise KeyError
def prune(self, name):
for e in self:
if e.name == name:
self.contents.remove(e)
return
raise KeyError
def __str__(self):
return self.name
@property @property
def name(self): def name(self):
return self.path.name return self.path.name
def by_name(self):
return [e.name for e in self.contents]
@abstractmethod @abstractmethod
def populate(self, log: Log) -> list: def populate(self, log: Log) -> list:
raise NotImplementedError raise NotImplementedError

View File

@ -1,13 +1,31 @@
from pathlib import Path from log import Log
from dir import Root from dir import Root
from layer import Layer from . import Layer
from dir import Artist
class Dedupe(Layer): class Dedupe(Layer):
def __init__(self, other: Root, log_path: Path): def __init__(self, other: Root, log: Log):
super().__init__(log_path, "TCD") super().__init__(log, "TCD")
self.other = other 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): def prune_artist(self, left: Artist, right: Artist):
pass 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}")