Change to wrapping the filesystem iterator rather than iterating over table values. Also centralise the is_playlist check and hide Playlists menu if none are presentcustom
parent
844b3f733e
commit
ff733e8f0c
@ -0,0 +1,35 @@ |
|||||||
|
local PlaylistIterator = {} |
||||||
|
|
||||||
|
function PlaylistIterator:is_playlist(item) |
||||||
|
return item:filepath():match("%.playlist$") |
||||||
|
or item:filepath():match("%.m3u8?$") |
||||||
|
end |
||||||
|
|
||||||
|
function PlaylistIterator:create(fs_iterator) |
||||||
|
local iterator = fs_iterator:clone() |
||||||
|
local obj = {}; |
||||||
|
|
||||||
|
local find_matching = function(iterate_fn) |
||||||
|
local next = iterate_fn(iterator); |
||||||
|
while next and (not PlaylistIterator:is_playlist(next) and not next:is_directory()) do |
||||||
|
next = iterate_fn(); |
||||||
|
end |
||||||
|
return next; |
||||||
|
end |
||||||
|
|
||||||
|
function obj:clone() |
||||||
|
return PlaylistIterator:create(iterator) |
||||||
|
end |
||||||
|
|
||||||
|
function obj:next() |
||||||
|
return find_matching(iterator.next) |
||||||
|
end |
||||||
|
|
||||||
|
function obj:prev() |
||||||
|
return find_matching(iterator.prev) |
||||||
|
end |
||||||
|
|
||||||
|
return obj |
||||||
|
end |
||||||
|
|
||||||
|
return PlaylistIterator |
@ -1,27 +0,0 @@ |
|||||||
|
|
||||||
local TableIterator = {} |
|
||||||
|
|
||||||
function TableIterator:create(table) |
|
||||||
local iterator = {}; |
|
||||||
iterator.index = 0; |
|
||||||
iterator.table = table; |
|
||||||
|
|
||||||
function iterator:clone() |
|
||||||
return TableIterator:create(table) |
|
||||||
end |
|
||||||
|
|
||||||
function iterator:next() |
|
||||||
self.index = self.index + 1 |
|
||||||
return self.table[self.index] |
|
||||||
end |
|
||||||
|
|
||||||
function iterator:prev() |
|
||||||
self.index = self.index - 1 |
|
||||||
return self.table[self.index] |
|
||||||
end |
|
||||||
|
|
||||||
return iterator |
|
||||||
end |
|
||||||
|
|
||||||
|
|
||||||
return TableIterator |
|
Loading…
Reference in new issue