feat: support load m3u8 playlist

This change is sponsored by @superuser7777

Related: https://github.com/BLumia/pineapple-pictures/issues/153
This commit is contained in:
Gary Wang 2025-06-28 09:27:30 +08:00
parent c828f86b74
commit 2846e4907b
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
3 changed files with 31 additions and 1 deletions

View File

@ -175,7 +175,16 @@ MainWindow::~MainWindow()
void MainWindow::showUrls(const QList<QUrl> &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"));

View File

@ -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<QUrl> 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();

View File

@ -61,6 +61,7 @@ public:
void setPlaylist(const QList<QUrl> & url);
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
Q_INVOKABLE QModelIndex loadM3U8Playlist(const QUrl & url);
int totalCount() const;
QModelIndex previousIndex() const;