-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_editor.py
More file actions
59 lines (54 loc) · 2.44 KB
/
open_editor.py
File metadata and controls
59 lines (54 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Script entry point to open the segment editor.
Can be called from keymap.xml or other addons.
Always uses trigger file method to signal the background service.
"""
import xbmc
import xbmcgui
import xbmcaddon
import xbmcvfs
import sys
import os
# Get addon by ID explicitly
try:
addon = xbmcaddon.Addon('service.segmenteditor')
except:
# Fallback - try to get current addon
try:
addon = xbmcaddon.Addon()
except:
xbmc.log("[service.segmenteditor] ❌ CRITICAL: Could not get addon object!", xbmc.LOGERROR)
xbmcgui.Dialog().ok("Segment Editor", "Error: Could not initialize addon.")
sys.exit(1)
addon_path = addon.getAddonInfo('path')
# Log for debugging
xbmc.log(f"[service.segmenteditor] 🔔 open_editor.py entry point triggered from: {addon_path}", xbmc.LOGINFO)
# Always use trigger file method to signal the background service
# This prevents multiple service instances from interfering
try:
trigger_file = os.path.join(addon_path, "trigger_editor.txt")
# Create trigger file using xbmcvfs for cross-platform compatibility
try:
f = xbmcvfs.File(trigger_file, 'w')
if f:
f.write('trigger')
f.close()
xbmc.log(f"[service.segmenteditor] ✅ Trigger file created: {trigger_file}", xbmc.LOGINFO)
else:
xbmc.log(f"[service.segmenteditor] ❌ Failed to create trigger file", xbmc.LOGERROR)
xbmcgui.Dialog().ok("Segment Editor", "Failed to create trigger file. Check Kodi logs.")
except Exception as vfs_err:
# Fallback to standard Python file operations
xbmc.log(f"[service.segmenteditor] ⚠️ xbmcvfs failed: {vfs_err}, trying fallback", xbmc.LOGWARNING)
try:
with open(trigger_file, 'w') as f:
f.write('trigger')
xbmc.log(f"[service.segmenteditor] ✅ Trigger file created (fallback): {trigger_file}", xbmc.LOGINFO)
except Exception as fallback_err:
xbmc.log(f"[service.segmenteditor] ❌ Fallback also failed: {fallback_err}", xbmc.LOGERROR)
xbmcgui.Dialog().ok("Segment Editor", f"Error creating trigger file: {str(fallback_err)}")
except Exception as e:
import traceback
error_msg = f"Error in open_editor.py: {e}\n{traceback.format_exc()}"
xbmc.log(f"[service.segmenteditor] ❌ {error_msg}", xbmc.LOGERROR)
xbmcgui.Dialog().ok("Segment Editor", f"Error: {str(e)}")