diff options
| author | ailurux <ailurux@noreply.codeberg.org> | 2025-02-05 04:56:06 +0000 |
|---|---|---|
| committer | ailurux <ailurux@noreply.codeberg.org> | 2025-02-05 04:56:06 +0000 |
| commit | 407c2f36f5dd6971d588f76ba5e426240f6c4131 (patch) | |
| tree | 811cc15ce41b7a086bf6e82dd4cbbd9b9674f135 /lua/playlist_iterator.lua | |
| parent | ebadc83f785da9a24cdcaba774613a1cebfb084d (diff) | |
| parent | 342726a9fc432650adb2e2de16fed02654f4d30d (diff) | |
| download | tangara-fw-407c2f36f5dd6971d588f76ba5e426240f6c4131.tar.gz | |
Merge pull request 'Playlist Browser' (#228) from slord/tangara-fw:playlist-browser into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/228
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 |
