diff --git a/qml/harbour-videoPlayer.qml b/qml/harbour-videoPlayer.qml index a5a9f7d..412b631 100644 --- a/qml/harbour-videoPlayer.qml +++ b/qml/harbour-videoPlayer.qml @@ -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 @@ -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") ; @@ -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); } diff --git a/qml/pages/OpenURLPage.qml b/qml/pages/OpenURLPage.qml index 12da199..6f31971 100644 --- a/qml/pages/OpenURLPage.qml +++ b/qml/pages/OpenURLPage.qml @@ -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(); diff --git a/qml/pages/PlaylistPage.qml b/qml/pages/PlaylistPage.qml index 4c4bc94..7337869 100644 --- a/qml/pages/PlaylistPage.qml +++ b/qml/pages/PlaylistPage.qml @@ -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; + } } } } @@ -233,7 +239,7 @@ Page dataContainer: playlistPage selectMode: true onFileOpen: { - mainWindow.modelPlaylist.addTrack(path); + mainWindow.modelPlaylist.addTrack(path, ""); } } } diff --git a/qml/pages/fileman/OpenDialog.qml b/qml/pages/fileman/OpenDialog.qml index 203c220..b3fbaf7 100644 --- a/qml/pages/fileman/OpenDialog.qml +++ b/qml/pages/fileman/OpenDialog.qml @@ -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 { @@ -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 {