Skip to content

Instantly share code, notes, and snippets.

@Bluscream
Last active April 6, 2019 07:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bluscream/dfb0c554b61c191a4f66 to your computer and use it in GitHub Desktop.
Save Bluscream/dfb0c554b61c191a4f66 to your computer and use it in GitHub Desktop.
VLC Intro/Credits Skipper
--[[
INSTALLATION:
Put the .lua file in the VLC subdir /lua/extensions, by default:
* Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\
* Windows (current user): %APPDATA%\VLC\lua\extensions\
* Linux (all users): /usr/lib/vlc/lua/extensions/
* Linux (current user): ~/.local/share/vlc/lua/extensions/
(create directories if they don't exist)
Restart VLC.
USAGE:
Then you simply use the extension by going to the "View" menu and selecting it there.
--]]
skip_begin = 0
skip_end = 0
ignore_first = true
is_first = true
mypl = nil
predefined={
{"--Series--",0,0,false},
-- Edit below this line
{"Game of Thrones",203,78,false},
{"Dexter",106,45,false},
{"House of Cards",54,114,true},
--{"Example Series",Intro in Seconds,Credits in Seconds,ignore first episode in playlist}
-- Edit above this line
{"-YouTube-",0,0,false},
-- Edit below this line
{"Gronkh",0,0,true},
{"PietSmiet",3,0,true},
--{"Example Youtube format",Intro in Seconds,Credits in Seconds,ignore first episode in playlist}
-- Edit above this line
}
function descriptor()
return {
title = "Skip Intro/Credits";
version = "1.0";
author = "Bergur Hallgrimsson, Bluscream";
url = 'http://addons.videolan.org/content/show.php?content=159976';
shortdesc = "Skip intro";
description = "Define the length of intro and credits for your favourite episode. Queue them up in the playlist and jump right into the episode and avoid having to see the intro and credits.";
capabilities = {"input-listener"}
}
end
function activate()
create_dialog()
local input = vlc.object.input()
mypl = vlc.playlist.get("playlist", false).children
if input then
vlc.var.add_callback(input, "intf-event", input_event_handler, "Hello world!")
end
end
function deactivate()
local input = vlc.object.input()
vlc.var.del_callback(input, "intf-event", input_event_handler, "Hello world!")
end
function close()
vlc.deactivate()
end
function meta_changed()
end
function input_changed()
local input = vlc.object.input()
mypl = vlc.playlist.get("playlist", false).children
if input then
if skip() then
vlc.var.set(input, "time", skip_begin)
end
vlc.var.add_callback(input, "intf-event", input_event_handler, "Hello world!")
end
end
function input_event_handler(var, old, new, data)
local input = vlc.object.input()
duration = vlc.input.item():duration()
elapsed_time = vlc.var.get(input, "time")
timetoskip = duration-skip_end
if elapsed_time > timetoskip and #mypl > 1 then
vlc.playlist.next()
elseif (elapsed_time > timetoskip) then
vlc.playlist.stop()
end
end
function create_dialog()
d = vlc.dialog("Skipper")
w1 = d:add_label("Skip intro [s]:",1,3,1,1)
w2 = d:add_text_input(skip_begin,2,3,1,1)
w3 = d:add_label("Skip credits [s]:",1,4,1,1)
w4 = d:add_text_input(skip_end,2,4,1,1)
w5 = d:add_button("Save and close", click_Save,1,6,2,1)
w6 = d:add_label("Predefined episodes:",1,1,2,1)
w7 = d:add_dropdown(1,2,1,1)
for i,predefined in pairs(predefined) do
w7:add_value(predefined[1], i)
end
w8 = d:add_button("Apply", click_Apply,2,2,1,1)
w9 = d:add_check_box("Ignore first episode",ignore_first,1,5,2,1)
end
function click_Save()
skip_begin = tonumber(w2:get_text())
skip_end = tonumber(w4:get_text())
ignore_first = w9:get_checked()
local input = vlc.object.input()
if input then
if skip() then
vlc.var.set(input, "time", skip_begin)
end
end
d:delete()
end
function click_Apply()
local predefined = predefined[w7:get_value()]
w2:set_text(predefined[2])
w4:set_text(predefined[3])
w9:set_checked(predefined[4])
d:update()
end
function skip()
if mypl then
first_id = mypl[1]['id']
current_id = (vlc.playlist.current() == -1) and first_id or (vlc.playlist.current()-1)
is_first = (first_id == current_id)
str_isFirst = is_first and "true" or "false"
str_ignore_first = ignore_first and "true" or "false"
end
return not (ignore_first and is_first)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment