MCPcopy Create free account
hub / github.com/blizzard4591/openMittsu / parseLineImpl

Method parseLineImpl

src/widgets/player/QPlaylistFileParser.cpp:95–145  ·  view source on GitHub ↗

* Extended M3U directives #EXTM3U - header - must be first line of file #EXTINF - extra info - length (seconds), title #EXTINF - extra info - length (seconds), artist '-' title Example #EXTM3U #EXTINF:123, Sample artist - Sample title C:\Documents and Settings\I\My Music\Sample.mp3 #EXTINF:321,Example Artist - Example title C:\Documents and Settings\I\My

Source from the content-addressed store, hash-verified

93
94 */
95 bool parseLineImpl(int lineIndex, const QString &line, const QUrl &root) override
96 {
97 if (line[0] == u'#') {
98 if (m_extendedFormat) {
99 if (line.startsWith(QLatin1String("#EXTINF:"))) {
100 m_extraInfo.clear();
101 int artistStart = line.indexOf(QLatin1String(","), 8);
102 bool ok = false;
103 QStringView lineView{ line };
104 int length = lineView.mid(8, artistStart < 8 ? -1 : artistStart - 8)
105 .trimmed()
106 .toInt(&ok);
107 if (ok && length > 0) {
108 // convert from second to milisecond
109 m_extraInfo[QMediaMetaData::Duration] = QVariant(length * 1000);
110 }
111 if (artistStart > 0) {
112 int titleStart = getSplitIndex(line, artistStart);
113 if (titleStart > artistStart) {
114 m_extraInfo[QMediaMetaData::Author] =
115 lineView.mid(artistStart + 1, titleStart - artistStart - 1)
116 .trimmed()
117 .toString()
118 .replace(QLatin1String("--"), QLatin1String("-"));
119 m_extraInfo[QMediaMetaData::Title] =
120 lineView.mid(titleStart + 1)
121 .trimmed()
122 .toString()
123 .replace(QLatin1String("--"), QLatin1String("-"));
124 } else {
125 m_extraInfo[QMediaMetaData::Title] =
126 lineView.mid(artistStart + 1)
127 .trimmed()
128 .toString()
129 .replace(QLatin1String("--"), QLatin1String("-"));
130 }
131 }
132 }
133 } else if (lineIndex == 0 && line.startsWith(QLatin1String("#EXTM3U"))) {
134 m_extendedFormat = true;
135 }
136 } else {
137 QUrl url = expandToFullPath(root, line);
138 m_extraInfo[QMediaMetaData::Url] = url;
139 m_parent->playlist.append(url);
140 newItemFound(QVariant::fromValue(m_extraInfo));
141 m_extraInfo.clear();
142 }
143
144 return true;
145 }
146
147 int getSplitIndex(const QString &line, int startPos)
148 {

Callers

nothing calls this directly

Calls 3

clearMethod · 0.45
toIntMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected