[Script] Download subtitles on-the-fly

Discuss your Lua playlist, album art and interface scripts.
kurdic
New Cone
New Cone
Posts: 1
Joined: 25 Oct 2011 18:30

Re: [Script] Download subtitles on-the-fly

Postby kurdic » 25 Oct 2011 18:40

Hi ale.

I can't find the %APPDATA%\VLC\lua\extensions\ folder. Only vlc folder for current user is: %APPDATA%\roaming\vlc\. So I'm a bit confused where to put the file.

Thnks.

etr
New Cone
New Cone
Posts: 7
Joined: 13 Oct 2011 12:39

Re: [Script] Download subtitles on-the-fly

Postby etr » 27 Oct 2011 02:08

Hi ale.

I can't find the %APPDATA%\VLC\lua\extensions\ folder. Only vlc folder for current user is: %APPDATA%\roaming\vlc\. So I'm a bit confused where to put the file.

Thnks.
Then create folder %APPDATA%\Roaming\vlc\lua\extensions and put it there.

mojitoo
New Cone
New Cone
Posts: 2
Joined: 28 Nov 2011 23:14

Re: [Script] Download subtitles on-the-fly

Postby mojitoo » 28 Nov 2011 23:22

Hey!

I'm using Mac OS and have located the extension folder and copied the lua file into it. But since the the mac version doesn't have a view menu I'm unable to localize where I can find it in the program. So where can find it if i'm using mac? I'm sorry but i missed that their where more pages to this subject...

fhtagn
New Cone
New Cone
Posts: 2
Joined: 04 Jan 2012 05:46

Re: [Script] Download subtitles on-the-fly

Postby fhtagn » 05 Jan 2012 19:30

Howdy!

I'd love it if there could be an implementation of the Windows Media Player Classic feature that searches opensubtitles.org database by hash (their twisted definition of hash)(I understand it is unique and fast enough, the two requirements for something meant to be on-the-fly). I prefer subscene, but I guess opensubtitles will have to do.

If I understood it correctly, the problem is there isn't an implementation of the hash function in Lua (and I don't even know if it will be fast enough). I will try to implement it and eventually post it here so others can contribute.

As an aside... subdownloader is in python and it already uses the hash function. Could vlc use that?
Why isn't this function in vlc, instead of being provided by an extension. No popular demand? An invite to piracy?

Thank you for your extension! keyword search works fine as it is, I'd just love to improve it.
Last edited by fhtagn on 06 Jan 2012 04:19, edited 1 time in total.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: [Script] Download subtitles on-the-fly

Postby Jean-Baptiste Kempf » 05 Jan 2012 22:57

It isn't a VLC function, because this is not really legal ... Texts and subtitles are copyrighted...

Anyway, take the version from the addons website, modify it and repost it with the hash.

No, python is not possible.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

fhtagn
New Cone
New Cone
Posts: 2
Joined: 04 Jan 2012 05:46

Re: [Script] Download subtitles on-the-fly

Postby fhtagn » 06 Jan 2012 04:19

I understand. Even if "searching and retrieving .srt files from a website, and embedding them in the current playing media" is not copyrighted or in any way illegal, I understand your point.

Will try to implement it!

also, thank you for VLC.

exebetche
Blank Cone
Blank Cone
Posts: 12
Joined: 04 Mar 2012 05:32

Re: [Script] Download subtitles on-the-fly

Postby exebetche » 08 Mar 2012 20:15

If I understood it correctly, the problem is there isn't an implementation of the hash function in Lua (and I don't even know if it will be fast enough). I will try to implement it and eventually post it here so others can contribute.
Hi

I just discovered your post and I wanted to tell you that I achieve this hash (checksum) function in my extension VLsub. It's actually pretty fast even with uncompiled LUA...
Now you can dig a subtitle synchronized with your video in one click!
Check this out:
http://addons.videolan.org/content/show ... ent=148752

PeteParsley
New Cone
New Cone
Posts: 1
Joined: 13 Dec 2012 18:56

Re: [Script] Download subtitles on-the-fly

Postby PeteParsley » 13 Dec 2012 20:11

Hi, I wondered for a long time why VLC didn't have the subtitle function as in for example bs player, glad people ar e working on it now.
I have the following suggestions:

-Languagetags for all languages ( did one for dutch myself, simple one to do).
-Also I saw that bsplayer has 2 other servers besides opensubtitlesDOTorg to download from, if they are free to use by anyone you might wanna add those


I wanna add one more thing being one example of some crashes I had whilst using this extension:
Your input can't be opened:
VLC is unable to open the MRL 'zip://http://www.opensubtitles.org/en/http:// ... 264!/Super ?282010?29 BRRip Xvid AC3?2dAnarchy.srt'. Check the log for details.
Hope these suggestions helped a bit.

XweAponX
Blank Cone
Blank Cone
Posts: 19
Joined: 15 Sep 2009 00:13
VLC version: 2.0.5 and 1.1.11
Operating System: Windows 7 and 8

Re: [Script] Download subtitles on-the-fly

Postby XweAponX » 21 Feb 2013 19:03

Wow - That works GREAT! It does take some fiddling with, as some of the subs are either zipped or not there at the URL it finds... But I was able to find the sub for the exact release, I used Fringe S1E1 as a test, it found the exact version of the release I was viewing, loaded it up and even copied it to the folder where I had the media. I downloaded the windows installer, IE9 detects it as a script but it allowed me to run it anyway. Thanx!

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: [Script] Download subtitles on-the-fly

Postby Jean-Baptiste Kempf » 26 Feb 2013 04:59

Wow - That works GREAT! It does take some fiddling with, as some of the subs are either zipped or not there at the URL it finds... But I was able to find the sub for the exact release, I used Fringe S1E1 as a test, it found the exact version of the release I was viewing, loaded it up and even copied it to the folder where I had the media. I downloaded the windows installer, IE9 detects it as a script but it allowed me to run it anyway. Thanx!
what version of the lua script did you take?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

XweAponX
Blank Cone
Blank Cone
Posts: 19
Joined: 15 Sep 2009 00:13
VLC version: 2.0.5 and 1.1.11
Operating System: Windows 7 and 8

Re: [Script] Download subtitles on-the-fly

Postby XweAponX » 12 Mar 2013 20:41

I'm not sure which one - It had a Windows Installer, and I just checked the latest version does not have one. The Windows package was numbered version 1.1.0.

I've used it quite a bit - I'd like to add in the one site where I get a lot of my subs. I get most of my subs from Addic7ed,com.

There is one thing I've got to say about the so called "legality" or lack thereof of downloading Subs: The Subs which are on the DVD or Blu-Ray you bought, are of course part of the copyright on that particular piece of media. But I'm tired of finding something really cool like this and then the legalists and religionists pounce on it. It's an argument as to why these kinds of people should refrain from Computing, because Computing, in general always skirts the boundaries of these so called legal issues.The reason WHY we can use these subtitles sites is that these subs are not from the releases - We make them ourselves, and due to that little thing they are outside of the purview of any legal issues. And, I prefer using Subs from these sources more than viewing the Subs on the release I bought - Because in 50% of all released movies and TV shows the Subs they provide are wrong.

Oh Yes - Last time I was here, I downloaded the Windows Installer for it that someone had made, and I suppose it was the lastest version that had been uploaded. I don't know if it was the current version though.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Revised Subtitles Finder

Postby mederi » 19 Mar 2013 13:24

Hi! So I dowloaded "SubtitlesFinder.lua" >> Source Code (zip archive from GitHub) << from:
http://thepanz.netsons.org/post/vlc-and ... downloader
And here is my revision:

Code: Select all

--[[ Subtitles Copyright © 2009-2010 VideoLAN and AUTHORS Authors: - thePanz (Download-and-save feature, updates, installer script) - ale5000 (Based on the script made by Jean-Philippe André) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. --]] dlg = nil dialog_is_opened = false dialog_is_hidden = false update_title_needed = false -- Common website = nil language = nil main_text_input = nil search_button = nil load_button = nil -- Dialog "Download subtitles" subtitles_list = nil subtitles_result = nil -- Dialog "Load subtitles from url..." type_text_input = nil function descriptor() return { title = "Subtitles Finder"; version = "1.1.0"; author = "thePanz, ale5000"; url = 'http://thepanz.netsons.org/post/vlc-and-opensubtitles-downloader'; description = "" .. "Find and get subtitles of movies from the internet." .. "<br /><br />Enabled online services:" .. "<ul>" .. "<li><a href='http://www.opensubtitles.org/'>www.OpenSubtitles.org</a></li>" .. "</ul>" .. "This plugin is based on the script made by Jean-Philippe André"; shortdesc = "Get the subtitles of movies from the internet, currently only from OpenSubtitles.org"; capabilities = { "menu"; "input-listener"--[[; "meta-listener"]] } } end function menu() if not dialog_is_hidden then return { "Download", "Upload", "Load from url...", "About" } else return { "Show" } end end -- Function triggered when the extension is activated function activate() vlc.msg.dbg(_VERSION) vlc.msg.dbg("[Subtitles] Activating") ---8 trigger_menu(1) ---8x return true end -- Function triggered when the extension is deactivated function deactivate() if dialog_is_opened then close() else reset_variables() dlg = nil end vlc.msg.dbg("[Subtitles] Deactivated") return true end function reset_variables() update_title_needed = false -- Common website = nil language = nil main_text_input = nil search_button = nil load_button = nil -- Dialog "Download subtitles" subtitles_list = nil subtitles_result = nil -- Dialog "Load subtitles from url..." type_text_input = nil end -- Function triggered when the dialog is closed function close() dialog_is_opened = false dialog_is_hidden = false vlc.msg.dbg("[Subtitles] Closing dialog") reset_variables() if dlg ~= nil then dlg:delete() end dlg = nil return true end -- Current input changed function input_changed() vlc.msg.dbg("[Subtitles] Input is changed") update_title() end -- Current input item meta changed --[[function meta_changed() end]] function update_title() if dialog_is_hidden or not update_title_needed then return true end vlc.msg.dbg("[Subtitles] Updating title") local item = vlc.input.item() if item == nil then return false end local title = item:name() -- It return the internal title or the filename if the first is missing if title ~= nil then title = string.gsub(title, "(.*)%.%w+$", "%1") -- Removes file extension if title ~= "" then main_text_input:set_text(title) dlg:update() return true end end return false end function show_dialog_download() -- column, row, colspan, rowspan dlg:add_label("<b>Database: </b>", 1, 1, 1, 1) website = dlg:add_dropdown(2, 1, 3, 1) ---1 dlg:add_label("<b>Search: </b>", 1, 2, 1, 1) main_text_input = dlg:add_text_input("", 2, 2, 3, 1) dlg:add_label("<b>Language: </b>", 1, 3, 1, 1) language = dlg:add_dropdown(2, 3, 1, 1) search_button = dlg:add_button("Search", click_search, 3, 3, 1, 1) dlg:add_button("Hide", hide_dialog, 4, 3, 1, 1) local data = descriptor() info_header = dlg:add_label("<hr /><center>More options are now available in VLC menu: View > " .. data.title .. " > ...<br />More VLC Lua Extensions: <a href='http://addons.videolan.org/index.php?xcontentmode=903'>http://addons.videolan.org</a></center>", 1, 4, 4, 1) ---1x for idx, ws in ipairs(websites) do website:add_value(ws.title, idx) end for idx, ws in ipairs(languages) do language:add_value(ws.title, idx) end update_title_needed = true update_title() dlg:update() return true end function show_dialog_upload() -- column, row, colspan, rowspan dlg:add_label("<right><b>Database: </b></right>", 1, 1, 1, 1) website = dlg:add_dropdown(2, 1, 4, 1) -- FIXME: Link is NOT yet working dlg:add_label("<center><a href='http://www.opensubtitles.org/upload'>Upload to OpenSubtitles.org</a></center>", 1, 2, 2, 1) for idx, ws in ipairs(websites) do website:add_value(ws.title, idx) end dlg:update() return true end function show_dialog_load_url() -- column, row, colspan, rowspan dlg:add_label("<right><b>URL: </b></right>", 1, 1, 1, 1) main_text_input = dlg:add_text_input("", 2, 1, 3, 1) dlg:add_label("<right><b>Type: </b></right>", 1, 2, 1, 1) type_text_input = dlg:add_text_input("", 2, 2, 1, 1) dlg:add_label("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", 3, 2, 1, 1) -- Spacer load_button = dlg:add_button("Load", click_load_from_url_button, 4, 2, 1, 1) dlg:update() return true end function show_dialog_about() local data = descriptor() -- column, row, colspan, rowspan dlg:add_label("<center><b>" .. data.title .. " " .. data.version .. "</b></center>", 1, 1, 1, 1) ---2 local additional_links="<br /><hr />Home: <a href='http://thepanz.netsons.org/post/vlc-and-opensubtitles-downloader'>VLC and OpenSubtitles downloader</a><br />Forum: <a href='http://forum.videolan.org/viewtopic.php?f=29&t=71535'>[Script] Download subtitles on-the-fly</a><br />Extensions: <a href='http://addons.videolan.org/index.php?xcontentmode=903'>http://addons.videolan.org</a>" dlg:add_html(data.description .. additional_links, 1, 2, 1, 1) ---2x dlg:update() return true end function sleep(sec) local t = vlc.misc.mdate() vlc.misc.mwait(t + sec*1000*1000) end function new_dialog(title) dlg = vlc.dialog(title) end function hide_dialog() dialog_is_hidden = true dlg:hide() end -- Function triggered when a element from the menu is selected function trigger_menu(id) if dialog_is_hidden then if dlg == nil then vlc.msg.err("[Subtitles] Dialog pointer lost") close() return false; end dialog_is_hidden = false dlg:show() return true end if(dialog_is_opened) then close() end dialog_is_opened = true if id == 1 then new_dialog("Download subtitles") return show_dialog_download() elseif id == 2 then new_dialog("Upload subtitles") return show_dialog_upload() elseif id == 3 then new_dialog("Load subtitles from url...") return show_dialog_load_url() elseif id == 4 then new_dialog("About") return show_dialog_about() end vlc.msg.err("[Subtitles] Invalid menu id: "..id) return false end function click_search() vlc.msg.dbg("[Subtitles] Clicked search button from \"Download subtitles\" dialog") local search_term = main_text_input:get_text() if(search_term == "") then return false end local old_button_name = search_button:get_text() search_button:set_text("Wait...") if subtitles_list ~= nil then subtitles_list:clear() end dlg:update() subtitles_result = nil local idx = website:get_value() local idx2 = language:get_value() if idx < 1 or idx2 < 1 then vlc.msg.err("[Subtitles] Invalid index in dropdown") search_button:set_text(old_button_name) return false end local ws = websites[idx] local lang = languages[idx2] local url = ws.urlfunc(search_term, lang.tag) -- vlc.msg.info("[Subtitles] Url: '" .. url .. "'") local stream = vlc.stream(url) if stream == nil then vlc.msg.err("[Subtitles] The site of subtitles isn't reachable") search_button:set_text(old_button_name) return false end local reading = "blah" local xmlpage = "" while(reading ~= nil and reading ~= "") do reading = stream:read(65653) if(reading) then xmlpage = xmlpage .. reading end end if xmlpage == "" then search_button:set_text(old_button_name) return false end subtitles_result = ws.parsefunc(xmlpage) if subtitles_list == nil then ---3 info_header:set_text("<hr />[Language][#Number of subtitles] Name of subtitle package") subtitles_list = dlg:add_list(1, 5, 4, 1) load_button = dlg:add_button("Load selected subtitles", click_load_from_search_button, 1, 6, 4, 1) save_checkbox = dlg:add_check_box("Save", false, 4, 6, 1, 1) info_footer = dlg:add_label("Then check loaded subtitles in VLC menu: Video > Subtitles Track > ...", 1, 7, 4, 1) ---3x end if not subtitles_result then subtitles_result = {} subtitles_result[1]= { url = "-1" } subtitles_list:add_value("Nothing found", 1) search_button:set_text(old_button_name) dlg:update() return false end for idx, res in ipairs(subtitles_result) do if(not res.language or lang.tag == "all" or lang.tag == res.language) then subtitles_list:add_value("["..res.language.."]".."[#"..res.numfiles.."] "..res.name, idx) end end search_button:set_text(old_button_name) dlg:update() return true end function load_unknown_subtitles(url, language) vlc.msg.dbg("[Subtitles] Loading "..language.." subtitle: "..url) vlc.input.add_subtitle(url) end function load_subtitles_in_the_archive(dataBuffer, language) local buffer_length = dataBuffer:len() local files_found_in_the_compressed_file = 0 local subtitles_found_in_the_compressed_file = 0 local endIdx = 1 local srturl, extension -- Find subtitles while(endIdx < buffer_length) do _, endIdx, srturl, extension = dataBuffer:find("<location>([^<]+)%.(%a%a%a?)</location>", endIdx) if(srturl == nil ) then break end --vlc.msg.dbg("[Subtitles] File found in the archive: " .. srturl .. extension) files_found_in_the_compressed_file = files_found_in_the_compressed_file + 1 srturl = string.gsub(srturl, "^(%a%a%a)://", "%1://http://") if(extension == "ass" or extension == "ssa" or extension == "srt" or extension == "smi" or extension == "sub" or extension == "rt" or extension == "txt" or extension == "mpl") then subtitles_found_in_the_compressed_file = subtitles_found_in_the_compressed_file + 1 vlc.msg.dbg("[Subtitles] Loading "..language.." subtitle: "..srturl) ---4 if save_checkbox:get_checked() then save_subtitle(srturl, extension, language) end ---4x vlc.input.add_subtitle(srturl.."."..extension) end end vlc.msg.info("[Subtitles] Files found in the compressed file: "..files_found_in_the_compressed_file) vlc.msg.info("[Subtitles] Subtitles found in the compressed file: "..subtitles_found_in_the_compressed_file) if(subtitles_found_in_the_compressed_file > 0) then return true end vlc.msg.warn("[Subtitles] No subtitles found in the compressed file") return false end function save_subtitle(url, extension, language) -- vlc.msg.info(url) -- vlc.msg.info(extension) -- vlc.msg.info(language) -- save2(url.."."..extension) local stream = vlc.stream(url.."."..extension) if stream == nil then vlc.msg.err("[Subtitle-download] The site of subtitles isn't reachable") return false end local data = stream:read(2048) if(data == nil) then vlc.msg.info("[Subtitle-download] Subtitle is NIL: "..url.."."..extension) else vlc.msg.info("[Subtitle-download] Buffering: "..url.."."..extension) local dataBuffer = "" while(data ~= nil and data ~= "") do dataBuffer = dataBuffer..data data = stream:read(8192) end -- vlc.msg.info("dataBuffer: "..dataBuffer) local item = vlc.input.item() if(item ~= nil) then local name = item:uri() -- vlc.msg.info("NAME: "..name) name = vlc.strings.decode_uri(string.gsub(name, "file:///", "")) ---7 Patch by abrahamvanhelpsing to handle Linux and Windows paths local winDir = os.getenv("windir") if (winDir == "") or (winDir == nil) then name = "/"..name end ---7x vlc.msg.info("[Subtitle-download] saving subtitle to: "..name.."."..language.."."..extension) local fsout = assert(io.open(name.."."..language.."."..extension, "w")) fsout:write(dataBuffer) assert(fsout:close()) end end end function parse_archive(url, language) if url == "-1" then vlc.msg.dbg("[Subtitles] Dummy result") return true end local stream = vlc.stream(url) if stream == nil then vlc.msg.err("[Subtitles] The site of subtitles isn't reachable") return false end stream:addfilter("zip,stream_filter_rar") local data = stream:read(2048) if(data == nil or data:find("<?xml version", 1, true) ~= 1) then vlc.msg.info("[Subtitles] Type: RAR or unknown file") load_unknown_subtitles(url, language) else vlc.msg.info("[Subtitles] Type: ZIP file") local dataBuffer = "" while(data ~= nil and data ~= "") do vlc.msg.dbg("Buffering...") dataBuffer = dataBuffer..data data = stream:read(8192) end load_subtitles_in_the_archive(dataBuffer, language) end --vlc.msg.dbg("[Subtitles] Subtitle data: "..dataBuffer) return true end function click_load_from_search_button() vlc.msg.dbg("[Subtitles] Clicked load button from \"Download subtitles\" dialog") if(not vlc.input.is_playing()) then vlc.msg.warn("[Subtitles] You cannot load subtitles if you aren't playing any file") ---5 info_footer:set_text("You cannot load subtitles if you aren't playing any file!") ---5x return true end local old_button_name = load_button:get_text() load_button:set_text("Wait...") dlg:update() local selection = subtitles_list:get_selection() local index, name for index, name in pairs(selection) do vlc.msg.dbg("[Subtitles] Selected the item "..index.." with the name: "..name) vlc.msg.dbg("[Subtitles] URL: "..subtitles_result[index].url) parse_archive(subtitles_result[index].url, subtitles_result[index].language) -- ZIP, RAR or unknown file end load_button:set_text(old_button_name) dlg:update() return true end function click_load_from_url_button() vlc.msg.dbg("[Subtitles] Clicked load button in \"Load subtitles from url...\" dialog") if(not vlc.input.is_playing()) then vlc.msg.warn("[Subtitles] You cannot load subtitles if you aren't playing any file") return true end local old_button_name = load_button:get_text() load_button:set_text("Wait...") type_text_input:set_text("") dlg:update() local url_to_load = main_text_input:get_text() if(url_to_load == "") then return false end vlc.msg.dbg("[Subtitles] URL: "..url_to_load) local _, ext_pos, extension = url_to_load:find("%.(%a%a%a?)", -4) if(ext_pos == url_to_load:len()) then type_text_input:set_text(extension) if(extension == "ass" or extension == "ssa" or extension == "srt" or extension == "smi" or extension == "sub" or extension == "rt" or extension == "txt" or extension == "mpl") then load_button:set_text(old_button_name) dlg:update() return vlc.input.add_subtitle(url_to_load) end end local result = parse_archive(url_to_load, "") if not result then vlc.msg.info("[Subtitles] Waiting 5 seconds before retry...") sleep(5) result = parse_archive(url_to_load, "") end load_button:set_text(old_button_name) dlg:update() return result end -- XML Parsing function parseargs(s) local arg = {} string.gsub(s, "(%w+)=([\"'])(.-)%2", function (w, _, a) arg[w] = a end) return arg end function collect(s) local stack = {} local top = {} table.insert(stack, top) local ni,c,label,xarg, empty local i, j = 1, 1 while true do ni,j,c,label,xarg, empty = string.find(s, "<(%/?)([%w:]+)(.-)(%/?)>", i) if not ni then break end local text = string.sub(s, i, ni-1) if not string.find(text, "^%s*$") then table.insert(top, text) end if empty == "/" then -- empty element tag table.insert(top, {label=label, xarg=parseargs(xarg), empty=1}) elseif c == "" then -- start tag top = {label=label, xarg=parseargs(xarg)} table.insert(stack, top) -- new level else -- end tag local toclose = table.remove(stack) -- remove top top = stack[#stack] if #stack < 1 then error("nothing to close with "..label) end if toclose.label ~= label then error("trying to close "..toclose.label.." with "..label) end table.insert(top, toclose) end i = j+1 end local text = string.sub(s, i) if not string.find(text, "^%s*$") then table.insert(stack[#stack], text) end if #stack > 1 then error("unclosed "..stack[stack.n].label) end return stack[1] end --[[ Websites configurations ]]-- -- OpenSubtitles.org -- This function uses first version of OS API. It will probably fail in the future. -- We'll need a XML-RPC key btw -- See: http://trac.opensubtitles.org/projects/opensubtitles/wiki/XMLRPC function urlOpenSub(search_term,lang) -- base = "http://api.opensubtitles.org/xml-rpc" -- lang = "eng" if lang == "all" then lang ="en" end base = "http://api.opensubtitles.org/"..lang.."/search/" -- if(lang) then base = base .. "sublanguageid-" .. lang .. "/" search_term = string.gsub(search_term, "%%", "%%37") search_term = string.gsub(search_term, " ", "%%20") return base .. "moviename-" .. search_term .. "/simplexml" -- http://api.opensubtitles.org/en/search/moviename- .. search_term .. /simplexml end function parseOpenSub(xmltext) vlc.msg.dbg("[Subtitles] Parsing XML data...") local xmltext = string.gsub(xmltext, "<%?xml version=\"1%.0\" encoding=\"utf-8\"%?>", "") local xmldata = collect(xmltext) for a,b in pairs(xmldata) do if type(b) == "table" then if b.label == "search" then xmldata = b break end end end if xmldata == nil then return nil end -- Subtitles information data local subname = {} local sub_movie = {} local suburl = {} local sublang = {} local sub_language = {} local subformat = {} local subfilenum = {} local subnum = 1 local baseurl = "" -- Let's browse iteratively the 'xmldata' tree -- OK, the variables' names aren't explicit enough, but just remember a couple -- a,b contains the index (a) and the data (b) of the table, which might also be a table for a,b in pairs(xmldata) do if type(b) == "table" then if b.label == "results" then for c,d in pairs(b) do if type(d) == "table" then if d.label == "subtitle" then for e,f in pairs(d) do if type(f) == "table" then if f.label == "releasename" then if f[1] ~= nil then subname[subnum] = f[1] else subname[subnum] = "" end elseif f.label == "movie" then if f[1] ~= nil then sub_movie[subnum] = f[1] else sub_movie[subnum] = "" end elseif f.label == "download" then if f[1] ~= nil then suburl[subnum] = f[1] else suburl[subnum] = "" end elseif f.label == "iso639" then -- language if f[1] ~= nil then sublang[subnum] = f[1] else sublang[subnum] = "" end elseif f.label == "language" then -- language -- not use yet if f[1] ~= nil then sub_language[subnum] = f[1] else sub_language[subnum] = "" end elseif f.label == "format" then if f[1] ~= nil then subformat[subnum] = f[1] else subformat[subnum] = "" end elseif f.label == "files" then if f[1] ~= nil then subfilenum[subnum] = f[1] else subfilenum[subnum] = "" end end end end subnum = subnum + 1 end end end elseif b.label == "base" then baseurl = b[1] end end end if subnum <= 1 then return nil end ret = {} for i = 1,(subnum - 1) do fullURL = baseurl .. "/" .. suburl[i] realName = string.gsub( subname[i], "<..CDATA.", "" ) realName = string.gsub( realName, "..>", "" ) if realName == "" then realName = string.gsub( sub_movie[i], "<..CDATA.", "" ) realName = string.gsub( realName, "..>", "" ) end ret[i] = { name = realName, url = fullURL, language = sublang[i], extension = ".zip" , numfiles = subfilenum[i] } vlc.msg.dbg("[Subtitles] Found subtitle " .. i .. ": ") vlc.msg.dbg(realName) vlc.msg.dbg(fullURL) end return ret end -- These tables must be after all function definitions websites = { { title = "OpenSubtitles.org", urlfunc = urlOpenSub, parsefunc = parseOpenSub } --[[; { title = "Fake (OS)", urlfunc = url2, parsefunc = parse2 }]] } -- ISO639 lang codes: -- For Opensubtitles refer to: http://www.opensubtitles.org/addons/export_languages.php languages = { { title = "All", tag = "all" }, ---6 { title = "Albanian [sq]", tag = "sq" }, { title = "Arabic [ar]", tag = "ar" }, { title = "Armenian [hy]", tag = "hy" }, { title = "Basque [eu]", tag = "eu" }, { title = "Bengali [bn]", tag = "bn" }, { title = "Bosnian [bs]", tag = "bs" }, { title = "Brazilian [pb]", tag = "pb" }, { title = "Breton [br]", tag = "br" }, { title = "Bulgarian [bg]", tag = "bg" }, { title = "Burmese [my]", tag = "my" }, { title = "Catalan [ca]", tag = "ca" }, { title = "Chinese [zh]", tag = "zh" }, { title = "Croation [hr]", tag = "hr" }, { title = "Czech [cs]", tag = "cs" }, { title = "Danish [da]", tag = "da" }, { title = "Dutch [nl]", tag = "nl" }, { title = "English [en]", tag = "en" }, { title = "Esperanto [eo]", tag = "eo" }, { title = "Estonian [et]", tag = "et" }, { title = "Finnish [fi]", tag = "fi" }, { title = "French [fr]", tag = "fr" }, { title = "Galician [gl]", tag = "gl" }, { title = "Georgian [ka]", tag = "ka" }, { title = "German [de]", tag = "de" }, { title = "Greek [el]", tag = "el" }, { title = "Hebrew [he]", tag = "he" }, { title = "Hindi [hi]", tag = "hi" }, { title = "Hungarian [hu]", tag = "hu" }, { title = "Icelandic [is]", tag = "is" }, { title = "Indonesian [id]", tag = "id" }, { title = "Italian [it]", tag = "it" }, { title = "Japanese [ja]", tag = "ja" }, { title = "Kazakh [kk]", tag = "kk" }, { title = "Khmer [km]", tag = "km" }, { title = "Korean [ko]", tag = "ko" }, { title = "Latvian [lv]", tag = "lv" }, { title = "Lithuanian [lt]", tag = "lt" }, { title = "Luxembourgish [lb]", tag = "lb" }, { title = "Macedonian [mk]", tag = "mk" }, { title = "Malay [ms]", tag = "ms" }, { title = "Malayalam [ml]", tag = "ml" }, { title = "Mongolian [mn]", tag = "mn" }, { title = "Norwegian [no]", tag = "no" }, { title = "Occitan [oc]", tag = "oc" }, { title = "Polish [pl]", tag = "pl" }, { title = "Portuguese [pt]", tag = "pt" }, { title = "Romanian [ro]", tag = "ro" }, { title = "Russian [ru]", tag = "ru" }, { title = "Serbian [sr]", tag = "sr" }, { title = "Sinhalese [si]", tag = "si" }, { title = "Slovak [sk]", tag = "sk" }, { title = "Slovenian [sl]", tag = "sl" }, { title = "Spanish [es]", tag = "es" }, { title = "Swahili [sw]", tag = "sw" }, { title = "Swedish [sv]", tag = "sv" }, { title = "Tagalog [tl]", tag = "tl" }, { title = "Telugu [te]", tag = "te" }, { title = "Thai [th]", tag = "th" }, { title = "Turkish [tr]", tag = "tr" }, { title = "Ukrainian [uk]", tag = "uk" }, { title = "Urdu [ur]", tag = "ur" }, { title = "Vietnamese [vi]", tag = "vi" } ---6x }
There are 6 changes marked by comments:

Code: Select all

---1 ... changes number 1 here ... ---1x
1.) longer Search text input field, shorter Language scroll down list >> swap
2.) additional links in menu About
3.) added header/footer above/under the selection list, added Save check-box
4.) save only if Save check-box is ticked
5.) show information also in dialog box
6.) added languages according to basic search on opensubtitles.org
--- EDIT ---
7.) applied patch by abrahamvanhelpsing to handle Linux and Windows paths when saving subtitles
--- EDIT 3.4.2013 ---
* fix of language "Italina" to correct "Italian"
--- EDIT 5.4.2013 ---
8.) forgot to highlight also automatic triggering of download dialog box
--- EDIT 7.4.2013 ---
Now all suggested improvements have been implemented in Subtitles Finder 1.3-beta
Last edited by mederi on 03 Apr 2013 20:56, edited 2 times in total.

cipricus
New Cone
New Cone
Posts: 3
Joined: 27 Mar 2013 20:25

Re: [Script] Download subtitles on-the-fly

Postby cipricus » 27 Mar 2013 20:29

works in Windows; but not in Linux

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: [Script] Download subtitles on-the-fly

Postby mederi » 27 Mar 2013 22:47

Applied patch by abrahamvanhelpsing to handle Linux and Windows paths when saving subtitles.

XweAponX
Blank Cone
Blank Cone
Posts: 19
Joined: 15 Sep 2009 00:13
VLC version: 2.0.5 and 1.1.11
Operating System: Windows 7 and 8

Re: [Script] Download subtitles on-the-fly

Postby XweAponX » 31 Mar 2013 23:10

I recently upgraded both of my machines to Windows 8 and re-downloaded the installer, and this add-on still works remarkably well. There is an issue where the playback stalls for an instant when applying the downloaded sub, and sometimes it will not load the sub automatically, but the sub is still there in the folder where my media is. It's about a 95% success rate finding the right sub and adding it in. The Installer I'm using says that it always downloads the latest version of this script, so I've been re-installing it about once every other week, it finds the new scripts and drops them in.

cipricus
New Cone
New Cone
Posts: 3
Joined: 27 Mar 2013 20:25

Re: [Script] Download subtitles on-the-fly

Postby cipricus » 02 Apr 2013 00:31

before applying abrahamvanhelpsing's patch it worked in Windows, now it works in Linux too. great job!

cipricus
New Cone
New Cone
Posts: 3
Joined: 27 Mar 2013 20:25

Re: [Script] Download subtitles on-the-fly

Postby cipricus » 02 Apr 2013 01:00

at the end, languages, 'Italina' needs correction to 'Italian'

thepanz
New Cone
New Cone
Posts: 2
Joined: 02 Jan 2011 21:39

Re: [Script] Download subtitles on-the-fly

Postby thepanz » 04 Apr 2013 11:01

I've updated the online script with your edits and gave authorship and thanks.
Could you try the new released version? In the source file you should read "Version 1.2"
Thanks for your efforts! :)

eckndu
New Cone
New Cone
Posts: 4
Joined: 24 Aug 2007 19:03

Re: [Script] Download subtitles on-the-fly

Postby eckndu » 07 Apr 2013 03:41

Hi, thanks for this addon.

the older version I had could put the srt along with its rar in the video's folder, which is nice; I had to manually delete the rar but i dont mind.
now the new one doesnt save the srt. so I used mederi's version.

however both OP, and mederi's new version made the video pause a few seconds before it can continue to play with the sub. minor annoyance but still thank for the service.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: [Script] Download subtitles on-the-fly

Postby mederi » 07 Apr 2013 14:32

the older version I had could put the srt along with its rar in the video's folder
What version was it, that was saving rars? Is it still available somewhere for downloading? I would like to check the code. Present version does not save all subtitle files if there are more of them in a zip package.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 2 guests