"""
self._kill_queue.put(True)
- self._mpv.command('playlist-play-index', self._idx)
+ self._play_at_index()
def _kill_mpv(self) -> None:
if self._mpv:
self._mpv = None
self._signal_update()
+ def _play_at_index(self):
+ if self._mpv:
+ self._mpv.command('playlist-play-index', self._idx)
+
@property
def empty(self) -> bool:
"""Return if playlist empty."""
"""Move player to previous item in playlist."""
if self._idx > 0:
self._idx -= 1
- if self._mpv:
- self._mpv.command('playlist-play-index', self._idx)
+ self._play_at_index()
def next(self) -> None:
"""Move player to next item in playlist."""
if self._idx < len(self._files) - 1:
self._idx += 1
- if self._mpv:
- self._mpv.command('playlist-play-index', self._idx)
+ self._play_at_index()
def jump_to(self, target_idx: int) -> None:
"""Move player to target_idx position in playlist."""
self._idx = target_idx
- if self._mpv:
- self._mpv.command('playlist-play-index', self._idx)
+ self._play_at_index()
def move_entry(self, start_idx: int, upwards=True) -> None:
"""Move playlist entry at start_idx up or down one step."""
self._start_mpv()
self._signal_update()
+ def inject_and_play(self, file: VideoFile) -> None:
+ """Inject file after current title, then jump to it."""
+ if self._files:
+ self._idx += 1
+ self._files.insert(self._idx, file)
+ if self._mpv:
+ self._mpv.command('loadfile', file.full_path,
+ 'insert-at', self._idx)
+ self._play_at_index()
+
class DownloadsManager:
"""Manages downloading and downloads access."""
postvars = parse_qs(self.rfile.read(body_length).decode())
if PAGE_NAMES['playlist'] == page_name:
self._receive_player_command(list(postvars.keys())[0])
+ if PAGE_NAMES['files'] == page_name:
+ self._receive_files_command(list(postvars.keys())[0])
elif PAGE_NAMES['file'] == page_name:
self._receive_video_flag(B64Str(toks_url[2]),
[FlagName(k) for k in postvars])
sleep(0.5) # avoid redir happening before current_file update
self._redirect(Path('/'))
+ def _receive_files_command(self, command: str) -> None:
+ if command.startswith('play_'):
+ conn = DbConnection()
+ file = VideoFile.get_by_b64(conn, B64Str(command.split('_', 1)[1]))
+ conn.commit_close()
+ self.server.player.inject_and_play(file)
+ self._redirect(Path('/'))
+
def _receive_video_flag(self,
rel_path_b64: B64Str,
flag_names: list[FlagName]