-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubsync_addon.lua
More file actions
116 lines (94 loc) · 3.45 KB
/
Copy pathsubsync_addon.lua
File metadata and controls
116 lines (94 loc) · 3.45 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function descriptor()
return {
title = "Auto-Sync Subtitle",
version = "1.0",
author = "Antigravity",
url = "",
shortdesc = "Syncs subtitle using ffsubsync",
description = "Uses ffsubsync to align subtitles with speech in the video",
capabilities = {"menu", "input-listener"}
}
end
function activate()
create_dialog()
end
function deactivate()
-- cleanup if needed
end
function close()
vlc.deactivate()
end
local dialog = nil
local subtitle_input = nil
local engine_dropdown = nil
local ffs_input = nil
local status_label = nil
local video_path = ""
function create_dialog()
dialog = vlc.dialog("Subtitle Auto-Sync")
local item = vlc.input.item()
if item then
video_path = item:uri()
video_path = vlc.strings.decode_uri(video_path)
-- Remove file:/// prefix for Windows
video_path = string.gsub(video_path, "^file:///", "")
-- Replace forward slashes with backslashes
video_path = string.gsub(video_path, "/", "\\")
else
video_path = "No video playing."
end
dialog:add_label("Video Path:", 1, 1, 1, 1)
dialog:add_label(video_path, 2, 1, 1, 1)
dialog:add_label("Subtitle Path (.srt):", 1, 2, 1, 1)
subtitle_input = dialog:add_text_input("", 2, 2, 1, 1)
dialog:add_label("Engine:", 1, 3, 1, 1)
engine_dropdown = dialog:add_dropdown(2, 3, 1, 1)
engine_dropdown:add_value("ffsubsync (Standard)", 1)
engine_dropdown:add_value("alass (Best for Extended Cuts)", 2)
dialog:add_label("Path to Executable:", 1, 4, 1, 1)
ffs_input = dialog:add_text_input("C:\\ffsubsync\\ffsubsync.exe", 2, 4, 1, 1)
dialog:add_button("Sync Subtitle", click_sync, 1, 5, 2, 1)
status_label = dialog:add_label("Ready", 1, 6, 2, 1)
end
function click_sync()
if video_path == "No video playing." then
status_label:set_text("Error: Please play a video first.")
return
end
local sub_path = subtitle_input:get_text()
if sub_path == "" then
status_label:set_text("Error: Please provide a subtitle file path.")
return
end
-- Optional: check if file exists, just basic check here
status_label:set_text("Syncing... Please wait (this might take a few minutes)")
vlc.msg.info("Starting sync for: " .. sub_path)
local ffs_exe = ffs_input:get_text()
if ffs_exe == "" then
status_label:set_text("Error: Please provide executable path.")
return
end
local out_path = string.gsub(sub_path, "%.srt$", ".synced.srt")
local engine_id = engine_dropdown:get_value()
local cmd = ""
if engine_id == 1 then
-- ffsubsync
cmd = string.format('"%s" "%s" -i "%s" -o "%s"', ffs_exe, video_path, sub_path, out_path)
else
-- alass
cmd = string.format('"%s" "%s" "%s" "%s"', ffs_exe, video_path, sub_path, out_path)
end
vlc.msg.info("Executing: " .. cmd)
local handle = io.popen(cmd)
if handle then
local output = handle:read("*a")
vlc.msg.info("ffsubsync output: " .. (output or ""))
handle:close()
status_label:set_text("Synced successfully! Loading...")
local uri_out_path = "file:///" .. string.gsub(out_path, "\\", "/")
vlc.input.add_subtitle(uri_out_path)
status_label:set_text("Synced and loaded!")
else
status_label:set_text("Sync failed. Execution error.")
end
end