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).
This commit is contained in:
Rafostar
2020-09-12 22:59:10 +02:00
parent 043fe9f75e
commit 5e6b0b9c48

View File

@@ -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;