Compare commits
No commits in common. "7fdb28d9658df066428b0ff7c2dd44a9972010d6" and "63f6f99caa11896e5b48f1abe886e5267b9417b5" have entirely different histories.
7fdb28d965
...
63f6f99caa
|
@ -11,32 +11,10 @@ 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
|
||||||
|
|
|
@ -1,31 +1,13 @@
|
||||||
from log import Log
|
from pathlib import Path
|
||||||
from dir import Root
|
from dir import Root
|
||||||
from . import Layer
|
from layer import Layer
|
||||||
from dir import Artist
|
|
||||||
|
|
||||||
|
|
||||||
class Dedupe(Layer):
|
class Dedupe(Layer):
|
||||||
def __init__(self, other: Root, log: Log):
|
def __init__(self, other: Root, log_path: Path):
|
||||||
super().__init__(log, "TCD")
|
super().__init__(log_path, "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 prune_artist(self, left: Artist, right: Artist):
|
def __process(self, root: Root):
|
||||||
existing_albums = right.by_name()
|
pass
|
||||||
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}")
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user