├── README.md ├── LICENSE └── SmartLoad.lua /README.md: -------------------------------------------------------------------------------- 1 | # vlcSmartLoad 2 | VLC extension to load next files in directory 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 TheBamby 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SmartLoad.lua: -------------------------------------------------------------------------------- 1 | function descriptor() 2 | return { 3 | title = "Smart Playlist Extender"; 4 | description = "Extends the playlist by files in last item's directory"; 5 | version = "0.1.1"; 6 | author = "thebamby"; 7 | capabilities = {} 8 | } 9 | end 10 | 11 | function activate() 12 | -- vlc.playlist.enqueue({{path = ""}}) 13 | -- if (true) then return end 14 | 15 | local playlistItems = vlc.playlist.list() 16 | -- vlc.msg.dbg(vlc.playlist.current()) 17 | if (#playlistItems == 0) then 18 | vlc.msg.info("[SmartLoad] No items in playlist!") 19 | vlc.deactivate() 20 | return 21 | end 22 | 23 | local curItem = playlistItems[#playlistItems] -- playlist.current_item() 24 | for k,v in pairs(curItem) do vlc.msg.dbg(tostring(k) .. " " .. tostring(v)) end 25 | local ignoredPaths = { "."; ".." } 26 | 27 | for key,item in ipairs(playlistItems) do 28 | table.insert(ignoredPaths, getFilename(item.path)) 29 | end 30 | 31 | if (not (string.sub(curItem.path, 1, 7) == "file://")) then 32 | vlc.msg.info("[SmartLoad] Last item is not a proper file!") 33 | vlc.deactivate() 34 | return 35 | end 36 | 37 | local folderPath = getFolder(curItem.path).path 38 | local curItemName = vlc.strings.decode_uri(getFilename(curItem.path).path) 39 | -- for k,v in pairs(vlc.net.opendir(folderPath)) do vlc.msg.dbg(tostring(k) .. " " .. tostring(v)) end 40 | local decodedFolderPath = vlc.strings.decode_uri(folderPath); 41 | local files = vlc.io.readdir(decodedFolderPath) 42 | table.sort(files) 43 | 44 | local beforeFile = true 45 | 46 | for _, item in ipairs(files) do 47 | if ((curItemName >= item) or (arrayContains(item, ignoredPaths))) then 48 | vlc.msg.dbg("Skip: " .. item) 49 | else 50 | vlc.msg.dbg("Trying to add: " .. item) 51 | vlc.playlist.enqueue({{path = "file://" .. folderPath .. item; name = item}}) 52 | end 53 | end 54 | vlc.deactivate() 55 | end 56 | 57 | function arrayContains(value, arr) 58 | for _, item in ipairs(arr) do 59 | if (item == value) then 60 | return true 61 | end 62 | end 63 | 64 | return false 65 | end 66 | 67 | function getFolder(path) 68 | local folderPath = string.match(path, ".*[\\\\/]") 69 | folderPath = string.gsub(folderPath, "file://", "") 70 | -- vlc.msg.dbg(folderPath) 71 | return unpercent(folderPath) 72 | end 73 | 74 | function getFilename(path) 75 | local filename = string.match(path, "[^\\\\/]*$") 76 | return unpercent(filename) 77 | end 78 | 79 | function unpercent(str) 80 | 81 | return vlc.strings.url_parse(str) 82 | -- local matchCount 83 | -- local parsedString 84 | -- local percMatch = "%%%x%x" 85 | -- function parsePercent(str) 86 | -- local varCode = tonumber(string.sub(str, 2), 16) 87 | -- -- vlc.msg.dbg("matched " .. str .. " charCode " .. varCode .. " char: " .. string.char(varCode)) 88 | -- return string.char(varCode) -- should be utf8.char(varCode) 89 | -- end 90 | 91 | -- parsedString, matchCount = string.gsub(str, percMatch, parsePercent) 92 | -- -- vlc.msg.dbg(matchCount .. " " .. parsedString) 93 | -- return parsedString 94 | end 95 | 96 | function deactivate() 97 | end 98 | 99 | function meta_changed() 100 | end 101 | 102 | function close() 103 | vlc.deactivate() 104 | end --------------------------------------------------------------------------------