summaryrefslogtreecommitdiff
path: root/lua/playlist_iterator.lua
diff options
context:
space:
mode:
authorrdsh <rdsh@noreply.codeberg.org>2025-02-05 21:57:45 +0000
committerrdsh <rdsh@noreply.codeberg.org>2025-02-05 21:57:45 +0000
commit2ec84a1393331f57f8402bce66d337c0dd255f64 (patch)
tree30f271bf10988a9717abdf266d135e3ec0ae2d31 /lua/playlist_iterator.lua
parentddcd06dbca61fc55a7c2cd68f82f8cfe7b4c5cbf (diff)
parent9ecb79a264daa7896ce7d5a65592c05631213d5a (diff)
downloadtangara-fw-2ec84a1393331f57f8402bce66d337c0dd255f64.tar.gz
Merge pull request 'main' (#1) from cool-tech-zone/tangara-fw:main into main
Reviewed-on: https://codeberg.org/rdsh/tangara-fw/pulls/1
Diffstat (limited to 'lua/playlist_iterator.lua')
-rw-r--r--lua/playlist_iterator.lua35
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