Added setting to disable the server for LAN chromecast devices
This commit is contained in:
@@ -406,6 +406,8 @@ class SublimeMusicApp(Gtk.Application):
|
||||
'download_on_stream'].get_active()
|
||||
self.state.config.song_play_notification = dialog.data[
|
||||
'song_play_notification'].get_active()
|
||||
self.state.config.serve_over_lan = dialog.data[
|
||||
'serve_over_lan'].get_active()
|
||||
self.state.config.prefetch_amount = dialog.data[
|
||||
'prefetch_amount'].get_value_as_int()
|
||||
self.state.config.concurrent_download_limit = dialog.data[
|
||||
@@ -557,7 +559,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.state.save_config()
|
||||
|
||||
def on_connected_server_changed(self, action, current_server):
|
||||
if self.state.config.current_server >= 0:
|
||||
if self.state.config.server:
|
||||
self.state.save()
|
||||
self.state.config.current_server = current_server
|
||||
self.state.save_config()
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import logging
|
||||
import keyring
|
||||
|
||||
from typing import List, Optional
|
||||
@@ -60,7 +61,8 @@ class AppConfiguration:
|
||||
prefetch_amount: int = 3
|
||||
concurrent_download_limit: int = 5
|
||||
port_number: int = 8282
|
||||
version: int = 1
|
||||
version: int = 2
|
||||
serve_over_lan: bool = True
|
||||
|
||||
def to_json(self):
|
||||
exclude = ('servers')
|
||||
@@ -78,6 +80,13 @@ class AppConfiguration:
|
||||
for server in self.servers:
|
||||
server.migrate()
|
||||
|
||||
if (getattr(self, 'version') or 0) < 2:
|
||||
logging.info('Migrating app configuration to version 2.')
|
||||
logging.info('Setting serve_over_lan to True')
|
||||
self.serve_over_lan = True
|
||||
|
||||
self.version = 2
|
||||
|
||||
@property
|
||||
def cache_location(self):
|
||||
if (hasattr(self, '_cache_location')
|
||||
|
@@ -194,7 +194,7 @@ class MPVPlayer(Player):
|
||||
class ChromecastPlayer(Player):
|
||||
chromecasts: List[Any] = []
|
||||
chromecast: pychromecast.Chromecast = None
|
||||
executor: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=50)
|
||||
executor: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=10)
|
||||
|
||||
class CastStatusListener:
|
||||
on_new_cast_status: Optional[Callable] = None
|
||||
@@ -316,9 +316,12 @@ class ChromecastPlayer(Player):
|
||||
self.host_ip = None
|
||||
|
||||
self.port = config.port_number
|
||||
self.server_thread = ChromecastPlayer.ServerThread(
|
||||
'0.0.0.0', self.port)
|
||||
self.server_thread.start()
|
||||
self.serve_over_lan = config.serve_over_lan
|
||||
|
||||
if self.serve_over_lan:
|
||||
self.server_thread = ChromecastPlayer.ServerThread(
|
||||
'0.0.0.0', self.port)
|
||||
self.server_thread.start()
|
||||
|
||||
def on_new_cast_status(self, status):
|
||||
self.on_player_event(
|
||||
@@ -389,8 +392,16 @@ class ChromecastPlayer(Player):
|
||||
|
||||
def play_media(self, file_or_url: str, progress: float, song: Child):
|
||||
stream_scheme = urlparse(file_or_url).scheme
|
||||
# If it's a local file, then see if we can serve it over the LAN.
|
||||
if not stream_scheme:
|
||||
file_or_url = f'http://{self.host_ip}:{self.port}/song/{song.id}'
|
||||
if self.serve_over_lan:
|
||||
host = f'{self.host_ip}:{self.port}'
|
||||
file_or_url = f'http://{host}/song/{song.id}'
|
||||
else:
|
||||
file_or_url, _ = CacheManager.get_song_filename_or_stream(
|
||||
song,
|
||||
force_stream=True,
|
||||
)
|
||||
|
||||
cover_art_url = CacheManager.get_cover_art_url(song.id, 1000)
|
||||
self.chromecast.media_controller.play_media(
|
||||
@@ -400,12 +411,12 @@ class ChromecastPlayer(Player):
|
||||
current_time=progress,
|
||||
title=song.title,
|
||||
thumb=cover_art_url,
|
||||
metadata=dict(
|
||||
metadataType=3,
|
||||
albumName=song.album,
|
||||
artist=song.artist,
|
||||
trackNumber=song.track,
|
||||
),
|
||||
metadata={
|
||||
'metadataType': 3,
|
||||
'albumName': song.album,
|
||||
'artist': song.artist,
|
||||
'trackNumber': song.track,
|
||||
},
|
||||
)
|
||||
self._timepos = progress
|
||||
|
||||
|
@@ -154,6 +154,10 @@ class ApplicationState:
|
||||
def migrate(self):
|
||||
"""Use this function to migrate any state storage that has changed."""
|
||||
self.config.migrate()
|
||||
self.save_config()
|
||||
|
||||
if self.config.server:
|
||||
self.save()
|
||||
|
||||
def save(self):
|
||||
# Make the necessary directories before writing the state.
|
||||
|
@@ -22,6 +22,10 @@ class SettingsDialog(EditFormDialog):
|
||||
'Show a notification when a song begins to play',
|
||||
'song_play_notification',
|
||||
),
|
||||
(
|
||||
'Serve locally cached files over the LAN to Chromecast devices.',
|
||||
'serve_over_lan',
|
||||
),
|
||||
]
|
||||
numeric_fields = [
|
||||
(
|
||||
|
Reference in New Issue
Block a user