Commit 3e4a7850 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Update VLSub.lua

parent 53ac08c9
...@@ -21,27 +21,29 @@ ...@@ -21,27 +21,29 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]] --]]
-- Extension description
function descriptor() function descriptor()
return { title = "VLsub" ; return { title = "VLsub 0.9" ;
version = "0.8" ; version = "0.9" ;
author = "exebetche" ; author = "exebetche" ;
url = 'http://www.opensubtitles.org/'; url = 'http://www.opensubtitles.org/';
shortdesc = "VLsub"; shortdesc = "VLsub";
description = "<center><b>VLsub</b></center>" description = "<center><b>VLsub</b></center>"
.. "Download subtitles from OpenSubtitles.org" ; .. "Dowload subtitles from OpenSubtitles.org" ;
capabilities = { "input-listener", "meta-listener" } capabilities = { "input-listener", "meta-listener" }
} }
end end
require "os"
-- Global variables -- Global variables
dlg = nil -- Dialog dlg = nil -- Dialog
conflocation = 'subdownloader.conf' --~ conflocation = 'subdownloader.conf'
url = "http://api.opensubtitles.org/xml-rpc" url = "http://api.opensubtitles.org/xml-rpc"
progressBarSize = 40 progressBarSize = 70
interface_state = 0
result_state = {} --~ default_language = "fre"
default_language = "eng" default_language = nil
refresh_toggle = false
function set_default_language() function set_default_language()
if default_language then if default_language then
...@@ -57,10 +59,10 @@ end ...@@ -57,10 +59,10 @@ end
function activate() function activate()
vlc.msg.dbg("[VLsub] Welcome") vlc.msg.dbg("[VLsub] Welcome")
set_default_language() set_default_language()
create_dialog() create_dialog()
openSub.getFileInfo() openSub.request("LogIn")
openSub.getMovieInfo() update_fields()
--~ openSub.request("LogIn")
end end
function deactivate() function deactivate()
...@@ -75,19 +77,30 @@ function close() ...@@ -75,19 +77,30 @@ function close()
end end
function meta_changed() function meta_changed()
update_fields()
end
function input_changed()
--~ Crash !?
--~ wait(3)
--~ update_fields()
end
function update_fields()
openSub.getFileInfo() openSub.getFileInfo()
openSub.getMovieInfo() openSub.getMovieInfo()
if tmp_method_id == "hash" then
searchHash() if openSub.movie.name ~= nil then
elseif tmp_method_id == "imdb" then
widget.get("title").input:set_text(openSub.movie.name) widget.get("title").input:set_text(openSub.movie.name)
end
if openSub.movie.seasonNumber ~= nil then
widget.get("season").input:set_text(openSub.movie.seasonNumber) widget.get("season").input:set_text(openSub.movie.seasonNumber)
widget.get("episode").input:set_text(openSub.movie.episodeNumber)
end end
end
function input_changed() if openSub.movie.episodeNumber ~= nil then
return false widget.get("episode").input:set_text(openSub.movie.episodeNumber)
end
end end
openSub = { openSub = {
...@@ -96,12 +109,12 @@ openSub = { ...@@ -96,12 +109,12 @@ openSub = {
conf = { conf = {
url = "http://api.opensubtitles.org/xml-rpc", url = "http://api.opensubtitles.org/xml-rpc",
userAgentHTTP = "VLSub", userAgentHTTP = "VLSub",
useragent = "VLSub 0.8", useragent = "VLSub 0.9",
username = "", username = "",
password = "", password = "",
language = "", language = "",
downloadSub = true, downloadSub = true,
removeTag = true, removeTag = false,
justgetlink = false justgetlink = false
}, },
session = { session = {
...@@ -123,14 +136,7 @@ openSub = { ...@@ -123,14 +136,7 @@ openSub = {
movie = { movie = {
name = "", name = "",
season = "", season = "",
episode = "", episode = ""
imdbid = nil,
imdbidShow = nil,
imdbidEpisode = nil,
imdbRequest = nil,
year = nil,
releasename = nil,
aka = nil
}, },
sub = { sub = {
id = nil, id = nil,
...@@ -166,8 +172,8 @@ openSub = { ...@@ -166,8 +172,8 @@ openSub = {
if status == 200 then if status == 200 then
response = parse_xmlrpc(responseStr) response = parse_xmlrpc(responseStr)
--~ vlc.msg.dbg(responseStr)
if (response and response.status == "200 OK") then if (response and response.status == "200 OK") then
vlc.msg.dbg(responseStr)
return openSub.methods[methodName].callback(response) return openSub.methods[methodName].callback(response)
elseif response then elseif response then
setError("code "..response.status.."("..status..")") setError("code "..response.status.."("..status..")")
...@@ -272,32 +278,24 @@ openSub = { ...@@ -272,32 +278,24 @@ openSub = {
end end
end end
}, },
SearchMoviesOnIMDB = { SearchSubtitles = {
methodName = "SearchSubtitles",
params = function() params = function()
openSub.actionLabel = "Searching movie on IMDB" openSub.actionLabel = "Searching subtitles"
setMessage(openSub.actionLabel..": "..progressBarContent(0)) setMessage(openSub.actionLabel..": "..progressBarContent(0))
return { local member = {
{ value={ string=openSub.session.token } }, { name="sublanguageid", value={ string=openSub.sub.languageid } },
{ value={ string=openSub.movie.imdbRequest } } { name="query", value={ string=openSub.movie.name } } }
}
end,
callback = function(resp)
openSub.itemStore = resp.data
if openSub.itemStore ~= "0" then
return true if openSub.movie.season ~= nil then
else table.insert(member, { name="season", value={ string=openSub.movie.season } })
openSub.itemStore = nil
return false
end end
if openSub.movie.episode ~= nil then
table.insert(member, { name="episode", value={ string=openSub.movie.episode } })
end end
},
SearchSubtitlesByIdIMDB = {
methodName = "SearchSubtitles",
params = function()
openSub.actionLabel = "Searching subtitles"
setMessage(openSub.actionLabel..": "..progressBarContent(0))
return { return {
{ value={ string=openSub.session.token } }, { value={ string=openSub.session.token } },
...@@ -306,9 +304,8 @@ openSub = { ...@@ -306,9 +304,8 @@ openSub = {
data={ data={
value={ value={
struct={ struct={
member={ member=member
{ name="sublanguageid", value={ string=openSub.sub.languageid } }, }}}}}}
{ name="imdbid", value={ string=openSub.movie.imdbid } } }}}}}}}
} }
end, end,
callback = function(resp) callback = function(resp)
...@@ -321,29 +318,6 @@ openSub = { ...@@ -321,29 +318,6 @@ openSub = {
return false return false
end end
end end
},
GetIMDBMovieDetails = {
params = function()
return {
{ value={ string=openSub.session.token } },
{ value={ string=openSub.movie.imdbid } }
}
end,
callback = function(resp)
print(dump_xml(resp))
end
},
IsTVserie = {
methodName = "GetIMDBMovieDetails",
params = function()
return {
{ value={ string=openSub.session.token } },
{ value={ string=openSub.movie.imdbid } }
}
end,
callback = function(resp)
return (string.lower(resp.data.kind)=="tv series")
end
} }
}, },
getInputItem = function() getInputItem = function()
...@@ -351,10 +325,12 @@ openSub = { ...@@ -351,10 +325,12 @@ openSub = {
end, end,
getFileInfo = function() getFileInfo = function()
local item = openSub.getInputItem() local item = openSub.getInputItem()
local file = openSub.file
if not item then if not item then
file.hasInput = false;
file.cleanName = "";
return false return false
else else
local file = openSub.file
local parsed_uri = vlc.net.url_parse(item:uri()) local parsed_uri = vlc.net.url_parse(item:uri())
file.uri = item:uri() file.uri = item:uri()
file.protocol = parsed_uri["protocol"] file.protocol = parsed_uri["protocol"]
...@@ -370,11 +346,16 @@ openSub = { ...@@ -370,11 +346,16 @@ openSub = {
if file.ext == "part" then if file.ext == "part" then
file.name, file.ext = string.match(file.name, "^([^/]+)%.([^%.]+)$") file.name, file.ext = string.match(file.name, "^([^/]+)%.([^%.]+)$")
end end
file.hasInput = true;
file.cleanName = string.gsub(file.name, "[%._]", " ") file.cleanName = string.gsub(file.name, "[%._]", " ")
vlc.msg.dbg(file.cleanName)
end end
end, end,
getMovieInfo = function() getMovieInfo = function()
if not openSub.file.name then if not openSub.file.name then
openSub.movie.name = ""
openSub.movie.seasonNumber = ""
openSub.movie.episodeNumber = ""
return false return false
end end
...@@ -392,6 +373,8 @@ openSub = { ...@@ -392,6 +373,8 @@ openSub = {
openSub.movie.name = openSub.file.cleanName openSub.movie.name = openSub.file.cleanName
openSub.movie.seasonNumber = "" openSub.movie.seasonNumber = ""
openSub.movie.episodeNumber = "" openSub.movie.episodeNumber = ""
vlc.msg.dbg(openSub.movie.name)
end end
end, end,
getMovieHash = function() getMovieHash = function()
...@@ -423,141 +406,61 @@ openSub = { ...@@ -423,141 +406,61 @@ openSub = {
return false return false
end end
local i = 1 local lo,hi=0,0
local a = {0, 0, 0, 0, 0, 0, 0, 0} for i=1,8192 do
local hash = "" local a,b,c,d = file:read(4):byte(1,4)
lo = lo + a + b*256 + c*65536 + d*16777216
local size = file:seek("end") a,b,c,d = file:read(4):byte(1,4)
file:seek("set", 0) hi = hi + a + b*256 + c*65536 + d*16777216
local bytes = file:read(65536) while lo>=4294967296 do
file:seek("set", size-65536) lo = lo-4294967296
bytes = bytes..file:read("*all") hi = hi+1
file:close ()
for b in string.gfind(string.format("%16X ", size), "..") do
d = tonumber(b, 16)
if type(d) ~= "nil" then a[9-i] = d end
i=i+1
end end
while hi>=4294967296 do
i = 1 hi = hi-4294967296
for b in string.gfind(bytes, ".") do
a[i] = a[i] + string.byte(b)
d = math.floor(a[i]/255)
if d>=1 then
a[i] = a[i] - d * 256
if i<8 then a[i+1] = a[i+1] + d end
end end
i=i+1
if i==9 then i=1 end
end end
local size = file:seek("end", -65536) + 65536
for i=8, 1, -1 do for i=1,8192 do
hash = hash..string.format("%02x",a[i]) local a,b,c,d = file:read(4):byte(1,4)
lo = lo + a + b*256 + c*65536 + d*16777216
a,b,c,d = file:read(4):byte(1,4)
hi = hi + a + b*256 + c*65536 + d*16777216
while lo>=4294967296 do
lo = lo-4294967296
hi = hi+1
end end
while hi>=4294967296 do
openSub.file.bytesize = size hi = hi-4294967296
openSub.file.hash = hash
return true
end,
getImdbEpisodeId = function(season, episode)
openSub.actionLabel = "Searching episode id on IMDB"
setMessage(openSub.actionLabel..": "..progressBarContent(0))
local IMDBurl = "http://www.imdb.com/title/tt"..openSub.movie.imdbid.."/episodes/_ajax?season="..season
local host, path = parse_url(IMDBurl)
local stream = vlc.stream(IMDBurl)
local data = ""
while data do
data = stream:read(65536)
local id = string.match(data, 'data%-const="tt(%d+)"[^>]+>\r?\n<img[^>]+>\r?\n<div> S'..season..', Ep'..episode)
return id
end end
return false
end,
getImdbEpisodeIdYQL = function(season, episode)
openSub.actionLabel = "Searching episode on IMDB"
setMessage(openSub.actionLabel..": "..progressBarContent(0))
local url = "http://pipes.yahoo.com/pipes/pipe.run?_id=5f525406f2b2b376eeb20b97a216bcb1&_render=json&imdbid="..openSub.movie.imdbid.."&season="..season.."&episode="..episode
local host, path = parse_url(url)
local header = {
"GET "..path.." HTTP/1.1",
"Host: "..host,
"User-Agent: "..openSub.conf.userAgentHTTP,
"",
""
}
local request = table.concat(header, "\r\n")
local fd = vlc.net.connect_tcp(host, 80)
local data = ""
if fd >= 0 then
local pollfds = {}
pollfds[fd] = vlc.net.POLLIN
vlc.net.send(fd, request)
vlc.net.poll(pollfds)
data = vlc.net.recv(fd, 2048)
print(data)
end end
lo = lo + size
setMessage(openSub.actionLabel..": "..progressBarContent(100)) while lo>=4294967296 do
lo = lo-4294967296
local id = string.match(data, '"content":"(%d+)"') hi = hi+1
return id end
end, while hi>=4294967296 do
getImdbEpisodeIdGoogle = function(season, episode, title) hi = hi-4294967296
openSub.actionLabel = "Searching episode on IMDB"
setMessage(openSub.actionLabel..": "..progressBarContent(0))
local query = 'site:imdb.com tv episode "'..title..'" (#'..season..'.'..episode..')'
local url = "https://www.google.com/uds/GwebSearch?hl=fr&source=gsc&gss=.com&gl=www.google.com&context=1&key=notsupplied&v=1.0&&q="..vlc.strings.encode_uri_component(query)
local host, path = parse_url(url)
local header = {
"GET "..path.." HTTP/1.1",
"Host: "..host,
"User-Agent: "..openSub.conf.userAgentHTTP,
"",
""
}
local request = table.concat(header, "\r\n")
local fd = vlc.net.connect_tcp(host, 80)
local data = ""
if fd >= 0 then
local pollfds = {}
pollfds[fd] = vlc.net.POLLIN
vlc.net.send(fd, request)
vlc.net.poll(pollfds)
data = vlc.net.recv(fd, 2048)
--print(data)
end end
setMessage(openSub.actionLabel..": "..progressBarContent(100)) openSub.file.bytesize = size
openSub.file.hash = string.format("%08x%08x", hi,lo)
local id = string.match(data, '"url":"http://www.imdb.com/title/tt(%d+)/"') return true
return id
end, end,
loadSubtitles = function(url, fileDir, SubFileName, target) loadSubtitles = function(url, SubFileName, target)
openSub.actionLabel = "Downloading subtitle" openSub.actionLabel = "Downloading subtitle"
setMessage(openSub.actionLabel..": "..progressBarContent(0)) setMessage(openSub.actionLabel..": "..progressBarContent(0))
local subfileURI = nil
local resp = get(url) local resp = get(url)
local subfileURI = ""
if resp then if resp then
local tmpFileName = fileDir..SubFileName..".zip" local tmpFileName = openSub.file.dir..SubFileName..".zip"
subfileURI = "zip://"..make_uri(tmpFileName, true).."!/"..SubFileName
local tmpFile = assert(io.open(tmpFileName, "wb")) local tmpFile = assert(io.open(tmpFileName, "wb"))
tmpFile:write(resp) tmpFile:write(resp)
tmpFile:flush()
tmpFile:close() tmpFile:close()
subfileURI = "zip://"..make_uri(tmpFileName, true).."!/"..SubFileName
if target then if target then
local stream = vlc.stream(subfileURI) local stream = vlc.stream(subfileURI)
local data = "" local data = ""
...@@ -571,18 +474,20 @@ openSub = { ...@@ -571,18 +474,20 @@ openSub = {
end end
data = stream:readline() data = stream:readline()
end end
subfile:close()
subfile:flush()
subfile:close()
stream = nil stream = nil
end collectgarbage()
subfileURI = make_uri(target, true) subfileURI = make_uri(target, true)
collectgarbage() -- force gargabe collection in order to close the opened stream end
os.remove(tmpFileName) os.remove(tmpFileName)
end end
local item = vlc.item or vlc.input.item() if vlc.item or vlc.input.item() then
if item then vlc.msg.dbg("Adding subtitle :" .. subfileURI)
vlc.input.add_subtitle(subfileURI) vlc.input.add_subtitle(subfileURI)
setMessage("Success: Subtitles loaded.")
else else
setError("No current input, unable to add subtitles "..target) setError("No current input, unable to add subtitles "..target)
end end
...@@ -590,8 +495,7 @@ openSub = { ...@@ -590,8 +495,7 @@ openSub = {
} }
function make_uri(str, encode) function make_uri(str, encode)
local iswindowPath = string.match(str, "^%a:/.+$") local windowdrive = string.match(str, "^(%a:/).+$")
-- vlc.msg.dbg(iswindowPath)
if encode then if encode then
local encodedPath = "" local encodedPath = ""
for w in string.gmatch(str, "/([^/]+)") do for w in string.gmatch(str, "/([^/]+)") do
...@@ -600,139 +504,58 @@ function make_uri(str, encode) ...@@ -600,139 +504,58 @@ function make_uri(str, encode)
end end
str = encodedPath str = encodedPath
end end
if iswindowPath then if windowdrive then
return "file:///"..str return "file:///"..windowdrive..str
else else
return "file://"..str return "file://"..str
end end
end end
function download_selection()
local selection = widget.getVal("mainlist")
if #selection > 0 and openSub.itemStore then
download_subtitles(selection)
end
end
function searchHash() function searchHash()
if not hasAssociatedResult() then
openSub.sub.languageid = languages[widget.getVal("language")][2] openSub.sub.languageid = languages[widget.getVal("language")][2]
message = widget.get("message")
if message.display == "none" then
message.display = "block"
widget.set_interface(interface)
end
openSub.getMovieHash() openSub.getMovieHash()
associatedResult()
if openSub.file.hash then if openSub.file.hash then
openSub.request("SearchSubtitlesByHash") openSub.request("SearchSubtitlesByHash")
display_subtitles() display_subtitles()
end end
else
local selection = widget.getVal("hashmainlist")
if #selection > 0 then
download_subtitles(selection)
end
end
end end
function searchIMBD() function searchIMBD()
local title = trim(widget.getVal("title")) openSub.movie.name = trim(widget.getVal("title"))
local old_title = trim(widget.get("title").value) openSub.movie.season = tonumber(widget.getVal("season"))
local season = tonumber(widget.getVal("season")) openSub.movie.episode = tonumber(widget.getVal("episode"))
local old_season = tonumber(widget.get("season").value) openSub.sub.languageid = languages[widget.getVal("language")][2]
local episode = tonumber(widget.getVal("episode"))
local old_episode = tonumber(widget.get("episode").value)
local language = languages[widget.getVal("language")][2]
local selection = widget.getVal("imdbmainlist")
local sel = (#selection > 0)
local newTitle = (title ~= old_title)
local newEpisode = (season ~= old_season or episode ~= old_episode)
local newLanguage = (language ~= openSub.sub.languageid)
local movie = openSub.movie
local imdbResults = {}
widget.get("title").value = title
widget.get("season").value = season
widget.get("episode").value = episode
openSub.sub.languageid = language
if newTitle then
movie.imdbRequest = title
movie.imdbid = nil
movie.imdbidShow = nil
if openSub.request("SearchMoviesOnIMDB") then -- search exact match
local lowerTitle = string.lower(title)
local itemTitle = ""
for i, item in ipairs(openSub.itemStore) do
-- itemTitle = string.match(item.title, "[%s\"]*([^%(\"]*)[%s\"']*%(?")
item.cleanTitle = string.match(item.title, "[%s\"]*([^%(\"]*)[%s\"']*%(?")
-- vlc.msg.dbg(itemTitle)
--[[if string.lower(itemTitle) == lowerTitle then
movie.imdbid = item.id
break
end]]
table.insert(imdbResults, item.title)
end
if not movie.imdbid then
widget.setVal("imdbmainlist")
widget.setVal("imdbmainlist", imdbResults)
end
end
end
if not movie.imdbid and sel then
local index = selection[1][1]
local item = openSub.itemStore[index]
movie.imdbid = item.id
movie.title = item.cleanTitle
movie.imdbidShow = movie.imdbid
newEpisode = true
end
if movie.imdbid then
if season and episode and (newTitle or newEpisode) then
if not newTitle then
movie.imdbid = movie.imdbidShow
end
movie.imdbidEpisode = openSub.getImdbEpisodeIdGoogle(season, episode, movie.title)
-- movie.imdbidEpisode = openSub.getImdbEpisodeId(season, episode)
if movie.imdbidEpisode then message = widget.get("message")
vlc.msg.dbg("Episode imdbid: "..movie.imdbidEpisode) if message.display == "none" then
movie.imdbidShow = movie.imdbid message.display = "block"
movie.imdbid = movie.imdbidEpisode widget.set_interface(interface)
elseif openSub.request("IsTVserie") then
movie.imdbidEpisode = openSub.getImdbEpisodeIdYQL(season, episode)
if movie.imdbidEpisode then
movie.imdbidShow = movie.imdbid
movie.imdbid = movie.imdbidEpisode
else
setError("Season/episode don't match for this title")
end
else
setError("Title not referenced as a TV serie on IMDB")
--~ -- , choose an other one and/or empty episode/season field")
widget.setVal("imdbmainlist", imdbResults)
end
end end
if newTitle or newEpisode or newLanguage then if openSub.file.name ~= "" then
openSub.request("SearchSubtitlesByIdIMDB") openSub.request("SearchSubtitles")
display_subtitles() display_subtitles()
elseif sel and openSub.itemStore then
download_subtitles(selection)
end
end end
end end
function associatedResult()
local item = openSub.getInputItem()
if not item then return false end
result_state[tmp_method_id] = item:uri()
end
function hasAssociatedResult()
local item = openSub.getInputItem()
if not item then return false end
return (result_state[tmp_method_id] == item:uri())
end
function display_subtitles() function display_subtitles()
local list = tmp_method_id.."mainlist" local list = "mainlist"
widget.setVal(list) widget.setVal(list) --~ Reset list
if openSub.itemStore then if openSub.itemStore then
for i, item in ipairs(openSub.itemStore) do for i, item in ipairs(openSub.itemStore) do
widget.setVal(list, item.SubFileName.." ["..item.SubLanguageID.."] ("..item.SubSumCD.." CD)") widget.setVal(list, item.SubFileName.." ["..item.SubLanguageID.."] ("..item.SubSumCD.." CD)")
...@@ -743,21 +566,21 @@ function display_subtitles() ...@@ -743,21 +566,21 @@ function display_subtitles()
end end
function download_subtitles(selection) function download_subtitles(selection)
local list = tmp_method_id.."mainlist" local list = "mainlist"
widget.resetSel(list) -- reset selection widget.resetSel(list) -- reset selection
local index = selection[1][1] local index = selection[1][1]
local item = openSub.itemStore[index] local item = openSub.itemStore[index]
local subfileTarget = "" local subfileTarget = ""
if openSub.file.dir and openSub.file.name then
subfileTarget = openSub.file.dir..openSub.file.name.."."..item.SubLanguageID.."."..item.SubFormat
else
subfileTarget = os.tmpname() --FIXME: ask the user where to put it instaed
end
if openSub.conf.justgetlink then if openSub.conf.justgetlink
setMessage("Link: <a href='"..item.ZipDownloadLink.."'>"..item.ZipDownloadLink.."</a>") or not (vlc.item or vlc.input.item())
or not openSub.file.dir
or not openSub.file.name then
setMessage("Link : <a href='"..item.ZipDownloadLink.."'>"..item.ZipDownloadLink.."</a>")
else else
openSub.loadSubtitles(item.ZipDownloadLink, openSub.file.dir, item.SubFileName, subfileTarget) subfileTarget = openSub.file.dir..openSub.file.name.."."..item.SubLanguageID.."."..item.SubFormat
vlc.msg.dbg("subfileTarget: "..subfileTarget)
openSub.loadSubtitles(item.ZipDownloadLink, item.SubFileName, subfileTarget)
end end
end end
...@@ -835,11 +658,19 @@ widget = { ...@@ -835,11 +658,19 @@ widget = {
set_interface = function(intf_map) set_interface = function(intf_map)
local root = {left = 1, top = 0, height = 0, hidden = false} local root = {left = 1, top = 0, height = 0, hidden = false}
widget.set_node(intf_map, root) widget.set_node(intf_map, root)
widget.force_refresh()
end,
force_refresh = function() --~ Hacky
if refresh_toggle then
refresh_toggle = false
dlg:set_title(openSub.conf.useragent)
else
refresh_toggle = true
dlg:set_title(openSub.conf.useragent.." ")
end
end, end,
destroy = function(w) destroy = function(w)
dlg:del_widget(w.input) dlg:del_widget(w.input)
--~ w.input = nil
--~ w.value = nil
if widget.registered_table[w.id] then if widget.registered_table[w.id] then
widget.registered_table[w.id] = nil widget.registered_table[w.id] = nil
end end
...@@ -968,11 +799,24 @@ widget = { ...@@ -968,11 +799,24 @@ widget = {
} }
function create_dialog() function create_dialog()
dlg = vlc.dialog("VLSub") dlg = vlc.dialog(openSub.conf.useragent)
widget.set_interface(interface)
end
function toggle_help()
helpMessage = widget.get("helpMessage")
if helpMessage.display == "block" then
helpMessage.display = "none"
elseif helpMessage.display == "none" then
helpMessage.display = "block"
end
widget.set_interface(interface) widget.set_interface(interface)
end end
function set_interface()
function set_interface() --~ old
local method_index = widget.getVal("method") local method_index = widget.getVal("method")
local method_id = methods[method_index][2] local method_id = methods[method_index][2]
if tmp_method_id then if tmp_method_id then
...@@ -1001,13 +845,14 @@ function set_interface() ...@@ -1001,13 +845,14 @@ function set_interface()
end end
function progressBarContent(pct) function progressBarContent(pct)
local content = "<span style='color:#181'>" local content = "<span style='background-color:#181;color:#181;'>"
local accomplished = math.ceil(progressBarSize*pct/100) local accomplished = math.ceil(progressBarSize*pct/100)
local left = progressBarSize - accomplished local left = progressBarSize - accomplished
content = content .. string.rep ("|", accomplished) content = content .. string.rep ("-", accomplished)
content = content .. "</span><span style='background-color:#fff;color:#fff;'>"
content = content .. string.rep ("-", left)
content = content .. "</span>" content = content .. "</span>"
content = content .. string.rep ("|", left)
return content return content
end end
...@@ -1022,13 +867,44 @@ function setMessage(str) ...@@ -1022,13 +867,44 @@ function setMessage(str)
end end
end end
--~ Misc utils
function file_exists(name)
local f=io.open(name ,"r")
if f~=nil then
io.close(f)
vlc.msg.dbg("File found!" .. name)
return true
else
vlc.msg.dbg("File not found. "..name)
return false
end
end
function wait(seconds)
local _start = os.time()
local _end = _start+seconds
while (_end ~= os.time()) do
end
end
function trim(str)
if not str then return "" end
return string.gsub(str, "^%s*(.-)%s*$", "%1")
end
function remove_tag(str)
return string.gsub(str, "{[^}]+}", "")
end
--~ Network utils
function get(url) function get(url)
local host, path = parse_url(url) local host, path = parse_url(url)
local header = { local header = {
"GET "..path.." HTTP/1.1", "GET "..path.." HTTP/1.1",
"Host: "..host, "Host: "..host,
"User-Agent: "..openSub.conf.userAgentHTTP, "User-Agent: "..openSub.conf.userAgentHTTP,
--~ "TE: identity", -- useless, and that's a shame
"", "",
"" ""
} }
...@@ -1100,6 +976,8 @@ function parse_url(url) ...@@ -1100,6 +976,8 @@ function parse_url(url)
return url_parsed["host"], url_parsed["path"], url_parsed["option"] return url_parsed["host"], url_parsed["path"], url_parsed["option"]
end end
--~ XML utils
function parse_xml(data) function parse_xml(data)
local tree = {} local tree = {}
local stack = {} local stack = {}
...@@ -1159,7 +1037,6 @@ function parse_xmlrpc(data) ...@@ -1159,7 +1037,6 @@ function parse_xmlrpc(data)
table.insert(stack, tree) table.insert(stack, tree)
for op, tag, p, empty, val in string.gmatch(data, "<(%/?)([%w:]+)(.-)(%/?)>[%s\r\n\t]*([^<]*)") do for op, tag, p, empty, val in string.gmatch(data, "<(%/?)([%w:]+)(.-)(%/?)>[%s\r\n\t]*([^<]*)") do
if op=="/" then if op=="/" then
if tag == "member" or tag == "array" then if tag == "member" or tag == "array" then
if level>0 then if level>0 then
...@@ -1209,7 +1086,6 @@ function dump_xml(data) ...@@ -1209,7 +1086,6 @@ function dump_xml(data)
local function parse(data, stack) local function parse(data, stack)
for k,v in pairs(data) do for k,v in pairs(data) do
if type(k)=="string" then if type(k)=="string" then
--~ print(k)
dump = dump.."\r\n"..string.rep (" ", level).."<"..k..">" dump = dump.."\r\n"..string.rep (" ", level).."<"..k..">"
table.insert(stack, k) table.insert(stack, k)
level = level + 1 level = level + 1
...@@ -1247,14 +1123,7 @@ function dump_xml(data) ...@@ -1247,14 +1123,7 @@ function dump_xml(data)
return dump return dump
end end
function trim(str) --~ Interface data
if not str then return "" end
return string.gsub(str, "^%s*(.-)%s*$", "%1")
end
function remove_tag(str)
return string.gsub(str, "{[^}]+}", "")
end
languages = { languages = {
{'All', 'all'}, {'All', 'all'},
...@@ -1320,54 +1189,40 @@ interface = { ...@@ -1320,54 +1189,40 @@ interface = {
id = "header", id = "header",
type = "div", type = "div",
content = { content = {
{
{ type = "label", value = "Search method:" },
{
type = "dropdown",
value = methods,
id = "method",
width = 2
},
{ type = "button", value = "Go", callback = set_interface }
},
{ {
{ type = "label", value = "Language:" }, { type = "label", value = "Language:" },
{ type = "dropdown", value = languages, id = "language" , width = 2 } { type = "dropdown", value = languages, id = "language" , width = 2 },
{ type = "button", value = "Search by hash", callback = searchHash },
} }
} }
}, },
{ {
id = "hash", id = "imdb",
type = "div", type = "div",
display = "none",
content = { content = {
{ {
{ type = "list", width = 4, id = "hashmainlist" } { type = "label", value = "Title:"},
{ type = "text_input", value = openSub.movie.name or "", id = "title", width = 2 },
{ type = "button", value = "Search by name", callback = searchIMBD }
},{ },{
{ type = "span", width = 2}, { type = "label", value = "Season (series):"},
{ type = "button", value = "Ok", callback = searchHash }, { type = "text_input", value = openSub.movie.seasonNumber or "", id = "season", width = 2 }
{ type = "button", value = "Close", callback = close } },{
{ type = "label", value = "Episode (series):"},
{ type = "text_input", value = openSub.movie.episodeNumber or "", id = "episode", width = 2 }
},{
{ type = "list", width = 4, id = "mainlist" }
} }
} }
}, },
{ {
id = "imdb",
type = "div", type = "div",
display = "none",
content = { content = {
{ {
{ type = "label", value = "Title:"}, { type = "button", value = "Help", callback = toggle_help },
{ type = "text_input", value = openSub.movie.name or "", id = "title" } { type = "span", width = 1},
},{ { type = "button", value = "Download", callback = download_selection },
{ type = "label", value = "Season (series):"},
{ type = "text_input", value = openSub.movie.seasonNumber or "", id = "season" }
},{
{ type = "label", value = "Episode (series):"},
{ type = "text_input", value = openSub.movie.episodeNumber or "", id = "episode" },
{ type = "button", value = "Ok", callback = searchIMBD },
{ type = "button", value = "Close", callback = close } { type = "button", value = "Close", callback = close }
},{
{ type = "list", width = 4, id = "imdbmainlist" }
} }
} }
}, },
...@@ -1376,7 +1231,39 @@ interface = { ...@@ -1376,7 +1231,39 @@ interface = {
type = "div", type = "div",
content = { content = {
{ {
{ type = "label", width = 4, value = "Powered by <a href='http://www.opensubtitles.org/'>opensubtitles.org</a>", id = "message" } { type = "html", width = 4,
display = "none",
value = ""..
" Download subtittles from <a href='http://www.opensubtitles.org/'>opensubtitles.org</a> and display them while watching a video.<br>"..
" <br>"..
" <b><u>Usage:</u></b><br>"..
" <br>"..
" VLSub is meant to be used while your watching the video, so start it first (if nothing is playing you will get a link to download the subtitles in your browser).<br>"..
" <br>"..
" Choose the language for your subtitles and click on the button corresponding to one of the two research method provided by VLSub:<br>"..
" <br>"..
" <b>Method 1: Search by hash</b><br>"..
" It is recommended to try this method first, because it performs a research based on the video file print, so you can find subtitles synchronized with your video.<br>"..
" <br>"..
" <b>Method 2: Search by name</b><br>"..
" If you have no luck with the first method, just check the title is correct before clicking. If you search subtitles for a serie, you can also provide a season and episode number.<br>"..
" <br>"..
" <b>Downloading Subtitles</b><br>"..
" Select one subtitle in the list and click on 'Download'.<br>"..
" It will be put in the same directory that your video, with the same name (different extension)"..
" so Vlc will load them automatically the next time you'll start the video.<br>"..
" <br>"..
" <b>/!\\ Beware :</b> Existing subtitles are overwrited without asking confirmation, so put them elsewhere if thet're important."
, id = "helpMessage"
}
},{
{
type = "label",
width = 4,
display = "none",
value = " ",
id = "message"
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment