mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-31 00:11:59 +02:00
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:
@@ -82,15 +82,38 @@ class ClapperPlayer extends GstPlayer.Player
|
|||||||
|
|
||||||
debug(`parsed source to URI: ${uri}`);
|
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');
|
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);
|
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)
|
set_playlist(playlist)
|
||||||
{
|
{
|
||||||
if(!Array.isArray(playlist))
|
if(!Array.isArray(playlist) || !playlist.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._trackId = 0;
|
this._trackId = 0;
|
||||||
|
Reference in New Issue
Block a user