Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromecast fixups, run.sh dirty venv mode, typing, enable warnings module and fix closing file handles #1345

Merged
merged 17 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ Changelog
### v7.9.0

- **Added** TIDAL support
- **Fixed** crashes related to PipeWire [#1250](https://github.com/Taiko2k/Tauon/issues/1250)
- **Fixed** audio cutting out on the PipeWire backend with specific custom quantum settings [#1245](https://github.com/Taiko2k/Tauon/issues/1245)
- **Fixed** wrong encoding used for some tags in XSPF exports [#1331](https://github.com/Taiko2k/Tauon/issues/1331)
- **Fixed** Spotify local audio playback. User Spotify password entry no longer required
- **Fixed** gensokyoradio.net radio fallback URL
- **Fixed** mishandling display change event, this fixes the "Grr" errors in the log
- **Fixed** loading configuration with negative integers, this fixes setting a negative baseline offset
- **Fixed** playlist being able to skip to next song even when current song was looped due to a race condition
- ***Removed*** guitar chords feature - api.guitarchords.com it partially relied on is dead and this feature was unmaintained
- **Fixed** leaking file handlers when handling themes and databases, this may fix potential memory leaks
- ***Removed*** guitar chords feature - api.guitarchords.com it partially relied on is dead, replaced by newer API that would need implementing, and the chords feature was unmaintained
- **Improved** Various changes to build system, Migrated to pyproject.toml
- Many other bug fixes and code refactors [Special thanks to @C0rn3j for a lot of these]


### v7.8.3

- **Fixed** crash when using IME
Expand Down
27 changes: 23 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ win_build() {
cp TaskbarLib.tlb dist/tauon/ || echo 'TLB is not present!'
}

dirty_venv_run() {
if ! command -v python; then
echo -e "python executable not found? Is python installed? Debian(-based) distributions may need python-is-python3 installed via apt."
exit 1
fi
# Ensure correct cwd, for example: ~/Projects/Tauon
cd "$(dirname "${0}")"
export PYTHONPATH=".":"${PYTHONPATH-}"
source .venv/bin/activate
tauonmb # "${@}" # Passing args is broken atm
}

clean_venv_run() {
if ! command -v python; then
Expand Down Expand Up @@ -117,11 +128,13 @@ process_answer() {
case "${answer}" in
"Clean venv run,1" | "1" ) # TODO(Martin): restore ability to pass args if necessary
clean_venv_run; exit ;;
"Windows build,2" | "2" )
"Dirty venv run,2" | "2" )
dirty_venv_run; exit ;;
"Windows build,3" | "3" )
win_build; exit ;;
"Compile phazor,3" | "3" )
"Compile phazor,4" | "4" )
compile_phazor; exit ;;
"Compile phazor with PipeWire support,4" | "4" )
"Compile phazor with PipeWire support,5" | "5" )
compile_phazor_pipewire; exit ;;
* )
echo "Wrong option supplied! Options were: "
Expand All @@ -134,7 +147,13 @@ process_answer() {
esac
}

answer_options=("Clean venv run" "Windows build" "Compile phazor" "Compile phazor with PipeWire support")
answer_options=(
"Clean venv run"
"Dirty venv run"
"Windows build"
"Compile phazor"
"Compile phazor with PipeWire support")

if [[ ${#} -eq 0 ]]; then
show_menu
else
Expand Down
7 changes: 7 additions & 0 deletions src/tauon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ def emit(self, record: dict):
logging.getLogger().handlers[0].setLevel(logging.DEBUG)
logging.getLogger().handlers[0].setFormatter(CustomLoggingFormatter())

# https://docs.python.org/3/library/warnings.html
logging.captureWarnings(capture=True)
if not sys.warnoptions:
import warnings
warnings.simplefilter("default")
os.environ["PYTHONWARNINGS"] = "default" # Also affect subprocesses

if sys.platform != "win32":
import fcntl

Expand Down
53 changes: 39 additions & 14 deletions src/tauon/t_modules/t_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from tauon.t_modules.t_extra import shooter

if TYPE_CHECKING:
from pychromecast import Chromecast
from pychromecast.models import CastInfo

from tauon.t_modules.t_main import Tauon

def get_ip() -> str:
Expand All @@ -17,24 +20,22 @@ def get_ip() -> str:
try:
# doesn't even have to be reachable
s.connect(("10.255.255.255", 1))
IP = s.getsockname()[0]
IPv4 = s.getsockname()[0]
except Exception:
logging.exception("Failed to get socket name.")
IP = "127.0.0.1"
IPv4 = "127.0.0.1"
finally:
s.close()
return IP
return IPv4


class Chrome:
def __init__(self, tauon: Tauon) -> None:
self.tauon = tauon
self.services = []
self.active = False
self.cast = None
self.target_playlist = None
self.target_id = None
self.save_vol = 100
self.tauon: Tauon = tauon
self.services: list[CastInfo] = []
self.active: bool = False
self.cast: Chromecast | None = None
self.save_vol: float = 100

def rescan(self) -> None:
logging.info("Scanning for chromecasts...")
Expand All @@ -43,8 +44,11 @@ def rescan(self) -> None:
try:
#self.tauon.gui.show_message(self.tauon.strings.scan_chrome)
services, browser = pychromecast.discovery.discover_chromecasts()
pychromecast.discovery.stop_discovery(browser)
browser.stop_discovery()
menu = self.tauon.chrome_menu
if menu is None:
logging.critical("menu was None, this should not happen!")
return
MenuItem = self.tauon.MenuItem

#menu.items.clear()
Expand Down Expand Up @@ -84,15 +88,21 @@ def four(self, item: dict) -> None:


def update(self) -> tuple:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return ()
self.cast.media_controller.update_status()
return self.cast.media_controller.status.current_time, \
self.cast.media_controller.status.media_custom_data.get("id"), \
self.cast.media_controller.status.player_state, \
self.cast.media_controller.status.duration

def start(self, track_id: int, enqueue: bool = False, t: int = 0, url: str | None = None) -> None:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return
self.cast.wait()
tr = self.tauon.pctl.g(track_id)
tr = self.tauon.pctl.get_track(track_id)
n = 0
try:
n = int(tr.track_number)
Expand Down Expand Up @@ -122,18 +132,33 @@ def start(self, track_id: int, enqueue: bool = False, t: int = 0, url: str | Non
self.cast.media_controller.play_media(url, "audio/mpeg", media_info=m, metadata=d, current_time=t, enqueue=enqueue)

def stop(self) -> None:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return
self.cast.media_controller.stop()

def play(self) -> None:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return
self.cast.media_controller.play()

def pause(self) -> None:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return
self.cast.media_controller.pause()

def seek(self, t: str) -> None:
self.cast.media_controller.seek(t)
def seek(self, position: float) -> None:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return
self.cast.media_controller.seek(position)

def volume(self, decimal: int) -> None:
if self.cast is None:
logging.critical("self.cast was None, this should not happen!")
return
self.cast.set_volume(decimal)

def end(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/tauon/t_modules/t_jellyfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def upload_playlist(self, pl: TauonPlaylist) -> None:

ids = []
for t in self.pctl.multi_playlist[pl].playlist_ids:
track = self.pctl.g(t)
track = self.pctl.get_track(t)
if track.url_key not in ids and track.file_ext == "JELY":
ids.append(track.url_key)

Expand Down Expand Up @@ -444,7 +444,7 @@ def ingest_library(self, return_list: bool = False) -> list | None:
#logging.info(track.items())
if replace_existing:
track_id = existing_track
nt = self.pctl.g(track_id)
nt = self.pctl.get_track(track_id)
else:
nt = self.tauon.TrackClass()
nt.index = track_id # this is tauons track id
Expand Down
Loading
Loading