Skip to content

Commit

Permalink
Add support for loading m3u files (Addresses some issues of #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
llelectronics committed Jun 5, 2018
1 parent 9c6f317 commit 872dd6b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
40 changes: 38 additions & 2 deletions qml/harbour-videoPlayer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import QtQuick.Window 2.1
import "pages"
import "pages/helper/yt.js" as YT
import "pages/helper/db.js" as DB
import "pages/helper/m3u.js" as M3U
import harbour.videoplayer.Videoplayer 1.0

ApplicationWindow
Expand Down Expand Up @@ -74,6 +75,38 @@ ApplicationWindow
else return false
}

function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function readM3uFile(file)
{
var allText
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
allText = rawFile.responseText;
var m3uPlaylist = M3U.parse(allText);
// Make sure Playlist is clear
modelPlaylist.clear();
for (var i=0; i< m3uPlaylist.tracks.length; i++) {
//console.debug(m3uPlaylist.tracks[i].title + " " + m3uPlaylist.tracks[i].file);
if (m3uPlaylist.tracks[i].title && m3uPlaylist.tracks[i].title != "")
modelPlaylist.addTrack(m3uPlaylist.tracks[i].file,m3uPlaylist.tracks[i].title);
else
modelPlaylist.addTrack(m3uPlaylist.tracks[i].file,"");
}
}
}
}
rawFile.send(null);
}

function loadUrl(url) {
if (autoPlay == true) {
console.debug("autoPlay = true") ;
Expand Down Expand Up @@ -273,8 +306,11 @@ ApplicationWindow
}
}

function addTrack(url) {
append({"title" : findBaseName(url), "url" : url});
function addTrack(url, title) {
if (title != "")
append({"title" : title, "url" : url});
else
append({"title" : findBaseName(url), "url" : url});
playlist.add(url);
}

Expand Down
7 changes: 6 additions & 1 deletion qml/pages/OpenURLPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ Dialog {
}
}
else {
if ((!mainWindow.contains(urlField.text.toString(),"rtsp")) && mainWindow.isUrl(urlField.text.toString())) {
if (mainWindow.endsWith(urlField.text.toString(), ".m3u")) {
// Handle M3U files here by loading them into the playlist
mainWindow.readM3uFile(urlField.text.toString());
firstPage.openPlaylist();
}
else if ((!mainWindow.contains(urlField.text.toString(),"rtsp")) && mainWindow.isUrl(urlField.text.toString())) {
// Call C++ side here to grab url
_ytdl.setUrl(urlField.text.toString());
_ytdl.getStreamUrl();
Expand Down
12 changes: 9 additions & 3 deletions qml/pages/PlaylistPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,14 @@ Page
selectMode: true
onFileOpen: {
//console.debug("Try loading playlist " + path);
mainWindow.modelPlaylist.isNew = false;
mainWindow.playlist.pllist = path;
if (mainWindow.endsWith(path, ".m3u")) {
// Handle M3U files here by loading them into the playlist
mainWindow.readM3uFile(path);
}
else {
mainWindow.modelPlaylist.isNew = false;
mainWindow.playlist.pllist = path;
}
}
}
}
Expand All @@ -233,7 +239,7 @@ Page
dataContainer: playlistPage
selectMode: true
onFileOpen: {
mainWindow.modelPlaylist.addTrack(path);
mainWindow.modelPlaylist.addTrack(path, "");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions qml/pages/fileman/OpenDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Page {
var i;
for (i = 0; i < fileModel.count; ++i)
if (!fileModel.isFolder(i))
mainWindow.modelPlaylist.addTrack(fileModel.get(i, "filePath"))
mainWindow.modelPlaylist.addTrack(fileModel.get(i, "filePath"), "")
}

SilicaListView {
Expand Down Expand Up @@ -210,7 +210,7 @@ Page {
mainWindow.infoBanner.parent = page
mainWindow.infoBanner.anchors.top = page.top
mainWindow.infoBanner.showText(mainWindow.findBaseName(filePath) + " " + qsTr("added to playlist"));
mainWindow.modelPlaylist.addTrack(filePath);
mainWindow.modelPlaylist.addTrack(filePath,"");
}

ListItem {
Expand Down

0 comments on commit 872dd6b

Please sign in to comment.