From 5e6b0b9c48aa7219e4df32c52b3881d4674a00ec Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sat, 12 Sep 2020 22:59:10 +0200 Subject: [PATCH] Load playlist from text file With this change Clapper can open and load a playlist inside a text file. The text file should have a ".claps" extension and include one media file path per line (path can be either absolute, relative or even a HTTP link). --- clapper_src/player.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/clapper_src/player.js b/clapper_src/player.js index 75a1c903..f77991ea 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -82,15 +82,38 @@ class ClapperPlayer extends GstPlayer.Player debug(`parsed source to URI: ${uri}`); - if(!Gio.file_new_for_uri(uri).query_exists(null)) + let file = Gio.file_new_for_uri(uri); + + if(!file.query_exists(null)) return debug(`file does not exist: ${source}`, 'LEVEL_WARNING'); + if(file.get_path().endsWith('.claps')) + return this.load_playlist_file(file); + this.set_uri(uri); } + load_playlist_file(file) + { + let stream = new Gio.DataInputStream({ + base_stream: file.read(null) + }); + let plist = []; + let line; + + while((line = stream.read_line(null)[0])) { + line = String(line); + debug(`new playlist item: ${line}`); + plist.push(line); + } + + stream.close(null); + this.set_playlist(plist); + } + set_playlist(playlist) { - if(!Array.isArray(playlist)) + if(!Array.isArray(playlist) || !playlist.length) return; this._trackId = 0;