-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm3uparser.cpp
More file actions
61 lines (51 loc) · 1.45 KB
/
m3uparser.cpp
File metadata and controls
61 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "m3uparser.h"
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>
M3uParser::M3uParser(const QString& playlistPath) :
_playlistPath(playlistPath)
{
}
QStringList* M3uParser::parse()
{
QStringList* paths = new QStringList;
QDir baseDir = QFileInfo(_playlistPath).dir();
QFile file(_playlistPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return nullptr;
}
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine();
// Drop lines from extended M3U files
if (line.startsWith("#EXTM3U") || line.startsWith("#EXTINF"))
{
continue;
}
// Unix only (for now): add absolute paths to the path list, and try to
// resolve relative paths in the playlist file to absolute paths. Those
// are then also added to the path list, yay!
//
// Patches for Windows welcome.
#ifdef Q_OS_WIN
#error "Unfortunately, I have not implemented support for relative paths in playlists for the Windows platform. Patches welcome!"
#endif
if (line.startsWith("/"))
{
if (QFile::exists(line))
{
paths->append(line);
}
continue;
}
auto absolutePath = baseDir.filePath(line);
if (QFile::exists(absolutePath))
{
paths->append(absolutePath);
}
}
return paths;
}