no logging
This commit is contained in:
@@ -6,7 +6,7 @@ import socket
|
||||
import re
|
||||
import subprocess
|
||||
from ._shared import Cmdlet, CmdletArg, parse_cmdlet_args
|
||||
from helper.logger import log
|
||||
from helper.logger import log, debug
|
||||
from result_table import ResultTable
|
||||
from .get_file import _get_fixed_ipc_pipe
|
||||
import pipeline as ctx
|
||||
@@ -33,13 +33,13 @@ def _send_ipc_command(command: Dict[str, Any]) -> Optional[Any]:
|
||||
except FileNotFoundError:
|
||||
return None # MPV not running
|
||||
except Exception as e:
|
||||
log(f"Windows IPC Error: {e}", file=sys.stderr)
|
||||
debug(f"Windows IPC Error: {e}", file=sys.stderr)
|
||||
return None
|
||||
else:
|
||||
# Unix socket
|
||||
af_unix = getattr(socket, 'AF_UNIX', None)
|
||||
if af_unix is None:
|
||||
log("Unix sockets not supported on this platform", file=sys.stderr)
|
||||
debug("Unix sockets not supported on this platform", file=sys.stderr)
|
||||
return None
|
||||
|
||||
try:
|
||||
@@ -77,11 +77,11 @@ def _send_ipc_command(command: Dict[str, Any]) -> Optional[Any]:
|
||||
except (FileNotFoundError, ConnectionRefusedError):
|
||||
return None # MPV not running
|
||||
except Exception as e:
|
||||
log(f"Unix IPC Error: {e}", file=sys.stderr)
|
||||
debug(f"Unix IPC Error: {e}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
log(f"IPC Error: {e}", file=sys.stderr)
|
||||
debug(f"IPC Error: {e}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
return None
|
||||
@@ -112,20 +112,20 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
cmd = {"command": ["set_property", "pause", False], "request_id": 103}
|
||||
resp = _send_ipc_command(cmd)
|
||||
if resp and resp.get("error") == "success":
|
||||
log("Resumed playback")
|
||||
debug("Resumed playback")
|
||||
return 0
|
||||
else:
|
||||
log("Failed to resume playback (MPV not running?)", file=sys.stderr)
|
||||
debug("Failed to resume playback (MPV not running?)", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if pause_mode:
|
||||
cmd = {"command": ["set_property", "pause", True], "request_id": 104}
|
||||
resp = _send_ipc_command(cmd)
|
||||
if resp and resp.get("error") == "success":
|
||||
log("Paused playback")
|
||||
debug("Paused playback")
|
||||
return 0
|
||||
else:
|
||||
log("Failed to pause playback (MPV not running?)", file=sys.stderr)
|
||||
debug("Failed to pause playback (MPV not running?)", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
# Handle piped input (add to playlist)
|
||||
@@ -178,12 +178,12 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
elif resp.get("error") == "success":
|
||||
added_count += 1
|
||||
if title:
|
||||
log(f"Queued: {title}")
|
||||
debug(f"Queued: {title}")
|
||||
else:
|
||||
log(f"Queued: {target}")
|
||||
debug(f"Queued: {target}")
|
||||
else:
|
||||
error_msg = str(resp.get('error'))
|
||||
log(f"Failed to queue item: {error_msg}", file=sys.stderr)
|
||||
debug(f"Failed to queue item: {error_msg}", file=sys.stderr)
|
||||
|
||||
# If error indicates parameter issues, try without options
|
||||
# (Though memory:// should avoid this, we keep fallback just in case)
|
||||
@@ -192,7 +192,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
resp = _send_ipc_command(cmd)
|
||||
if resp and resp.get("error") == "success":
|
||||
added_count += 1
|
||||
log(f"Queued (fallback): {title or target}")
|
||||
debug(f"Queued (fallback): {title or target}")
|
||||
|
||||
if added_count > 0:
|
||||
# If we added items, we might want to play the first one if nothing is playing?
|
||||
@@ -203,7 +203,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
items = _get_playlist()
|
||||
|
||||
if not items:
|
||||
log("MPV playlist is empty or MPV is not running.")
|
||||
debug("MPV playlist is empty or MPV is not running.")
|
||||
return 0
|
||||
|
||||
# If index is provided, perform action (Play or Clear)
|
||||
@@ -213,7 +213,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
idx = int(index_arg) - 1
|
||||
|
||||
if idx < 0 or idx >= len(items):
|
||||
log(f"Index {index_arg} out of range (1-{len(items)}).")
|
||||
debug(f"Index {index_arg} out of range (1-{len(items)}).")
|
||||
return 1
|
||||
|
||||
item = items[idx]
|
||||
@@ -224,13 +224,13 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
cmd = {"command": ["playlist-remove", idx], "request_id": 101}
|
||||
resp = _send_ipc_command(cmd)
|
||||
if resp and resp.get("error") == "success":
|
||||
log(f"Removed: {title}")
|
||||
debug(f"Removed: {title}")
|
||||
# Refresh items for listing
|
||||
items = _get_playlist()
|
||||
list_mode = True
|
||||
index_arg = None
|
||||
else:
|
||||
log(f"Failed to remove item: {resp.get('error') if resp else 'No response'}")
|
||||
debug(f"Failed to remove item: {resp.get('error') if resp else 'No response'}")
|
||||
return 1
|
||||
else:
|
||||
# Play item
|
||||
@@ -241,20 +241,20 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
unpause_cmd = {"command": ["set_property", "pause", False], "request_id": 103}
|
||||
_send_ipc_command(unpause_cmd)
|
||||
|
||||
log(f"Playing: {title}")
|
||||
debug(f"Playing: {title}")
|
||||
return 0
|
||||
else:
|
||||
log(f"Failed to play item: {resp.get('error') if resp else 'No response'}")
|
||||
debug(f"Failed to play item: {resp.get('error') if resp else 'No response'}")
|
||||
return 1
|
||||
|
||||
except ValueError:
|
||||
log(f"Invalid index: {index_arg}")
|
||||
debug(f"Invalid index: {index_arg}")
|
||||
return 1
|
||||
|
||||
# List items (Default action or after clear)
|
||||
if list_mode or index_arg is None:
|
||||
if not items:
|
||||
log("MPV playlist is empty.")
|
||||
debug("MPV playlist is empty.")
|
||||
return 0
|
||||
|
||||
table = ResultTable("MPV Playlist")
|
||||
@@ -347,9 +347,9 @@ def _start_mpv(items: List[Any]) -> None:
|
||||
kwargs['creationflags'] = 0x00000008 # DETACHED_PROCESS
|
||||
|
||||
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, **kwargs)
|
||||
log(f"Started MPV with {len(cmd)-3} items")
|
||||
debug(f"Started MPV with {len(cmd)-3} items")
|
||||
except Exception as e:
|
||||
log(f"Error starting MPV: {e}", file=sys.stderr)
|
||||
debug(f"Error starting MPV: {e}", file=sys.stderr)
|
||||
|
||||
CMDLET = Cmdlet(
|
||||
name=".pipe",
|
||||
|
||||
Reference in New Issue
Block a user