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:
parent
c828f86b74
commit
2846e4907b
@ -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"));
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user