fix(playback): forward preferred title and author to download manager
This commit is contained in:
@@ -45,12 +45,16 @@ class ControllerLifecycleMixin(ControllerStateMixin):
|
|||||||
try:
|
try:
|
||||||
proc, return_code = process_mod.run_ffplay(cmd)
|
proc, return_code = process_mod.run_ffplay(cmd)
|
||||||
if proc is None:
|
if proc is None:
|
||||||
if return_code == 0 and start_position > 0 and self.total_duration and start_position >= self.total_duration - 5:
|
if (
|
||||||
|
return_code == 0
|
||||||
|
and start_position > 0
|
||||||
|
and self.total_duration
|
||||||
|
and start_position >= self.total_duration - 5
|
||||||
|
):
|
||||||
notify("Reached end of file")
|
notify("Reached end of file")
|
||||||
self._reset_state()
|
self._reset_state()
|
||||||
return False
|
return False
|
||||||
notify(
|
notify(f"Playback process exited immediately (code: {return_code})")
|
||||||
f"Playback process exited immediately (code: {return_code})")
|
|
||||||
return False
|
return False
|
||||||
self.playback_process = proc
|
self.playback_process = proc
|
||||||
self.is_playing = True
|
self.is_playing = True
|
||||||
@@ -114,6 +118,8 @@ class ControllerLifecycleMixin(ControllerStateMixin):
|
|||||||
download_manager: DownloadManager,
|
download_manager: DownloadManager,
|
||||||
asin: str,
|
asin: str,
|
||||||
status_callback: StatusCallback | None = None,
|
status_callback: StatusCallback | None = None,
|
||||||
|
preferred_title: str | None = None,
|
||||||
|
preferred_author: str | None = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Download AAX if needed, get activation bytes, then start playback. Returns True on success."""
|
"""Download AAX if needed, get activation bytes, then start playback. Returns True on success."""
|
||||||
notify = status_callback or self.notify
|
notify = status_callback or self.notify
|
||||||
@@ -121,7 +127,12 @@ class ControllerLifecycleMixin(ControllerStateMixin):
|
|||||||
notify("Could not download file")
|
notify("Could not download file")
|
||||||
return False
|
return False
|
||||||
notify("Preparing playback...")
|
notify("Preparing playback...")
|
||||||
local_path = download_manager.get_or_download(asin, notify)
|
local_path = download_manager.get_or_download(
|
||||||
|
asin,
|
||||||
|
notify,
|
||||||
|
preferred_title=preferred_title,
|
||||||
|
preferred_author=preferred_author,
|
||||||
|
)
|
||||||
if not local_path:
|
if not local_path:
|
||||||
notify("Could not download file")
|
notify("Could not download file")
|
||||||
return False
|
return False
|
||||||
@@ -136,14 +147,15 @@ class ControllerLifecycleMixin(ControllerStateMixin):
|
|||||||
last = self.library_client.get_last_position(asin)
|
last = self.library_client.get_last_position(asin)
|
||||||
if last is not None and last > 0:
|
if last is not None and last > 0:
|
||||||
start_position = last
|
start_position = last
|
||||||
notify(
|
notify(f"Resuming from {LibraryClient.format_time(start_position)}")
|
||||||
f"Resuming from {LibraryClient.format_time(start_position)}")
|
|
||||||
except (OSError, ValueError, KeyError):
|
except (OSError, ValueError, KeyError):
|
||||||
pass
|
pass
|
||||||
notify(f"Starting playback of {local_path.name}...")
|
notify(f"Starting playback of {local_path.name}...")
|
||||||
self.current_asin = asin
|
self.current_asin = asin
|
||||||
self.last_save_time = time.time()
|
self.last_save_time = time.time()
|
||||||
return self.start(local_path, activation_hex, notify, start_position, self.playback_speed)
|
return self.start(
|
||||||
|
local_path, activation_hex, notify, start_position, self.playback_speed
|
||||||
|
)
|
||||||
|
|
||||||
def toggle_playback(self) -> bool:
|
def toggle_playback(self) -> bool:
|
||||||
"""Toggle between pause and resume. Returns True if an action was performed."""
|
"""Toggle between pause and resume. Returns True if an action was performed."""
|
||||||
@@ -160,7 +172,10 @@ class ControllerLifecycleMixin(ControllerStateMixin):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _restart_at_position(
|
def _restart_at_position(
|
||||||
self, new_position: float, new_speed: float | None = None, message: str | None = None
|
self,
|
||||||
|
new_position: float,
|
||||||
|
new_speed: float | None = None,
|
||||||
|
message: str | None = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Stop current process and start again at new_position; optionally set speed and notify."""
|
"""Stop current process and start again at new_position; optionally set speed and notify."""
|
||||||
if not self.is_playing or not self.current_file_path:
|
if not self.is_playing or not self.current_file_path:
|
||||||
@@ -170,7 +185,9 @@ class ControllerLifecycleMixin(ControllerStateMixin):
|
|||||||
speed = new_speed if new_speed is not None else saved["speed"]
|
speed = new_speed if new_speed is not None else saved["speed"]
|
||||||
self._stop_process()
|
self._stop_process()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
if self.start(saved["file_path"], saved["activation"], self.notify, new_position, speed):
|
if self.start(
|
||||||
|
saved["file_path"], saved["activation"], self.notify, new_position, speed
|
||||||
|
):
|
||||||
self.current_asin = saved["asin"]
|
self.current_asin = saved["asin"]
|
||||||
self.total_duration = saved["duration"]
|
self.total_duration = saved["duration"]
|
||||||
self.chapters = saved["chapters"]
|
self.chapters = saved["chapters"]
|
||||||
|
|||||||
Reference in New Issue
Block a user