Compare commits
3 Commits
63f6f99caa
...
7fdb28d965
Author | SHA1 | Date | |
---|---|---|---|
7fdb28d965 | |||
a44d6f034a | |||
1c42269f92 |
|
@ -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
|
||||||
|
|
|
@ -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}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user