diff options
| author | Sam <github@samlord.co.uk> | 2025-02-04 21:13:52 +0000 |
|---|---|---|
| committer | Sam <github@samlord.co.uk> | 2025-02-04 21:13:52 +0000 |
| commit | ff733e8f0c827e3d2d91bb7db29a85807867ab5e (patch) | |
| tree | ede269bca54b5316e5e0cd13eedde82d938b26dc /lua/playlist_iterator.lua | |
| parent | 844b3f733ec30eff41c3b3d48c74561d7b11da8e (diff) | |
| download | tangara-fw-ff733e8f0c827e3d2d91bb7db29a85807867ab5e.tar.gz | |
Wrap filesystem iterator
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 present
Diffstat (limited to 'lua/playlist_iterator.lua')
| -rw-r--r-- | lua/playlist_iterator.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lua/playlist_iterator.lua b/lua/playlist_iterator.lua new file mode 100644 index 00000000..06e80ad2 --- /dev/null +++ b/lua/playlist_iterator.lua @@ -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 |
