Skip to content

Commit

Permalink
windows version prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienPensart committed Nov 28, 2023
1 parent 6c0d510 commit 7cc41df
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 155 deletions.
2 changes: 1 addition & 1 deletion musicbot/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def music(self) -> Music | None:
return None
folder = Folder(
name=str(self.folder),
path=str(self.path),
path=self.path,
username=current_user(),
ipv4=public_ip,
)
Expand Down
25 changes: 13 additions & 12 deletions musicbot/folder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path
from dataclasses import dataclass

from beartype import beartype
Expand All @@ -13,7 +13,7 @@ class Folder(MusicbotObject):
name: str
ipv4: str
username: str
path: str
path: Path

n_genres: int = 0
all_genres: str = ""
Expand All @@ -33,9 +33,10 @@ def __repr__(self) -> str:
return f"{self.name} {self.ipv4} {self.username}"

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

def http_link(self, relative: bool = False) -> str:
return f"http://{self.ipv4}/{self.effective_path(relative)}"
Expand All @@ -48,27 +49,27 @@ def remote_ssh_link(self) -> str:

def links(self, playlist_options: PlaylistOptions) -> frozenset[str]:
paths = []
if "all" in playlist_options.kinds:
return frozenset({self.local_ssh_link(), self.remote_ssh_link(), self.http_link(playlist_options.relative), self.effective_path(playlist_options.relative)})

# if "local-ssh" in playlist_options.kinds and self.ipv4 == self.public_ip():
if "local-ssh" in playlist_options.kinds:
if "all" in playlist_options.kinds or "local-ssh" in playlist_options.kinds:
paths.append(self.local_ssh_link())

# if "remote-ssh" in playlist_options.kinds and self.ipv4 != self.public_ip():
if "remote-ssh" in playlist_options.kinds:
if "all" in playlist_options.kinds or "remote-ssh" in playlist_options.kinds:
paths.append(self.remote_ssh_link())

# if "local-http" in playlist_options.kinds and self.ipv4 == self.public_ip():
if "local-http" in playlist_options.kinds:
if "all" in playlist_options.kinds or "local-http" in playlist_options.kinds:
paths.append(self.http_link(playlist_options.relative))

# if "remote-http" in playlist_options.kinds and self.ipv4 != self.public_ip():
if "remote-http" in playlist_options.kinds:
if "all" in playlist_options.kinds or "remote-http" in playlist_options.kinds:
paths.append(self.http_link(playlist_options.relative))

if "local" in playlist_options.kinds and os.path.isfile(self.path):
if "all" in playlist_options.kinds or "local" in playlist_options.kinds and self.path.is_file():
paths.append(self.effective_path(playlist_options.relative))
if "remote" in playlist_options.kinds and not os.path.isfile(self.path):

if "all" in playlist_options.kinds or "remote" in playlist_options.kinds and not self.path.is_file():
paths.append(self.effective_path(playlist_options.relative))

return frozenset(paths)
2 changes: 1 addition & 1 deletion musicbot/musicdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def upsert_path(
result = await upsert(self.client, **input_music)

keywords = frozenset(keyword.name for keyword in result.keywords)
folders = [Folder(path=folder.path, name=folder.name, ipv4=folder.ipv4, username=folder.username) for folder in result.folders if folder.path is not None]
folders = [Folder(path=Path(folder.path), name=folder.name, ipv4=folder.ipv4, username=folder.username) for folder in result.folders if folder.path is not None]
output_music = Music(
title=result.name,
artist=result.artist.name,
Expand Down
5 changes: 3 additions & 2 deletions musicbot/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import random
from codecs import StreamReaderWriter
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Self

import click
Expand Down Expand Up @@ -49,8 +50,8 @@ def from_edgedb(
musics = []
for result in results:
keywords = frozenset(keyword.name for keyword in result.keywords)
# folders = frozenset(Folder(path=folder["@path"], name=folder.name, ipv4=folder.ipv4, username=folder.username) for folder in result.folders)
folders = frozenset(Folder(path=folder.path, name=folder.name, ipv4=folder.ipv4, username=folder.username) for folder in result.folders)
# folders = frozenset(Folder(path=Path(folder["@path"]), name=folder.name, ipv4=folder.ipv4, username=folder.username) for folder in result.folders)
folders = frozenset(Folder(path=Path(folder.path), name=folder.name, ipv4=folder.ipv4, username=folder.username) for folder in result.folders)
music = Music(
title=result.name,
artist=result.artist.name,
Expand Down
Loading

0 comments on commit 7cc41df

Please sign in to comment.