14#include <QDomDocument>
19#include <QRegularExpression>
37 QString extension = QFileInfo(
filename).suffix().toLower();
39 if (extension ==
"pls")
41 else if (extension ==
"m3u")
43 else if (extension ==
"asx")
51 LOG(VB_FILE, LOG_DEBUG, QString(
"DecoderHandler: parsePLS - '%1'").arg(
filename));
53 QSettings settings(
filename, QSettings::IniFormat);
56 QStringList groups = settings.childGroups();
58 if (groups.contains(
"playlist"))
60 settings.beginGroup(
"playlist");
62 else if (groups.contains(
"Playlist"))
64 settings.beginGroup(
"Playlist");
68 LOG(VB_GENERAL, LOG_ERR, QString(
"DecoderHandler: parsePLS - playlist group not found"));
75 QStringList keys = settings.childKeys();
77 if (keys.contains(
"numberofentries"))
79 num_entries = settings.value(
"numberofentries", -1).toInt();
81 else if (keys.contains(
"NumberOfEntries"))
83 num_entries = settings.value(
"NumberOfEntries", -1).toInt();
87 LOG(VB_GENERAL, LOG_ERR, QString(
"DecoderHandler: parsePLS - NumberOfEntries key not found"));
91 for (
int n = 1; n <= num_entries; n++)
94 QString t_key = QString(
"Title%1").arg(n);
95 QString f_key = QString(
"File%1").arg(n);
96 QString l_key = QString(
"Length%1").arg(n);
98 e->setFile(settings.value(f_key).toString());
99 e->setTitle(settings.value(t_key).toString());
100 e->setLength(settings.value(l_key).toInt());
109static constexpr const char*
M3U_INFO {
"#EXTINF" };
114 if (!f.open(QIODevice::ReadOnly))
117 QTextStream stream(&f);
118 QString data = stream.readAll();
119 static const QRegularExpression kNewlineRE {
"\\R" };
120 QStringList lines = data.split(kNewlineRE);
122 QStringList::iterator it;
123 for (it = lines.begin(); it != lines.end(); ++it)
151 QDomDocument doc(
"mydocument");
153 if (!
file.open(QIODevice::ReadOnly))
156 if (!doc.setContent(&
file))
164 QDomNodeList entryList = doc.elementsByTagName(
"Entry");
167 for (
int x = 0; x < entryList.count(); x++)
169 QDomNode n = entryList.item(x);
170 QDomElement elem = n.toElement();
171 QDomNodeList refList = elem.elementsByTagName(
"ref");
172 for (
int y = 0; y < refList.count(); y++)
174 QDomNode n2 = refList.item(y);
175 QDomElement elem2 = n2.toElement();
178 url = elem2.attribute(
"href");
182 e->setFile(url.replace(
"mms://",
"mmsh://"));
183 e->setTitle(url.replace(
"mms://",
"mmsh://"));
Class for representing entries in a pls file.
Class for containing the info of a pls or m3u file.
static int parsePLS(PlayListFile *pls, const QString &filename)
Parse a pls file.
void add(PlayListFileEntry *e)
Add a entry to the playlist.
static int parseASX(PlayListFile *pls, const QString &filename)
Parse a asx file.
static int parseM3U(PlayListFile *pls, const QString &filename)
Parse a m3u file.
void clear(void)
Clear out all the entries.
static int parse(PlayListFile *pls, const QString &filename)
Parse a pls, m3u or asx playlist file.
int size(void) const
Get the number of entries in the pls file.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static constexpr const char * M3U_INFO
static constexpr const char * M3U_HEADER