Skip to content

Commit

Permalink
Small typing and pathlib fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
C0rn3j committed Dec 24, 2024
1 parent eeaf013 commit 733ae43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
from tauon.t_modules import t_bootstrap
from tauon.t_modules.t_config import Config
from tauon.t_modules.t_db_migrate import database_migrate
#from tauon.t_modules.t_dbus import MPRIS
from tauon.t_modules.t_dbus import Gnome
from tauon.t_modules.t_draw import QuickThumbnail, TDraw
from tauon.t_modules.t_extra import (
ColourGenCache,
Expand Down Expand Up @@ -336,8 +336,6 @@
#from tauon.t_modules.guitar_chords import GuitarChords

if TYPE_CHECKING:
# TODO(Martin): These two classes are within player4(), rip them out and put them as a top level?
from tauon.t_modules.t_phazor import Cachement, LibreSpot
from ctypes import CDLL
from io import BufferedReader, BytesIO
from pylast import Artist, LibreFMNetwork
Expand Down Expand Up @@ -5220,9 +5218,8 @@ def __init__(self):
self.gst_devices = [] # Display names
self.gst_outputs = {} # Display name : (sink, device)

# The way the class is defined in t_dbus makes it tricky to import
# self.mpris: MPRIS | None = None
self.mpris = None
# TODO(Martin) : Fix this by moving the class to root of the module
self.mpris: Gnome.main.MPRIS | None = None
self.tray_update = None
self.eq = [0] * 2 # not used
self.enable_eq = True # not used
Expand Down Expand Up @@ -8788,7 +8785,8 @@ def __init__(self):
self.desktop = desktop
self.device = socket.gethostname()

self.cachement: Cachement | None = None
# TODO(Martin) : Fix this by moving the class to root of the module
self.cachement: player4.Cachement | None = None
self.dummy_event = SDL_Event()
self.translate = _
self.strings = strings
Expand Down Expand Up @@ -8851,7 +8849,8 @@ def __init__(self):
self.remote_limited = True
self.enable_librespot = shutil.which("librespot")

self.spotc: LibreSpot | None = None
# TODO(Martin) : Fix this by moving the class to root of the module
self.spotc: player4.LibreSpot | None = None
self.librespot_p = None
self.MenuItem = MenuItem
self.tag_scan = tag_scan
Expand Down
13 changes: 7 additions & 6 deletions src/tauon/t_modules/t_phazor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def phazor_exists(pctl: PlayerCtl) -> bool:
return get_phazor_path(pctl).exists()

def player4(tauon: Tauon) -> None:

pctl = tauon.pctl
gui = tauon.gui
prefs = tauon.prefs
Expand Down Expand Up @@ -168,9 +167,9 @@ def scan_device() -> None:

class LibreSpot:
def __init__(self) -> None:

self.running = False
self.flush = False

def go(self, force: bool = False) -> int:
aud.config_set_feed_samplerate(44100)
aud.config_set_min_buffer(1000)
Expand Down Expand Up @@ -222,9 +221,11 @@ def go(self, force: bool = False) -> int:
return 1

return 0

def soft_end(self) -> None:
self.running = False
pctl.spot_playing = False

def end(self) -> None:
self.running = False
pctl.spot_playing = False
Expand Down Expand Up @@ -378,7 +379,7 @@ def __init__(self) -> None:
self.direc = audio_cache2
if prefs.tmp_cache:
self.direc = os.path.join(tmp_cache_dir(), "audio-cache")
if not os.path.exists(self.direc):
if not Path(self.direc).exists():
os.makedirs(self.direc)
self.list: list[str] = prefs.cache_list
self.files = os.listdir(self.direc)
Expand All @@ -395,9 +396,9 @@ def get_key(self, track: TrackClass) -> str:
def get_file_cached_only(self, track: TrackClass) -> str | None:
key = self.get_key(track)
if key in self.files:
path = os.path.join(self.direc, key)
if os.path.isfile(path):
return path
path = Path(self.direc) / key
if path.is_file():
return str(path)
return None

def get_file(self, track: TrackClass) -> tuple[int, str | None]:
Expand Down

0 comments on commit 733ae43

Please sign in to comment.