From fc5e768ef01b1178d756bd84c7a596449758357d Mon Sep 17 00:00:00 2001 From: blissful Date: Tue, 10 Oct 2023 23:24:36 -0400 Subject: [PATCH] first attempt at reading the file --- rose/__init__.py | 3 --- rose/cache/update.py | 1 + rose/virtualfs/__init__.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/rose/__init__.py b/rose/__init__.py index 725f4eb..228fe65 100644 --- a/rose/__init__.py +++ b/rose/__init__.py @@ -14,6 +14,3 @@ stream_handler = logging.StreamHandler(sys.stdout) stream_handler.setFormatter(stream_formatter) logger.addHandler(stream_handler) - file_handler = logging.FileHandler("/home/blissful/rose.log") - file_handler.setFormatter(stream_formatter) - logger.addHandler(file_handler) diff --git a/rose/cache/update.py b/rose/cache/update.py index f13a618..a1edf0b 100644 --- a/rose/cache/update.py +++ b/rose/cache/update.py @@ -220,6 +220,7 @@ def update_cache_for_release(c: Config, release_dir: Path) -> Path: virtual_filename += f" {{{tags.duration_sec % 60:02d}s}}" if tags.artists != tags.album_artists: virtual_filename += " [by " + _format_artists(tags.artists) + "]" + virtual_filename += filepath.suffix virtual_filename = sanitize_filename(virtual_filename) # And in case of a name collision, add an extra number at the end. Iterate to find # the first unused number. diff --git a/rose/virtualfs/__init__.py b/rose/virtualfs/__init__.py index 7077fe4..9460acc 100644 --- a/rose/virtualfs/__init__.py +++ b/rose/virtualfs/__init__.py @@ -4,6 +4,7 @@ import stat import subprocess from collections.abc import Iterator +from pathlib import Path from typing import Any, Literal import fuse @@ -200,6 +201,34 @@ def readdir(self, path: str, _: Any) -> Iterator[fuse.Direntry]: return return + raise fuse.FuseError(errno.ENOENT) + + def read(self, path: str, length: int, offset: int, _: int) -> bytes: + logger.debug(f"Received read for {path}") + + def read_bytes(p: Path) -> bytes: + with p.open("rb") as fp: + fp.seek(offset) + return fp.read(length) + + parts = path.split("/")[1:] # First part is always empty string. + + if parts[0] == "albums": + if len(parts) != 3: + raise fuse.FuseError(errno.ENOENT) + for track in list_tracks(self.config, parts[1]): + if track.virtual_filename == parts[2]: + return read_bytes(track.source_path) + raise fuse.FuseError(errno.ENOENT) + if parts[0] in ["artists", "genres", "labels"]: + if len(parts) != 4: + raise fuse.FuseError(errno.ENOENT) + for track in list_tracks(self.config, parts[2]): + if track.virtual_filename == parts[3]: + return read_bytes(track.source_path) + raise fuse.FuseError(errno.ENOENT) + raise fuse.FuseError(errno.ENOENT) + def mount_virtualfs(c: Config) -> None: server = VirtualFS(c)