Compare commits

..

No commits in common. "7fdb28d9658df066428b0ff7c2dd44a9972010d6" and "63f6f99caa11896e5b48f1abe886e5267b9417b5" have entirely different histories.

2 changed files with 6 additions and 46 deletions

View File

@ -11,32 +11,10 @@ class Directory(ABC):
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
def name(self):
return self.path.name
def by_name(self):
return [e.name for e in self.contents]
@abstractmethod
def populate(self, log: Log) -> list:
raise NotImplementedError

View File

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