[vlc-commits] Revert "VLSub: Allow a subtitle to be loaded without download it"
Hugo Beauzée-Luyssen
git at videolan.org
Thu Apr 5 10:26:02 CEST 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Apr 3 13:41:04 2018 +0200| [d55ef2c177abfa9e160d36b172bcaed17e6c5f89] | committer: Hugo Beauzée-Luyssen
Revert "VLSub: Allow a subtitle to be loaded without download it"
This reverts commit d32f7fb5777bf7073162c61294a5aab33f87adbe.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d55ef2c177abfa9e160d36b172bcaed17e6c5f89
---
share/lua/extensions/VLSub.lua | 132 ++++++++++++++++++++++++-----------------
1 file changed, 79 insertions(+), 53 deletions(-)
diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index 83a25d1efd..793f2bc458 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -1064,7 +1064,6 @@ function SetDownloadBehaviours()
openSub.conf.downloadBehaviours = nil
openSub.conf.downloadBehaviours = {
{'save', lang["int_dowload_save"]},
- {'load', lang["int_dowload_load"]},
{'manual', lang["int_dowload_manual"]}
}
end
@@ -1671,7 +1670,7 @@ function get_first_sel(list)
end
function find_subtitle_in_archive(archivePath, subfileExt)
- local archive = vlc.directory_stream(archivePath)
+ local archive = vlc.directory_stream("file://" .. archivePath)
local items = archive:readdir()
if not items then
return nil
@@ -1685,7 +1684,44 @@ function find_subtitle_in_archive(archivePath, subfileExt)
return nil
end
-function dump_subtitle_file(item, subtitleMrl)
+function download_subtitles()
+ local index = get_first_sel(input_table["mainlist"])
+
+ if index == 0 then
+ setMessage(lang["mess_no_selection"])
+ return false
+ end
+
+ openSub.actionLabel = lang["mess_downloading"]
+
+ display_subtitles() -- reset selection
+
+ local item = openSub.itemStore[index]
+
+ if openSub.option.downloadBehaviour == 'manual'
+ or not openSub.file.hasInput then
+ local link = "<span style='color:#181'>"
+ link = link.."<b>"..lang["mess_dowload_link"]..":</b>"
+ link = link.."</span> "
+ link = link.."</span> <a href='"..
+ item.ZipDownloadLink.."'>"
+ link = link..item.MovieReleaseName.."</a>"
+
+ setMessage(link)
+ return false
+ end
+
+ local message = ""
+ local subfileName = openSub.file.name or ""
+
+ if openSub.option.langExt then
+ subfileName = subfileName.."."..item.SubLanguageID
+ end
+
+ subfileName = subfileName.."."..item.SubFormat
+ local tmp_dir
+ local file_target_access = true
+
if is_dir(openSub.file.dir) then
tmp_dir = openSub.file.dir
elseif openSub.conf.dirPath then
@@ -1701,13 +1737,19 @@ function dump_subtitle_file(item, subtitleMrl)
return false
end
- local subfileName = openSub.file.name or ""
+ local tmpFileName = dump_zip(
+ item.ZipDownloadLink,
+ tmp_dir,
+ item.SubFileName)
- if openSub.option.langExt then
- subfileName = subfileName.."."..item.SubLanguageID
- end
+ vlc.msg.dbg("[VLsub] tmpFileName: "..tmpFileName)
- subfileName = subfileName.."."..item.SubFormat
+ local subtitleMrl = find_subtitle_in_archive(tmpFileName, item.SubFormat)
+
+ if not subtitleMrl then
+ vlc.msg.err( "Failed to extract subtitle" )
+ return false
+ end
-- Determine if the path to the video file is accessible for writing
@@ -1725,7 +1767,7 @@ function dump_subtitle_file(item, subtitleMrl)
setError(lang["mess_save_fail"].." "..
"<a href='"..item.ZipDownloadLink.."'>"..
lang["mess_click_link"].."</a>")
- return nil
+ return false
end
end
@@ -1748,65 +1790,49 @@ function dump_subtitle_file(item, subtitleMrl)
stream = nil
collectgarbage()
- return target
-end
-
-function download_subtitles()
- local index = get_first_sel(input_table["mainlist"])
-
- if index == 0 then
- setMessage(lang["mess_no_selection"])
- return false
+ if not os.remove(tmpFileName) then
+ vlc.msg.err("[VLsub] Unable to remove temp: "..tmpFileName)
end
- openSub.actionLabel = lang["mess_downloading"]
+ -- load subtitles
+ if add_sub(target) then
+ message = success_tag(lang["mess_loaded"]) .. message
+ else
+ message = error_tag(lang["mess_not_load"]) .. message
+ end
- display_subtitles() -- reset selection
+ setMessage(message)
+end
- local item = openSub.itemStore[index]
+function dump_zip(url, dir, subfileName)
+ -- Dump zipped data in a temporary file
+ setMessage(openSub.actionLabel..": "..progressBarContent(0))
+ local resp = get(url)
- if openSub.option.downloadBehaviour == 'manual'
- or not openSub.file.hasInput then
- local link = "<span style='color:#181'>"
- link = link.."<b>"..lang["mess_dowload_link"]..":</b>"
- link = link.."</span> "
- link = link.."</span> <a href='"..
- item.ZipDownloadLink.."'>"
- link = link..item.MovieReleaseName.."</a>"
-
- setMessage(link)
+ if not resp then
+ setError(lang["mess_no_response"])
return false
end
- local message = ""
-
- local subtitleMrl = find_subtitle_in_archive(item.ZipDownloadLink, item.SubFormat)
- if not subtitleMrl then
- vlc.msg.err( "Failed to extract subtitle" )
+ local tmpFileName = dir..subfileName..".gz"
+ if not file_touch(tmpFileName) then
return false
end
+ local tmpFile = assert(io.open(tmpFileName, "wb"))
- if openSub.option.downloadBehaviour == 'save' then
- local target = dump_subtitle_file(item, subtitleMrl)
- if target then
- subtitleMrl = vlc.strings.make_uri(target)
- end
- end
-
- -- load subtitles
- if add_sub(subtitleMrl) then
- message = success_tag(lang["mess_loaded"]) .. message
- else
- message = error_tag(lang["mess_not_load"]) .. message
- end
+ tmpFile:write(resp)
+ tmpFile:flush()
+ tmpFile:close()
+ tmpFile = nil
+ collectgarbage()
- setMessage(message)
+ return tmpFileName
end
-function add_sub(subMrl)
+function add_sub(subPath)
if vlc.item or vlc.input.item() then
- vlc.msg.dbg("[VLsub] Adding subtitle :" .. subMrl)
- return vlc.input.add_subtitle_mrl(subMrl, true)
+ vlc.msg.dbg("[VLsub] Adding subtitle :" .. subPath)
+ return vlc.input.add_subtitle(subPath, true)
end
return false
end
More information about the vlc-commits
mailing list