Skip to content

Commit

Permalink
windows version prepared (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienPensart committed Nov 30, 2023
1 parent 7cc41df commit 91691dd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion musicbot/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def music_input(self) -> dict[str, Any] | None:
data["ipv4"] = folder.ipv4
data["username"] = folder.username
data["folder"] = folder.name
data["path"] = folder.path
data["path"] = str(folder.path)
return data

def set_tags(
Expand Down
9 changes: 7 additions & 2 deletions musicbot/folder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import asdict, dataclass
from pathlib import Path
from dataclasses import dataclass

from beartype import beartype

Expand Down Expand Up @@ -32,11 +32,16 @@ class Folder(MusicbotObject):
def __repr__(self) -> str:
return f"{self.name} {self.ipv4} {self.username}"

def to_dict(self) -> dict:
data = asdict(self)
data["path"] = str(data["path"])
return data

def effective_path(self, relative: bool = False) -> str:
path = str(self.path)
if relative:
path = str(self.path.relative_to(self.name))
return path.replace(" ", "\ ")
return path.replace(" ", "\\ ")

def http_link(self, relative: bool = False) -> str:
return f"http://{self.ipv4}/{self.effective_path(relative)}"
Expand Down
2 changes: 1 addition & 1 deletion musicbot/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def human_repr(self) -> str:
data: dict[str, Any] = asdict(self)
data["size"] = bytes_to_human(data["size"])
data["length"] = precise_seconds_to_human(data["length"])
data["folders"] = list(asdict(folder) for folder in data["folders"])
data["folders"] = list(folder.to_dict() for folder in data["folders"])
data["keywords"] = list(data["keywords"])
return yaml_dump(data)

Expand Down
2 changes: 1 addition & 1 deletion musicbot/musicdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def folders(self) -> list[Folder]:
folders = []
for result in results:
folder = Folder(
path=result.name,
path=Path(result.name),
name=result.name,
ipv4=result.ipv4,
username=result.username,
Expand Down
3 changes: 3 additions & 0 deletions musicbot/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import traceback
from collections.abc import Callable, Collection, Iterable, Sequence
from datetime import datetime
from pathlib import Path
from typing import IO, Any, NoReturn, ParamSpec, TypeVar

import attr
Expand All @@ -36,6 +37,8 @@ def default_encoder(data: Any) -> Any:
"""Encode in json structure which cannot"""
if isinstance(data, (frozenset, set)):
return list(data)
if isinstance(data, Path):
return str(data)
if dataclasses.is_dataclass(data):
return dataclasses.asdict(data)
# if isinstance(data, CaseInsensitiveDict):
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 91691dd

Please sign in to comment.