diff --git a/lazy_player/__init__.py b/lazy_player/__init__.py index dc21a23..53ba543 100644 --- a/lazy_player/__init__.py +++ b/lazy_player/__init__.py @@ -304,7 +304,7 @@ class MainWindow(Gtk.ApplicationWindow): success, duration = self.pipeline.query_duration(Gst.Format.TIME) if success: self.pipeline.seek_simple( - Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, duration - 1 + Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, duration ) return True @@ -314,6 +314,22 @@ class MainWindow(Gtk.ApplicationWindow): return False + def _toggle_watched_status(self) -> None: + """Toggle watched status for the selected file""" + file_item = self.selection + if file_item.file_type == FileType.DIRECTORY: + return + + position = file_item.load_attribute("position", 0) + duration = file_item.load_attribute("duration", 1) + + # If position exists and is >= 90% through, clear it + if position > 0 and (position / duration) >= 0.9: + file_item.save_attribute("position", None) + else: + # Otherwise mark as complete + file_item.save_attribute("position", duration) + def _on_menu_key_pressed( self, keyval: int, @@ -324,6 +340,10 @@ class MainWindow(Gtk.ApplicationWindow): self.close() return True + elif keyval == Gdk.keyval_from_name("w"): + self._toggle_watched_status() + return True + return False def _on_key_pressed( diff --git a/lazy_player/file_model.py b/lazy_player/file_model.py index 00b4bb1..62c021c 100644 --- a/lazy_player/file_model.py +++ b/lazy_player/file_model.py @@ -1,7 +1,6 @@ from __future__ import annotations import os -import sys from enum import Enum, auto from typing import overload @@ -52,8 +51,7 @@ class FileItem(GObject.Object): try: strval = os.getxattr(self.full_path, f"user.lazy_player.{name}") return type(dfl)(strval) - except OSError as err: - print(err, file=sys.stderr) + except OSError: return dfl def save_attribute(self, name: str, value: str | float | int | None) -> None: @@ -62,5 +60,5 @@ class FileItem(GObject.Object): os.removexattr(self.full_path, f"user.lazy_player.{name}") else: os.setxattr(self.full_path, f"user.lazy_player.{name}", str(value).encode("utf8")) - except OSError as err: - print(err, file=sys.stderr) + except OSError: + pass