From 8af6e6b1b45835c20cb3040855b753664c882d8f Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Tue, 17 Dec 2024 01:29:34 +0100
Subject: [PATCH] Restart playlist after ending of last file.

---
 src/ytplom/misc.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py
index 3a0be6d..81406d0 100644
--- a/src/ytplom/misc.py
+++ b/src/ytplom/misc.py
@@ -568,6 +568,7 @@ class Player:
         - build MPV's internal playlist from .playlist
         - bind starting of files to ._signal_update and setting ._idx to MPV's
           own playlist position index
+        - bind ending last file to re-starting at playlist start
         - start playing
         """
         self._mpv = MPV(input_default_bindings=True,
@@ -582,6 +583,13 @@ class Player:
             self._idx = self._mpv.playlist_pos
             self._signal_update()
 
+        @self._mpv.event_callback('end-file')
+        def on_end_file(event) -> None:
+            if (b'eof' == event.as_dict()['reason']
+                    and self._idx + 1 == len(self.playlist)):
+                self._idx = 0
+                self._play_at_index()
+
         @self._mpv.event_callback('shutdown')
         def on_shutdown(_) -> None:
             self._kill_queue.put(True)
-- 
2.30.2