diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 9cf99ad..1b8109f 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -175,7 +175,16 @@ MainWindow::~MainWindow() void MainWindow::showUrls(const QList &urls) { if (!urls.isEmpty()) { - m_graphicsView->showFileFromPath(urls.first().toLocalFile()); + const QUrl & firstUrl = urls.first(); + if (urls.count() == 1) { + const QString lowerCaseUrlPath(firstUrl.path().toLower()); + if (lowerCaseUrlPath.endsWith(".m3u8") || lowerCaseUrlPath.endsWith(".m3u")) { + m_pm->loadM3U8Playlist(firstUrl); + galleryCurrent(true, true); + return; + } + } + m_graphicsView->showFileFromPath(firstUrl.toLocalFile()); m_pm->loadPlaylist(urls); } else { m_graphicsView->showText(tr("File url list is empty")); diff --git a/app/playlistmanager.cpp b/app/playlistmanager.cpp index 7ada680..c86ff02 100644 --- a/app/playlistmanager.cpp +++ b/app/playlistmanager.cpp @@ -186,6 +186,26 @@ QModelIndex PlaylistManager::loadPlaylist(const QUrl &url) return idx; } +QModelIndex PlaylistManager::loadM3U8Playlist(const QUrl &url) +{ + QFile file(url.toLocalFile()); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QList urls; + while (!file.atEnd()) { + QString line = file.readLine(); + if (line.startsWith('#')) { + continue; + } + QFileInfo fileInfo(file); + QUrl item = QUrl::fromUserInput(line, fileInfo.absolutePath()); + urls.append(item); + } + return loadPlaylist(urls); + } else { + return {}; + } +} + int PlaylistManager::totalCount() const { return m_model.rowCount(); diff --git a/app/playlistmanager.h b/app/playlistmanager.h index 2339409..6bc2aaf 100644 --- a/app/playlistmanager.h +++ b/app/playlistmanager.h @@ -61,6 +61,7 @@ public: void setPlaylist(const QList & url); Q_INVOKABLE QModelIndex loadPlaylist(const QList & urls); Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url); + Q_INVOKABLE QModelIndex loadM3U8Playlist(const QUrl & url); int totalCount() const; QModelIndex previousIndex() const;