diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-10-31 20:16:49 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-10-31 20:16:49 +0000 |
| commit | 7ac7b86f7c85118e917cc1822508171d4541dee5 (patch) | |
| tree | 644830eb537ba81c4a706a541f6f8edf18f363a6 /src | |
| parent | 793a032bbba9ab1a3d3917206c54dd4e136abbc8 (diff) | |
| download | qmmp-7ac7b86f7c85118e917cc1822508171d4541dee5.tar.gz qmmp-7ac7b86f7c85118e917cc1822508171d4541dee5.tar.bz2 qmmp-7ac7b86f7c85118e917cc1822508171d4541dee5.zip | |
optimized cue parser
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1345 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/Input/cue/cueparser.cpp | 79 | ||||
| -rw-r--r-- | src/plugins/Input/cue/cueparser.h | 1 |
2 files changed, 32 insertions, 48 deletions
diff --git a/src/plugins/Input/cue/cueparser.cpp b/src/plugins/Input/cue/cueparser.cpp index ba4305bfc..b8b9cb7ff 100644 --- a/src/plugins/Input/cue/cueparser.cpp +++ b/src/plugins/Input/cue/cueparser.cpp @@ -37,13 +37,13 @@ CUEParser::CUEParser(const QString &fileName) qDebug("CUEParser: error: %s", qPrintable(file.errorString())); return; } - QString album, genre, date, comment; QTextStream textStream (&file); QSettings settings(Qmmp::configFile(), QSettings::IniFormat); QTextCodec *codec = QTextCodec::codecForName(settings.value("CUE/encoding","ISO-8859-1").toByteArray ()); textStream.setCodec(codec); - QString artist; - bool skip_index = FALSE; + QString album, genre, date, comment, artist, file_path; + bool new_file = FALSE; + while (!textStream.atEnd()) { QString line = textStream.readLine().trimmed(); @@ -53,23 +53,29 @@ CUEParser::CUEParser(const QString &fileName) if (words[0] == "FILE") { - m_filePath = QFileInfo(fileName).dir().filePath(words[1]); - skip_index = TRUE; + if(!m_infoList.isEmpty()) + { + QList <FileInfo *> f_list = MetaDataManager::instance()->createPlayList(file_path, FALSE); + qint64 l = f_list.isEmpty() ? 0 : f_list.at(0)->length() * 1000; + if (l > m_offsets.last()) + m_infoList.last().setLength(l - m_offsets.last()); + else + m_infoList.last().setLength(0); + } + file_path = QFileInfo(fileName).dir().filePath(words[1]); + new_file = TRUE; } + else if (words[0] == "PERFORMER") { - if (m_infoList.isEmpty()) - { + if(m_infoList.isEmpty()) artist = words[1]; - continue; - } else m_infoList.last().setMetaData(Qmmp::ARTIST, words[1]); - } else if (words[0] == "TITLE") { - if (m_infoList.isEmpty()) + if(m_infoList.isEmpty()) album = words[1]; else m_infoList.last().setMetaData(Qmmp::TITLE, words[1]); @@ -82,18 +88,24 @@ CUEParser::CUEParser(const QString &fileName) path.replace("?", QString(QUrl::toPercentEncoding("?"))); FileInfo info("cue://" + path + QString("#%1").arg(words[1].toInt())); info.setMetaData(Qmmp::TRACK, words[1].toInt()); + info.setMetaData(Qmmp::ALBUM, album); + info.setMetaData(Qmmp::GENRE, genre); + info.setMetaData(Qmmp::YEAR, date); + info.setMetaData(Qmmp::COMMENT, comment); + info.setMetaData(Qmmp::ARTIST, artist); m_infoList << info; m_offsets << 0; - m_files << m_filePath; - skip_index = FALSE; + m_files << file_path; } - else if (words[0] == "INDEX") + else if (words[0] == "INDEX" && words[1] == "01") { - if (m_infoList.isEmpty() || skip_index) + if (m_infoList.isEmpty()) continue; - m_infoList.last ().setLength(getLength(words[2])); m_offsets.last() = getLength(words[2]); - skip_index = (words[1] == "01"); //use 01 index only + int c = m_infoList.count(); + if(c > 1 && !new_file) + m_infoList[c - 2].setLength(m_offsets[c - 1] - m_offsets[c - 2]); + new_file = FALSE; } else if (words[0] == "REM") { @@ -107,43 +119,16 @@ CUEParser::CUEParser(const QString &fileName) comment = words[2]; } } - //calculate length - for (int i = 0; i < m_infoList.size() - 1; ++i) - { - if (m_files[i+1] == m_files[i]) - m_infoList[i].setLength(m_infoList[i+1].length() - m_infoList[i].length()); - else - { - QList <FileInfo *> f_list = MetaDataManager::instance()->createPlayList(m_files[i], FALSE); - qint64 l = f_list.isEmpty() ? 0 : f_list.at(0)->length() * 1000; - if (l > m_infoList[i].length()) - m_infoList[i].setLength(l - m_infoList[i].length()); - else - m_infoList[i].setLength(0); - } - } - //calculate last item length - QList <FileInfo *> f_list = MetaDataManager::instance()->createPlayList(m_filePath, FALSE); + QList <FileInfo *> f_list = MetaDataManager::instance()->createPlayList(file_path, FALSE); qint64 l = f_list.isEmpty() ? 0 : f_list.at(0)->length() * 1000; - if (l > m_infoList.last().length()) - m_infoList.last().setLength(l - m_infoList.last().length()); + if (l > m_offsets.last()) + m_infoList.last().setLength(l - m_offsets.last()); else m_infoList.last().setLength(0); - - for (int i = 0; i < m_infoList.size(); ++i) - { - m_infoList[i].setMetaData(Qmmp::ALBUM, album); - m_infoList[i].setMetaData(Qmmp::GENRE, genre); - m_infoList[i].setMetaData(Qmmp::YEAR, date); - m_infoList[i].setMetaData(Qmmp::COMMENT, comment); - if (!m_infoList[i].metaData().count(Qmmp::ARTIST) && !artist.isEmpty()) - m_infoList[i].setMetaData(Qmmp::ARTIST, artist); - } file.close(); } - CUEParser::~CUEParser() { } diff --git a/src/plugins/Input/cue/cueparser.h b/src/plugins/Input/cue/cueparser.h index 3dc4f60e9..cdf943127 100644 --- a/src/plugins/Input/cue/cueparser.h +++ b/src/plugins/Input/cue/cueparser.h @@ -48,7 +48,6 @@ public: const QString trackURL(int track); private: - QString m_filePath; QList <FileInfo> m_infoList; QList <qint64> m_offsets; QStringList m_files; |
