Skip to content

Commit

Permalink
skip file date assertions on linux + tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jor-mar committed Jan 11, 2024
1 parent 4463f4f commit 42b2c91
Show file tree
Hide file tree
Showing 43 changed files with 342 additions and 343 deletions.
3 changes: 1 addition & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def reload_local(self, *kinds: str) -> None:

load_all = not kinds
if load_all:
self.remote.library.load()
self.local.library.load()
elif kinds:
if "tracks" in kinds:
self.local.library.load_tracks()
Expand Down Expand Up @@ -777,7 +777,6 @@ def get_parser() -> argparse.ArgumentParser:

## SELECTED FOR DEVELOPMENT
# TODO: separate all CLI concerns to other repo
# TODO: check loaded numbers on linux again
# TODO: expand readme + check all example functions work
# TODO: expand docstrings everywhere
# TODO: release to pypi + implement CI/CD structure on GitHub
Expand Down
2 changes: 1 addition & 1 deletion src/syncify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
PROGRAM_OWNER_NAME = "George Martin Marino"
PROGRAM_OWNER_USER = "geo-martino"
PROGRAM_OWNER_EMAIL = f"gm.engineer+{PROGRAM_NAME.lower()}@pm.me"
PROGRAM_URL = f"https://github.com/{PROGRAM_OWNER_USER}/{PROGRAM_NAME.casefold()}"
PROGRAM_URL = f"https://github.com/{PROGRAM_OWNER_USER}/{PROGRAM_NAME.lower()}"

MODULE_ROOT: str = basename(dirname(__file__))
PACKAGE_ROOT: str = dirname(dirname(dirname(__file__)))
6 changes: 3 additions & 3 deletions src/syncify/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from syncify.report import report_missing_tags
from syncify.shared.api.authorise import APIAuthoriser
from syncify.shared.api.request import RequestHandler
from syncify.shared.core.base import NamedObject
from syncify.shared.core.base import Nameable
from syncify.shared.core.enum import TagField
from syncify.shared.core.misc import PrettyPrinter
from syncify.shared.core.object import Library
Expand Down Expand Up @@ -295,7 +295,7 @@ def __deepcopy__(self, _: dict = None):
return obj


class ConfigFilter[T: str | NamedObject](BaseConfig, FilterComparers[T]):
class ConfigFilter[T: str | Nameable](BaseConfig, FilterComparers[T]):
"""
Set the settings for granular filtering from a config file.
See :py:class:`Config` for more documentation regarding operation.
Expand All @@ -316,7 +316,7 @@ def __init__(self, settings: dict[Any, Any]):
self.match_all = self._file.pop("match_all", self.match_all)
self.comparers = tuple(Comparer(condition=cond, expected=exp) for cond, exp in self._file.items())

self.transform = lambda value: value.name if isinstance(value, NamedObject) else value
self.transform = lambda value: value.name if isinstance(value, Nameable) else value


class ConfigPlaylists(BaseConfig):
Expand Down
19 changes: 4 additions & 15 deletions src/syncify/local/exception.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

from syncify.shared.exception import SyncifyError


Expand Down Expand Up @@ -97,23 +95,14 @@ class ImageLoadError(FileError):


###########################################################################
## MusicBee errors
## Library errors
###########################################################################
class MusicBeeError(LocalError):
class LocalLibraryError(LocalError):
"""Exception raised for errors related to MusicBee logic."""


class FieldError(MusicBeeError):
"""
Exception raised for errors related to MusicBee field.
:param message: Explanation of the error.
"""
def __init__(self, message: str | None = None, field: Any | None = None):
self.field = field
self.message = message
formatted = f"{message}: {field}" if field else message
super().__init__(message=formatted)
class MusicBeeError(LocalLibraryError):
"""Exception raised for errors related to MusicBee logic."""


class MusicBeeIDError(MusicBeeError):
Expand Down
4 changes: 2 additions & 2 deletions src/syncify/local/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def filename(self) -> str:
@property
def ext(self) -> str:
"""The file extension in lowercase."""
return splitext(self.path)[1].casefold()
return splitext(self.path)[1].lower()

@property
def size(self) -> int | None:
Expand Down Expand Up @@ -242,7 +242,7 @@ def map(self, value: str | File | None, check_existence: bool = False) -> str |
seps = ("\\", "/")
elif "\\" in replacement and "\\" not in path:
seps = ("/", "\\")
path = sep.join([replacement.rstrip("\\/"), path[len(stem):].lstrip("\\/")])
path = sep.join([replacement.rstrip("\\/"), path[len(stem):].lstrip("\\/")]).rstrip("\\/")
break

if sep == "\\":
Expand Down
28 changes: 11 additions & 17 deletions src/syncify/local/library/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Any

from syncify.local.collection import LocalCollection, LocalFolder, LocalAlbum, LocalArtist, LocalGenres
from syncify.local.exception import LocalCollectionError
from syncify.local.file import PathMapper, PathStemMapper
from syncify.local.playlist import PLAYLIST_FILETYPES, LocalPlaylist, load_playlist
from syncify.local.track import TRACK_CLASSES, LocalTrack, load_track
Expand Down Expand Up @@ -143,7 +142,7 @@ def playlist_folder(self, value: str | None):
pl_total = len(playlists)
pl_filtered = self.playlist_filter(playlists)
self._playlist_paths = {
name: path for name, path in sorted(playlists.items(), key=lambda x: x[0])
name: path for name, path in sorted(playlists.items(), key=lambda x: x[0].casefold())
if name in pl_filtered
}

Expand Down Expand Up @@ -304,24 +303,19 @@ def load_playlists(self) -> None:
return

self.logger.debug(f"Load {self.name} playlist data: START")
names = sorted(self._playlist_paths.keys())

self.logger.info(f"\33[1;95m >\33[1;97m Loading playlist data for {len(names)} playlists \33[0m")

playlists: dict[str, LocalPlaylist] = {}
bar: Iterable[str] = self.logger.get_progress_bar(iterable=names, desc="Loading playlists", unit="playlists")
for name in bar:
path = self._playlist_paths.get(name)
if path is None:
raise LocalCollectionError(
f"Playlist name not found in the stored paths of this manager: {name}", kind="playlist"
)
self.logger.info(
f"\33[1;95m >\33[1;97m Loading playlist data for {len(self._playlist_paths)} playlists \33[0m"
)

playlists[name] = load_playlist(
iterable = self._playlist_paths.items()
bar = self.logger.get_progress_bar(iterable=iterable, desc="Loading playlists", unit="playlists")
playlists: list[LocalPlaylist] = [
load_playlist(
path=path, tracks=self.tracks, path_mapper=self.path_mapper, remote_wrangler=self.remote_wrangler,
)
) for name, path in bar
]

self._playlists = playlists
self._playlists = {pl.name: pl for pl in sorted(playlists, key=lambda x: x.name.casefold())}
self.logger.debug(f"Load {self.name} playlists: DONE\n")

def log_playlists(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/syncify/local/library/musicbee.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(

library_folders = []
for path in to_collection(self.settings_xml.get("OrganisationMonitoredFolders", {}).get("string")):
library_folders.append(path)
library_folders.append(path_mapper.map(path))

super().__init__(
library_folders=library_folders,
Expand Down
3 changes: 2 additions & 1 deletion src/syncify/local/playlist/xautopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from syncify.local.file import PathMapper
from syncify.local.playlist.base import LocalPlaylist
from syncify.local.track import LocalTrack
from syncify.processors.filter import FilterDefinedList, FilterComparers, FilterMatcher
from syncify.processors.filter import FilterDefinedList, FilterComparers
from syncify.processors.filter_matcher import FilterMatcher
from syncify.processors.limit import ItemLimiter
from syncify.processors.sort import ItemSorter
from syncify.shared.core.enum import Fields
Expand Down
4 changes: 2 additions & 2 deletions src/syncify/local/track/base/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def uri(self, value: str | None):
else:
self._uri = value
self._has_uri = True
setattr(self, self.uri_tag.name.casefold(), value)
setattr(self, self.uri_tag.name.lower(), value)

@property
def has_uri(self):
Expand Down Expand Up @@ -539,7 +539,7 @@ def _read_uri(self) -> str | None:
return

# WORKAROUND: for dodgy MP3 tag comments, split on null and take first value
possible_values: tuple[str, ...] | None = to_collection(self[self.uri_tag.name.casefold()])
possible_values: tuple[str, ...] | None = to_collection(self[self.uri_tag.name.lower()])
if not possible_values:
return None

Expand Down
2 changes: 1 addition & 1 deletion src/syncify/local/track/base/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def extract_images_to_file(self, output_folder: str) -> int:
count = 0

for i, image in enumerate(images):
output_path = join(output_folder, self.filename + f"_{str(i).zfill(2)}" + image.format.casefold())
output_path = join(output_folder, self.filename + f"_{str(i).zfill(2)}" + image.format.lower())
os.makedirs(dirname(output_path), exist_ok=True)

image.save(output_path)
Expand Down
2 changes: 1 addition & 1 deletion src/syncify/local/track/base/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def _write_uri(self, dry_run: bool = True) -> bool:
if not self.remote_wrangler:
return False

tag_id = next(iter(self.tag_map[self.uri_tag.name.casefold()]), None)
tag_id = next(iter(self.tag_map[self.uri_tag.name.lower()]), None)
tag_value = self.remote_wrangler.unavailable_uri_dummy if not self.has_uri else self.uri
return self._write_tag(tag_id, tag_value, dry_run)

Expand Down
2 changes: 1 addition & 1 deletion src/syncify/local/track/flac.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _write_images(self, dry_run: bool = True) -> bool:
return updated

def delete_tag(self, tag_name: str, dry_run: bool = True) -> bool:
if tag_name == LocalTrackField.IMAGES.name.casefold():
if tag_name == LocalTrackField.IMAGES.name.lower():
self._file.clear_pictures()
return True

Expand Down
2 changes: 1 addition & 1 deletion src/syncify/local/track/mp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _write_uri(self, dry_run: bool = True) -> bool:

return tag_id is not None
else:
tag_id = next(iter(self.tag_map[self.uri_tag.name.casefold()]), None)
tag_id = next(iter(self.tag_map[self.uri_tag.name.lower()]), None)
return self._write_tag(tag_id, tag_value, dry_run)

def delete_tag(self, tag_name: str, dry_run: bool = True) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/syncify/processors/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from operator import mul
from typing import Any, Self

from syncify.local.exception import FieldError
from syncify.processors.base import DynamicProcessor, MusicBeeProcessor, dynamicprocessormethod
from syncify.processors.exception import ComparerError
from syncify.processors.time import TimeMapper
from syncify.shared.core.base import Item
from syncify.shared.core.enum import Field
from syncify.shared.exception import FieldError
from syncify.shared.field import Fields
from syncify.shared.types import UnitSequence
from syncify.shared.utils import to_collection
Expand Down
Loading

0 comments on commit 42b2c91

Please sign in to comment.