-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSmartLoad.lua
More file actions
104 lines (86 loc) · 2.96 KB
/
Copy pathSmartLoad.lua
File metadata and controls
104 lines (86 loc) · 2.96 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
function descriptor()
return {
title = "Smart Playlist Extender";
description = "Extends the playlist by files in last item's directory";
version = "0.1.1";
author = "thebamby";
capabilities = {}
}
end
function activate()
-- vlc.playlist.enqueue({{path = ""}})
-- if (true) then return end
local playlistItems = vlc.playlist.list()
-- vlc.msg.dbg(vlc.playlist.current())
if (#playlistItems == 0) then
vlc.msg.info("[SmartLoad] No items in playlist!")
vlc.deactivate()
return
end
local curItem = playlistItems[#playlistItems] -- playlist.current_item()
for k,v in pairs(curItem) do vlc.msg.dbg(tostring(k) .. " " .. tostring(v)) end
local ignoredPaths = { "."; ".." }
for key,item in ipairs(playlistItems) do
table.insert(ignoredPaths, getFilename(item.path))
end
if (not (string.sub(curItem.path, 1, 7) == "file://")) then
vlc.msg.info("[SmartLoad] Last item is not a proper file!")
vlc.deactivate()
return
end
local folderPath = getFolder(curItem.path).path
local curItemName = vlc.strings.decode_uri(getFilename(curItem.path).path)
-- for k,v in pairs(vlc.net.opendir(folderPath)) do vlc.msg.dbg(tostring(k) .. " " .. tostring(v)) end
local decodedFolderPath = vlc.strings.decode_uri(folderPath);
local files = vlc.io.readdir(decodedFolderPath)
table.sort(files)
local beforeFile = true
for _, item in ipairs(files) do
if ((curItemName >= item) or (arrayContains(item, ignoredPaths))) then
vlc.msg.dbg("Skip: " .. item)
else
vlc.msg.dbg("Trying to add: " .. item)
vlc.playlist.enqueue({{path = "file://" .. folderPath .. item; name = item}})
end
end
vlc.deactivate()
end
function arrayContains(value, arr)
for _, item in ipairs(arr) do
if (item == value) then
return true
end
end
return false
end
function getFolder(path)
local folderPath = string.match(path, ".*[\\\\/]")
folderPath = string.gsub(folderPath, "file://", "")
-- vlc.msg.dbg(folderPath)
return unpercent(folderPath)
end
function getFilename(path)
local filename = string.match(path, "[^\\\\/]*$")
return unpercent(filename)
end
function unpercent(str)
return vlc.strings.url_parse(str)
-- local matchCount
-- local parsedString
-- local percMatch = "%%%x%x"
-- function parsePercent(str)
-- local varCode = tonumber(string.sub(str, 2), 16)
-- -- vlc.msg.dbg("matched " .. str .. " charCode " .. varCode .. " char: " .. string.char(varCode))
-- return string.char(varCode) -- should be utf8.char(varCode)
-- end
-- parsedString, matchCount = string.gsub(str, percMatch, parsePercent)
-- -- vlc.msg.dbg(matchCount .. " " .. parsedString)
-- return parsedString
end
function deactivate()
end
function meta_changed()
end
function close()
vlc.deactivate()
end