diff --git a/cozy/architecture/observable.py b/cozy/architecture/observable.py index eb27831f..9380d4f7 100644 --- a/cozy/architecture/observable.py +++ b/cozy/architecture/observable.py @@ -33,21 +33,23 @@ def remove_bind(self, prop: str, callback: Callable): if callback in self._observers[prop]: self._observers[prop].remove(callback) else: - log.info("Callback not found in prop's {} observers. Skipping remove bind...".format(prop)) + log.info("Callback not found in prop's %s observers. Skipping remove bind...", prop) else: log.info("Prop not found in observers. Skipping remove bind...") def _notify(self, prop: str): + if prop not in self._observers: + return + try: - if prop in self._observers: - for callback in self._observers[prop]: - callback() + for callback in self._observers[prop]: + callback() except Exception as e: log.error(e) reporter.exception("observable", e) def _notify_main_thread(self, prop: str): - GLib.MainContext.default().invoke_full(GLib.PRIORITY_DEFAULT_IDLE, self._notify, (prop)) + GLib.MainContext.default().invoke_full(GLib.PRIORITY_DEFAULT_IDLE, self._notify, prop) def _destroy_observers(self): self._observers = {} diff --git a/cozy/control/artwork_cache.py b/cozy/control/artwork_cache.py index 462e7ddd..e2bbdf23 100644 --- a/cozy/control/artwork_cache.py +++ b/cozy/control/artwork_cache.py @@ -129,7 +129,7 @@ def _load_pixbuf_from_cache(self, book, size): else: pixbuf = None except Exception as e: - log.warning("Failed to load pixbuf from path: {}. Deleting file.".format(path)) + log.warning("Failed to load pixbuf from path: %s. Deleting file.", path) log.debug(e) os.remove(path) return None diff --git a/cozy/control/db.py b/cozy/control/db.py index 935c7168..247dc618 100644 --- a/cozy/control/db.py +++ b/cozy/control/db.py @@ -25,7 +25,7 @@ def init_db(): _connect_db(_db) sqlite_version = ".".join([str(num) for num in _db.server_version]) - log.info("SQLite version: {}".format(sqlite_version)) + log.info("SQLite version: %s", sqlite_version) if Settings.table_exists(): update_db() diff --git a/cozy/control/db_updater.py b/cozy/control/db_updater.py index bd973110..ec66d02c 100644 --- a/cozy/control/db_updater.py +++ b/cozy/control/db_updater.py @@ -136,7 +136,7 @@ def _update_db_9(db): file = next((f for f in files if f.path == path), None) if File.select().where(File.path == path).count() > 0: - log.info("Path already existing in db: {}".format(path)) + log.info("Path already existing in db: %s", path) file = File.select().where(File.path == path).get() elif not file: file = File(path=path, modified=track.modified, id=file_id) @@ -144,7 +144,7 @@ def _update_db_9(db): file_id += 1 if TrackToFile.select().join(Track).where(TrackToFile.track.id == track.id).count() > 0: - log.info("TrackToFile already existing in db: {}".format(path)) + log.info("TrackToFile already existing in db: %s", path) continue track_to_file = TrackToFile(track=track.id, file=file, start_at=0) diff --git a/cozy/control/filesystem_monitor.py b/cozy/control/filesystem_monitor.py index bc826f9c..cfdf7a1f 100644 --- a/cozy/control/filesystem_monitor.py +++ b/cozy/control/filesystem_monitor.py @@ -100,10 +100,10 @@ def is_external(self, directory: str) -> bool: return False if path in directory and mount.can_unmount(): - log.info("Storage location {} is external".format(directory)) + log.info("Storage location %s is external", directory) return True - log.info("Storage location {} is not external".format(directory)) + log.info("Storage location %s is not external", directory) return False def __on_mount_added(self, monitor, mount): diff --git a/cozy/control/mpris.py b/cozy/control/mpris.py index 42e0746d..da206fa9 100644 --- a/cozy/control/mpris.py +++ b/cozy/control/mpris.py @@ -106,17 +106,17 @@ def on_method_call( result = getattr(self, snake_method)(*args) except AttributeError: invocation.return_dbus_error( - "{}.Error.NotSupported".format(interface_name), "Unsupported property" + f"{interface_name}.Error.NotSupported", "Unsupported property" ) except Exception as e: log.error(e) reporter.exception("mpris", e) reporter.error( "mpris", - "MPRIS method call failed with method name: {}".format(method_name), + f"MPRIS method call failed with method name: {method_name}", ) invocation.return_dbus_error( - "{}.Error.Failed".format(interface_name), "Internal exception occurred" + f"{interface_name}.Error.Failed", "Internal exception occurred" ) else: # out_args is at least (signature1). diff --git a/cozy/media/files.py b/cozy/media/files.py index f31efb69..c4d9092a 100644 --- a/cozy/media/files.py +++ b/cozy/media/files.py @@ -52,7 +52,7 @@ def _copy_all(self, sources, destination: str): self._copy_file(path, file_copy_destination) def _copy_file(self, source_path: str, dest_path: str): - log.info("Copy file {} to {}".format(source_path, dest_path)) + log.info("Copy file %s to %s", source_path, dest_path) source = Gio.File.new_for_path(source_path) destination = Gio.File.new_for_path(dest_path) @@ -72,7 +72,7 @@ def _copy_file(self, source_path: str, dest_path: str): else: reporter.exception("files", e) - log.error("Failed to copy file: {}".format(e)) + log.error("Failed to copy file: %s", e) self._file_progess += 1 def _copy_directory(self, path, destination): diff --git a/cozy/media/gst_player.py b/cozy/media/gst_player.py index 27396c40..6d57d553 100644 --- a/cozy/media/gst_player.py +++ b/cozy/media/gst_player.py @@ -99,7 +99,7 @@ def state(self) -> GstPlayerState: elif state == Gst.State.PAUSED: return GstPlayerState.PAUSED else: - log.debug("GST player state was not playing or paused but {}.".format(state)) + log.debug("GST player state was not playing or paused but %s", state) return GstPlayerState.STOPPED @property @@ -268,7 +268,7 @@ def _on_gst_message(self, _, message: Gst.Message): reporter.warning("gst_player", "gst: Resource not found. Stopping player.") return - reporter.error("player", "{}: {}".format(error.code, error)) - log.error("{}: {}".format(error.code, error)) + reporter.error("player", f"{error.code}: {error}") + log.error("%s: %s", error.code, error) log.debug(debug_msg) self.emit_event("error", error) diff --git a/cozy/media/importer.py b/cozy/media/importer.py index d5429372..884c55e6 100644 --- a/cozy/media/importer.py +++ b/cozy/media/importer.py @@ -198,7 +198,7 @@ def _filter_unchanged_files(self, files: List[str]) -> List[str]: yield file except Exception as e: log.debug(e) - log.info("Could not get modified timestamp for file {}".format(file)) + log.info("Could not get modified timestamp for file %s", file) continue continue diff --git a/cozy/media/media_detector.py b/cozy/media/media_detector.py index c5f3fb19..cfb1a6d4 100644 --- a/cozy/media/media_detector.py +++ b/cozy/media/media_detector.py @@ -34,7 +34,7 @@ def get_media_data(self) -> MediaFile: try: discoverer_info: GstPbutils.DiscovererInfo = self.discoverer.discover_uri(self.uri) except Exception as e: - log.info("Skipping file because it couldn't be detected: {}".format(self.uri)) + log.info("Skipping file because it couldn't be detected: %s", self.uri) raise AudioFileCouldNotBeDiscovered(self.uri) is_valid_audio_file = self._is_valid_audio_file(discoverer_info) diff --git a/cozy/media/player.py b/cozy/media/player.py index e018a4b0..472c5563 100644 --- a/cozy/media/player.py +++ b/cozy/media/player.py @@ -380,7 +380,7 @@ def _emit_tick(self): position_for_ui = self.position - self.loaded_chapter.start_position self.emit_event_main_thread("position", position_for_ui) except Exception as e: - log.warning("Could not emit position event: {}".format(e)) + log.warning("Could not emit position event: %s", e) def _fadeout_playback(self): duration = self._app_settings.sleep_timer_fadeout_duration * 20 diff --git a/cozy/model/book.py b/cozy/model/book.py index 9e4d5bc2..a5b62775 100644 --- a/cozy/model/book.py +++ b/cozy/model/book.py @@ -216,7 +216,7 @@ def _fetch_chapters(self): except TrackInconsistentData: log.warning("Skipping inconsistent model") except Exception as e: - log.error("Could not create chapter object: {}".format(e)) + log.error("Could not create chapter object: %s", e) for chapter in self._chapters: chapter.add_listener(self._on_chapter_event) diff --git a/cozy/model/database_importer.py b/cozy/model/database_importer.py index 8629b14d..29aa10d8 100644 --- a/cozy/model/database_importer.py +++ b/cozy/model/database_importer.py @@ -81,7 +81,7 @@ def _prepare_track_db_objects(self, media_files: Set[MediaFile]) -> Set[TrackIns book = next((book for book in book_db_objects if is_same_book(book.name, media_file.book_name)), None) file_query = File.select().where(File.path == media_file.path) if not file_query.exists(): - log.error("No file object with path present: {}".format(media_file.path)) + log.error("No file object with path present: %s", media_file.path) continue file = file_query.get() diff --git a/cozy/model/library.py b/cozy/model/library.py index e25dcb8c..d377dece 100644 --- a/cozy/model/library.py +++ b/cozy/model/library.py @@ -93,10 +93,8 @@ def rebase_path(self, old_path: str, new_path: str): self.emit_event_main_thread("rebase-started") chapter_count = len(self.chapters) - progress = 0 - for chapter in self.chapters: + for progress, chapter in enumerate(self.chapters, 1): if chapter.file.startswith(old_path): - progress += 1 chapter.file = chapter.file.replace(old_path, new_path) self.emit_event_main_thread("rebase-progress", progress / chapter_count) diff --git a/cozy/model/settings.py b/cozy/model/settings.py index 432415bb..c9202233 100644 --- a/cozy/model/settings.py +++ b/cozy/model/settings.py @@ -1,5 +1,4 @@ import logging -from typing import List, Optional import peewee @@ -16,8 +15,8 @@ class Settings: - _storages: List[Storage] = [] - _db = cache = inject.attr(SqliteDatabase) + _storages: list[Storage] = [] + _db = inject.attr(SqliteDatabase) def __init__(self): self._db_object: SettingsModel = SettingsModel.get() @@ -27,7 +26,7 @@ def first_start(self) -> bool: return self._db_object.first_start @property - def last_played_book(self) -> Optional[Book]: + def last_played_book(self) -> Book | None: try: return self._db_object.last_played_book except peewee.DoesNotExist: @@ -48,21 +47,21 @@ def last_played_book(self, new_value): self._db_object.save(only=self._db_object.dirty_fields) @property - def default_location(self): - return next(location - for location - in self.storage_locations - if location.default) + def default_location(self) -> bool: + for location in self.storage_locations: + if location.default: + return True + return False @property - def storage_locations(self): + def storage_locations(self) -> list[Storage]: if not self._storages: self._load_all_storage_locations() return self._storages @property - def external_storage_locations(self): + def external_storage_locations(self) -> list[Storage]: if not self._storages: self._load_all_storage_locations() @@ -78,14 +77,12 @@ def _load_all_storage_locations(self): try: self._storages.append(Storage(self._db, storage_db_obj.id)) except InvalidPath: - log.error("Invalid path found in database, skipping: {}".format(storage_db_obj.path)) + log.error("Invalid path found in database, skipping: %s", storage_db_obj.path) self._ensure_default_storage_present() def _ensure_default_storage_present(self): - default_storage_present = any(storage.default - for storage - in self._storages) + default_storage_present = any(storage.default for storage in self._storages) - if not default_storage_present and len(self._storages) > 0: + if not default_storage_present and self._storages: self._storages[0].default = True diff --git a/cozy/model/single_file_chapter.py b/cozy/model/single_file_chapter.py deleted file mode 100644 index be387575..00000000 --- a/cozy/model/single_file_chapter.py +++ /dev/null @@ -1,31 +0,0 @@ -from cozy.model.chapter import Chapter - - -class SingleFileChapter(Chapter): - @property - def name(self): - pass - - @property - def number(self): - pass - - @property - def disk(self): - pass - - @property - def position(self): - pass - - @property - def file(self): - pass - - @property - def length(self): - pass - - @property - def modified(self): - pass diff --git a/cozy/model/track.py b/cozy/model/track.py index 971be6b0..983fccbe 100644 --- a/cozy/model/track.py +++ b/cozy/model/track.py @@ -35,7 +35,7 @@ def name(self): if self._db_object.name: return self._db_object.name - return "{} {}".format(_("Chapter"), self.number) + return f"{_('Chapter')} {self.number}" @name.setter def name(self, new_name: str): diff --git a/cozy/report/report_to_loki.py b/cozy/report/report_to_loki.py index 6b779065..6720a100 100644 --- a/cozy/report/report_to_loki.py +++ b/cozy/report/report_to_loki.py @@ -61,7 +61,7 @@ def report(component: str, type: LogLevel, message: str, exception: Exception): labels = __append_label(labels, "distro_version", distro.version()) labels = __append_label(labels, "desktop_environment", os.environ.get('DESKTOP_SESSION')) - line = "[{}] {}".format(LOG_LEVEL_MAP[type], message) + line = f"[{LOG_LEVEL_MAP[type]}] {message}" headers = { 'Content-type': 'application/json' diff --git a/cozy/ui/library_view.py b/cozy/ui/library_view.py index 3e530919..b97f0261 100644 --- a/cozy/ui/library_view.py +++ b/cozy/ui/library_view.py @@ -1,14 +1,13 @@ import functools from typing import Optional -from gi.repository import Gtk, Adw -from gi.repository.Gtk import Builder +from gi.repository import Adw, Gtk from cozy.ext import inject from cozy.ui.widgets.book_element import BookElement from cozy.ui.delete_book_view import DeleteBookView from cozy.ui.widgets.filter_list_box import FilterListBox -from cozy.view_model.library_view_model import LibraryViewModel, LibraryViewMode, LibraryPage +from cozy.view_model.library_view_model import LibraryViewModel, LibraryViewMode READER_PAGE = "reader" AUTHOR_PAGE = "author" @@ -23,7 +22,7 @@ class LibraryView: _view_model: LibraryViewModel = inject.attr(LibraryViewModel) - def __init__(self, builder: Builder): + def __init__(self, builder: Gtk.Builder): self._builder = builder self._connected_book_element: Optional[BookElement] = None diff --git a/cozy/view_model/book_detail_view_model.py b/cozy/view_model/book_detail_view_model.py index ede76aec..4eb7e9c9 100644 --- a/cozy/view_model/book_detail_view_model.py +++ b/cozy/view_model/book_detail_view_model.py @@ -1,5 +1,3 @@ -from typing import Optional - from cozy import tools from cozy.application_settings import ApplicationSettings from cozy.architecture.event_sender import EventSender @@ -29,7 +27,7 @@ def __init__(self): self._play = False self._current_chapter = None - self._book: Book = None + self._book: Book | None = None self._lock_ui: bool = False self._player.add_listener(self._on_player_event) @@ -45,14 +43,14 @@ def playing(self) -> bool: return self._player.playing @property - def current_chapter(self) -> Optional[Chapter]: + def current_chapter(self) -> Chapter | None: if not self.book: return None return self.book.current_chapter @property - def book(self) -> Optional[Book]: + def book(self) -> Book | None: return self._book @book.setter @@ -77,33 +75,32 @@ def book(self, value: Book): self._notify("book") @property - def last_played_text(self) -> Optional[str]: + def last_played_text(self) -> str | None: if not self._book: return None return tools.past_date_to_human_readable(self._book.last_played) @property - def total_text(self) -> Optional[str]: + def total_text(self) -> str | None: if not self._book: return None return tools.seconds_to_human_readable(self._book.duration / self._book.playback_speed) @property - def remaining_text(self) -> Optional[str]: + def remaining_text(self) -> str | None: if not self._book: return None - remaining = self._book.duration / self._book.playback_speed - self._book.progress / self._book.playback_speed - return tools.seconds_to_human_readable(remaining) + remaining = self._book.duration - self._book.progress + return tools.seconds_to_human_readable(remaining / self._book.playback_speed) @property - def progress_percent(self) -> Optional[float]: + def progress_percent(self) -> float | None: if not self._book: return None - - if self._book.duration < 1: + elif self._book.duration < 1: return 1.0 return self._book.progress / self._book.duration @@ -113,9 +110,7 @@ def disk_count(self) -> int: if not self._book: return 0 - return len({chapter.disk - for chapter - in self._book.chapters}) + return len({chapter.disk for chapter in self._book.chapters}) @property def is_book_available(self) -> bool: @@ -127,10 +122,10 @@ def is_book_available(self) -> bool: @property def is_book_external(self) -> bool: first_chapter_path = self._book.chapters[0].file - return any(storage.path - in first_chapter_path - for storage - in self._settings.external_storage_locations) + for storage in self._settings.external_storage_locations: + if storage.path in first_chapter_path: + return True + return False @property def lock_ui(self) -> bool: @@ -167,9 +162,9 @@ def _on_player_event(self, event, message): if not self.book: return - if event == "play" or event == "pause": + if event in {"play", "pause"}: self._notify("playing") - elif event == "position" or event == "book-finished": + elif event in {"position", "book-finished"}: self._notify("progress_percent") self._notify("remaining_text") @@ -177,9 +172,7 @@ def _on_fs_monitor_event(self, event, _): if not self._book: return - if event == "storage-online": - self._notify("is_book_available") - elif event == "storage-offline": + if event in {"storage-online", "storage-offline"}: self._notify("is_book_available") def _on_book_current_chapter_changed(self): @@ -203,15 +196,10 @@ def _on_playback_speed_changed(self): self._notify("total_text") def _on_offline_cache_event(self, event, message): - try: - if message.id != self._book.id: - return - except Exception as e: + if not (message and self._book) or self._book.id != message.id: return - if event == "book-offline-removed": - self._notify("downloaded") - elif event == "book-offline": + if event in {"book-offline-removed", "book-offline"}: self._notify("downloaded") def _on_app_setting_changed(self, event, _): diff --git a/cozy/view_model/headerbar_view_model.py b/cozy/view_model/headerbar_view_model.py index dc20d622..f2ec365c 100644 --- a/cozy/view_model/headerbar_view_model.py +++ b/cozy/view_model/headerbar_view_model.py @@ -38,7 +38,7 @@ def __init__(self): @property def lock_ui(self) -> bool: - return self._view == View.NO_MEDIA or self._view == View.EMPTY_STATE or self._view == View.PREPARING_LIBRARY + return self._view in {View.NO_MEDIA, View.EMPTY_STATE, View.PREPARING_LIBRARY} @property def state(self) -> HeaderBarState: diff --git a/cozy/view_model/library_view_model.py b/cozy/view_model/library_view_model.py index 612724e8..180ac467 100644 --- a/cozy/view_model/library_view_model.py +++ b/cozy/view_model/library_view_model.py @@ -3,8 +3,6 @@ from enum import Enum, auto from typing import Optional -from gi.repository import Gtk - import cozy.ext.inject as inject from cozy.application_settings import ApplicationSettings from cozy.architecture.event_sender import EventSender @@ -31,12 +29,6 @@ class LibraryViewMode(Enum): READER = auto() -class LibraryPage(Enum): - NONE = auto() - FILTER = auto() - BOOKS = auto() - - class LibraryViewModel(Observable, EventSender): _application_settings: ApplicationSettings = inject.attr(ApplicationSettings) _fs_monitor: FilesystemMonitor = inject.attr("FilesystemMonitor") @@ -86,8 +78,11 @@ def selected_filter(self, value): self._notify("selected_filter") @property - def is_any_book_in_progress(self): - return any(book.position > 0 for book in self.books) + def is_any_book_in_progress(self) -> bool: + for book in self.books: + if book.position > 0: + return True + return False @property def authors(self): @@ -135,24 +130,20 @@ def remove_book(self, book: Book): def display_book_filter(self, book_element: BookElement): book = book_element.book - author = book.author - reader = book.reader hide_offline_books = self._application_settings.hide_offline book_is_online = self._fs_monitor.get_book_online(book) - if hide_offline_books and not book_is_online and not book.downloaded: - return False - - if self.library_view_mode == LibraryViewMode.CURRENT: - return True if book.last_played > 0 else False - if self.selected_filter == _("All"): return True + elif hide_offline_books and not book_is_online and not book.downloaded: + return False + elif self.library_view_mode == LibraryViewMode.CURRENT: + return book.last_played > 0 elif self.library_view_mode == LibraryViewMode.AUTHOR: - return True if self.selected_filter in author else False + return self.selected_filter in book.author elif self.library_view_mode == LibraryViewMode.READER: - return True if self.selected_filter in reader else False + return self.selected_filter in book.reader def display_book_sort(self, book_element1, book_element2): if self._library_view_mode == LibraryViewMode.CURRENT: @@ -164,7 +155,10 @@ def open_library(self): self._notify("library_view_mode") def book_files_exist(self, book: Book) -> bool: - return any(os.path.exists(chapter.file) for chapter in book.chapters) + for chapter in book.chapters: + if os.path.isfile(chapter.file): + return True + return False def _on_fs_monitor_event(self, event, _): if event == "storage-online": @@ -175,10 +169,6 @@ def _on_fs_monitor_event(self, event, _): self._notify("authors") self._notify("readers") self._notify("books-filter") - elif event == "external-storage-added": - pass - elif event == "external-storage-removed": - pass def _on_application_setting_changed(self, event, _): if event == "hide-offline": @@ -200,17 +190,14 @@ def _on_importer_event(self, event, message): self._notify("books") self._notify("books-filter") self._notify("library_view_mode") - if event == "import-failed": + elif event == "import-failed": ImportFailedDialog(message).show() def _on_player_event(self, event, message): - if event == "play": - book = message - - if book: - self._notify("current_book_in_playback") - self._notify("playing") - self._notify("books-filter") + if event == "play" and message: + self._notify("current_book_in_playback") + self._notify("playing") + self._notify("books-filter") elif event == "pause": self._notify("playing") elif event == "chapter-changed": @@ -219,7 +206,7 @@ def _on_player_event(self, event, message): elif event == "stop": self._notify("playing") self._notify("current_book_in_playback") - elif event == "position" or event == "book-finished": + elif event in {"position", "book-finished"}: self._notify("book-progress") def _on_settings_event(self, event: str, message): @@ -252,11 +239,12 @@ def delete_book_files(self, book: Book): for chapter in book.chapters: try: os.remove(chapter.file) - log.info("Deleted file: {}".format(chapter.file)) except Exception as e: - log.error("Failed to delete file: {}".format(chapter.file)) + log.error("Failed to delete file: %s", chapter.file) log.debug(e) reporter.warning("library_view_model", "Failed to delete a file.") + else: + log.info("Deleted file: %s", chapter.file) def play_book(self, book: Book): self._player.play_pause_book(book) diff --git a/cozy/view_model/playback_control_view_model.py b/cozy/view_model/playback_control_view_model.py index 3214b9bf..4f24f9b6 100644 --- a/cozy/view_model/playback_control_view_model.py +++ b/cozy/view_model/playback_control_view_model.py @@ -94,7 +94,7 @@ def open_book_detail(self): self.emit_event(OpenView.BOOK, self.book) def _on_player_event(self, event, message): - if event == "play" or event == "pause": + if event in {"play", "pause"}: if self.book: self._notify("playing") elif event == "position": diff --git a/cozy/view_model/playback_speed_view_model.py b/cozy/view_model/playback_speed_view_model.py index be8fb31d..0de22a83 100644 --- a/cozy/view_model/playback_speed_view_model.py +++ b/cozy/view_model/playback_speed_view_model.py @@ -20,8 +20,8 @@ def __init__(self): def playback_speed(self) -> float: if self._book: return self._book.playback_speed - else: - return 1.0 + + return 1.0 @playback_speed.setter def playback_speed(self, new_value: float): diff --git a/cozy/view_model/settings_view_model.py b/cozy/view_model/settings_view_model.py index 28251f8a..716aa524 100644 --- a/cozy/view_model/settings_view_model.py +++ b/cozy/view_model/settings_view_model.py @@ -62,7 +62,7 @@ def add_storage_location(self): def remove_storage_location(self, model: Storage): if model.default: - log.error("deleting the default storage location {} is not possible".format(model.path)) + log.error("deleting the default storage location %s is not possible", model.path) reporter.error("settings_view_model", "deleting the default storage location is not possible") return diff --git a/cozy/view_model/sleep_timer_view_model.py b/cozy/view_model/sleep_timer_view_model.py index 99d8b388..296ef8c1 100644 --- a/cozy/view_model/sleep_timer_view_model.py +++ b/cozy/view_model/sleep_timer_view_model.py @@ -76,13 +76,7 @@ def destroy(self): self._stop_timer() def _start_timer(self): - if self._sleep_timer: - return - - if self.remaining_seconds < 1: - return - - if not self._player.playing: + if self._sleep_timer or self.remaining_seconds < 1 or not self._player.playing: return log.info("Start Timer") @@ -114,12 +108,10 @@ def _on_timer_tick(self): self._notify_main_thread("remaining_seconds") def _get_fadeout(self) -> int: - fadeout = 0 - if self._app_settings.sleep_timer_fadeout: - fadeout = self._app_settings.sleep_timer_fadeout_duration + return self._app_settings.sleep_timer_fadeout_duration - return fadeout + return 0 def _stop_playback(self): fadeout = self._get_fadeout() @@ -150,7 +142,7 @@ def _on_player_changed(self, event, _): self._notify("stop_after_chapter") elif event == "play": self._start_timer() - elif event == "pause" or event == "stop": + elif event in {"pause", "stop"}: self._stop_timer() elif event == "fadeout-finished" and self._wait_for_fadeout_end: self._wait_for_fadeout_end = False