Skip to content

Commit

Permalink
first attempt at reading the file
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 11, 2023
1 parent 5fd711b commit fc5e768
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
3 changes: 0 additions & 3 deletions rose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions rose/cache/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions rose/virtualfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import stat
import subprocess
from collections.abc import Iterator
from pathlib import Path
from typing import Any, Literal

import fuse
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fc5e768

Please sign in to comment.