MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / comskip_process_recording

Function comskip_process_recording

apps/channels/tasks.py:2717–2985  ·  view source on GitHub ↗

Run comskip on the MKV to remove commercials and replace the file in place. Safe to call even if comskip is not installed; stores status in custom_properties.comskip.

(recording_id: int)

Source from the content-addressed store, hash-verified

2715
2716@shared_task
2717def comskip_process_recording(recording_id: int):
2718 """Run comskip on the MKV to remove commercials and replace the file in place.
2719 Safe to call even if comskip is not installed; stores status in custom_properties.comskip.
2720 """
2721 import shutil
2722 from django.db import DatabaseError
2723 from .models import Recording
2724 # Helper to broadcast status over websocket
2725 def _ws(status: str, extra: dict | None = None):
2726 try:
2727 from core.utils import send_websocket_update
2728 payload = {"success": True, "type": "comskip_status", "status": status, "recording_id": recording_id}
2729 if extra:
2730 payload.update(extra)
2731 send_websocket_update('updates', 'update', payload)
2732 except Exception:
2733 pass
2734
2735 try:
2736 rec = Recording.objects.get(id=recording_id)
2737 except Recording.DoesNotExist:
2738 return "not_found"
2739
2740 cp = rec.custom_properties.copy() if isinstance(rec.custom_properties, dict) else {}
2741
2742 def _persist_custom_properties():
2743 """Persist updated custom_properties without raising if the row disappeared."""
2744 try:
2745 updated = Recording.objects.filter(pk=recording_id).update(custom_properties=cp)
2746 if not updated:
2747 logger.warning(
2748 "Recording %s vanished before comskip status could be saved",
2749 recording_id,
2750 )
2751 return False
2752 except DatabaseError as db_err:
2753 logger.warning(
2754 "Failed to persist comskip status for recording %s: %s",
2755 recording_id,
2756 db_err,
2757 )
2758 return False
2759 except Exception as unexpected:
2760 logger.warning(
2761 "Unexpected error while saving comskip status for recording %s: %s",
2762 recording_id,
2763 unexpected,
2764 )
2765 return False
2766 return True
2767 file_path = (cp or {}).get("file_path")
2768 if not file_path or not os.path.exists(file_path):
2769 return "no_file"
2770
2771 if isinstance(cp.get("comskip"), dict) and cp["comskip"].get("status") == "completed":
2772 return "already_processed"
2773
2774 comskip_bin = shutil.which("comskip")

Callers

nothing calls this directly

Calls 10

_wsFunction · 0.85
_ffprobe_durationFunction · 0.85
get_dvr_comskip_modeMethod · 0.80
extendMethod · 0.80
runMethod · 0.80
getMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected