no logging

This commit is contained in:
nose
2025-11-26 00:02:33 -08:00
parent d1f08216a2
commit 935ce303d0
5 changed files with 201 additions and 232 deletions

View File

@@ -7,7 +7,7 @@ import subprocess as _subprocess
import json
import sys
from helper.logger import log
from helper.logger import log, debug
import uuid as _uuid
import time as _time
@@ -312,10 +312,10 @@ def _send_to_mpv_pipe(file_url: str, ipc_pipe: str, title: str, headers: Optiona
if response_line:
resp = json.loads(response_line.decode('utf-8'))
if resp.get('error') != 'success':
log(f"[get-file] MPV error: {resp.get('error')}", file=sys.stderr)
debug(f"[get-file] MPV error: {resp.get('error')}", file=sys.stderr)
return False
log(f"[get-file] Sent to existing MPV: {title}", file=sys.stderr)
debug(f"[get-file] Sent to existing MPV: {title}", file=sys.stderr)
return True
except (OSError, IOError):
# Pipe not available
@@ -341,20 +341,20 @@ def _send_to_mpv_pipe(file_url: str, ipc_pipe: str, title: str, headers: Optiona
if response_data:
resp = json.loads(response_data.decode('utf-8'))
if resp.get('error') != 'success':
log(f"[get-file] MPV error: {resp.get('error')}", file=sys.stderr)
debug(f"[get-file] MPV error: {resp.get('error')}", file=sys.stderr)
sock.close()
return False
except:
pass
sock.close()
log(f"[get-file] Sent to existing MPV: {title}", file=sys.stderr)
debug(f"[get-file] Sent to existing MPV: {title}", file=sys.stderr)
return True
except (OSError, socket.error, ConnectionRefusedError):
# Pipe doesn't exist or MPV not listening - will need to start new instance
return False
except Exception as e:
log(f"[get-file] IPC error: {e}", file=sys.stderr)
debug(f"[get-file] IPC error: {e}", file=sys.stderr)
return False
@@ -371,11 +371,11 @@ def _play_in_mpv(file_url: str, file_title: str, is_stream: bool = False, header
try:
# First try to send to existing MPV instance
if _send_to_mpv_pipe(file_url, ipc_pipe, file_title, headers):
print(f"Added to MPV: {file_title}")
debug(f"Added to MPV: {file_title}")
return True
# No existing MPV or pipe unavailable - start new instance
log(f"[get-file] Starting new MPV instance (pipe: {ipc_pipe})", file=sys.stderr)
debug(f"[get-file] Starting new MPV instance (pipe: {ipc_pipe})", file=sys.stderr)
cmd = ['mpv', file_url, f'--input-ipc-server={ipc_pipe}']
# Set title for new instance
@@ -397,8 +397,8 @@ def _play_in_mpv(file_url: str, file_title: str, is_stream: bool = False, header
_subprocess.Popen(cmd, stdin=_subprocess.DEVNULL, stdout=_subprocess.DEVNULL, stderr=_subprocess.DEVNULL, **kwargs)
print(f"{'Streaming' if is_stream else 'Playing'} in MPV: {file_title}")
log(f"[get-file] Started MPV with {file_title} (IPC: {ipc_pipe})", file=sys.stderr)
debug(f"{'Streaming' if is_stream else 'Playing'} in MPV: {file_title}")
debug(f"[get-file] Started MPV with {file_title} (IPC: {ipc_pipe})", file=sys.stderr)
return True
except FileNotFoundError:
@@ -447,7 +447,7 @@ def _handle_search_result(result: Any, args: Sequence[str], config: Dict[str, An
log("Error: No storage backend specified in result", file=sys.stderr)
return 1
log(f"[get-file] Retrieving file from storage: {storage_name}", file=sys.stderr)
debug(f"[get-file] Retrieving file from storage: {storage_name}", file=sys.stderr)
# Handle different storage backends
if storage_name.lower() == 'hydrus':
@@ -536,38 +536,24 @@ def _handle_hydrus_file(file_hash: Optional[str], file_title: str, config: Dict[
try:
import webbrowser
webbrowser.open(web_url)
log(f"[get-file] Opened in browser: {file_title}", file=sys.stderr)
debug(f"[get-file] Opened in browser: {file_title}", file=sys.stderr)
except Exception:
pass
return 0
elif force_mpv or (is_media and mpv_available):
# Auto-play in MPV for media files (if available), or user requested it
if _play_in_mpv(stream_url, file_title, is_stream=True, headers=headers):
# Emit result as PipeObject-compatible dict for pipelining
ipc_pipe = _get_fixed_ipc_pipe()
result_dict = create_pipe_object_result(
source='hydrus',
identifier=file_hash,
file_path=stream_url,
cmdlet_name='get-file',
title=file_title,
file_hash=file_hash,
extra={
'ipc': ipc_pipe,
'action_type': 'streaming',
'web_url': web_url,
'hydrus_url': hydrus_url,
'access_key': access_key
}
)
ctx.emit(result_dict)
# Show pipe menu instead of emitting result for display
# This allows immediate @N selection from the playlist
from . import pipe
pipe._run(None, [], config)
return 0
else:
# Fall back to browser
try:
import webbrowser
webbrowser.open(web_url)
log(f"[get-file] Opened in browser instead", file=sys.stderr)
debug(f"[get-file] Opened in browser instead", file=sys.stderr)
except Exception:
pass
return 0
@@ -593,7 +579,7 @@ def _handle_hydrus_file(file_hash: Optional[str], file_title: str, config: Dict[
try:
import webbrowser
webbrowser.open(web_url)
log(f"[get-file] Opened in browser: {file_title}", file=sys.stderr)
debug(f"[get-file] Opened in browser: {file_title}", file=sys.stderr)
except Exception:
pass
return 0
@@ -641,7 +627,7 @@ def _handle_local_file(file_path: Optional[str], file_title: str, args: Sequence
else: # Linux
sp.run(['xdg-open', file_path])
ctx.emit(f"Opened: {file_title}")
log(f"[get-file] Opened {file_title} with default app", file=sys.stderr)
debug(f"[get-file] Opened {file_title} with default app", file=sys.stderr)
return 0
except Exception as e:
log(f"Error opening file: {e}", file=sys.stderr)
@@ -649,21 +635,10 @@ def _handle_local_file(file_path: Optional[str], file_title: str, args: Sequence
elif force_mpv or (is_media and mpv_available):
# Auto-play in MPV for media files (if available), or user requested it
if _play_in_mpv(file_path, file_title, is_stream=False):
# Emit result as PipeObject-compatible dict for pipelining
ipc_pipe = _get_fixed_ipc_pipe()
result_dict = create_pipe_object_result(
source='local',
identifier=str(Path(file_path).stem) if file_path else 'unknown',
file_path=file_path,
cmdlet_name='get-file',
title=file_title,
file_hash=file_hash, # Include hash from search result if available
extra={
'ipc': ipc_pipe, # MPV IPC pipe for Lua script control
'action_type': 'playing' # Distinguish from other get-file actions
}
)
ctx.emit(result_dict)
# Show pipe menu instead of emitting result for display
# This allows immediate @N selection from the playlist
from . import pipe
pipe._run(None, [], config)
return 0
else:
# Fall back to default application
@@ -676,7 +651,7 @@ def _handle_local_file(file_path: Optional[str], file_title: str, args: Sequence
os.startfile(file_path)
else: # Linux
_subprocess.run(['xdg-open', file_path])
log(f"[get-file] Opened with default app instead", file=sys.stderr)
debug(f"[get-file] Opened with default app instead", file=sys.stderr)
except Exception:
pass
return 0
@@ -694,7 +669,7 @@ def _handle_local_file(file_path: Optional[str], file_title: str, args: Sequence
else: # Linux
sp.run(['xdg-open', file_path])
print(f"Opened: {file_title}")
log(f"[get-file] Opened {file_title} with default app", file=sys.stderr)
debug(f"[get-file] Opened {file_title} with default app", file=sys.stderr)
# Emit result for downstream processing
result_dict = create_pipe_object_result(
@@ -751,7 +726,7 @@ def _handle_debrid_file(magnet_id: int, magnet_title: str, config: Dict[str, Any
try:
client = AllDebridClient(api_key)
log(f"[get-file] Downloading magnet {magnet_id}: {magnet_title}", file=sys.stderr)
debug(f"[get-file] Downloading magnet {magnet_id}: {magnet_title}", file=sys.stderr)
# Fetch magnet files
try: