diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-02-04 17:49:16 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-02-04 17:49:16 +0000 |
| commit | b26977973942e1ee88e9e52c547615a853548eec (patch) | |
| tree | ac8d463e8de5c3d316eddd624b94653fea4ed48b /src | |
| parent | 072b64d7a7a8cf869c67af7aba8e6f2f9726c0bc (diff) | |
| download | qmmp-b26977973942e1ee88e9e52c547615a853548eec.tar.gz qmmp-b26977973942e1ee88e9e52c547615a853548eec.tar.bz2 qmmp-b26977973942e1ee88e9e52c547615a853548eec.zip | |
updated embedded cue parsers
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1547 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/Input/flac/cueparser.cpp | 52 | ||||
| -rw-r--r-- | src/plugins/Input/wavpack/cueparser.cpp | 51 |
2 files changed, 42 insertions, 61 deletions
diff --git a/src/plugins/Input/flac/cueparser.cpp b/src/plugins/Input/flac/cueparser.cpp index 75b538bcf..16682dd25 100644 --- a/src/plugins/Input/flac/cueparser.cpp +++ b/src/plugins/Input/flac/cueparser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Ilya Kotov * + * Copyright (C) 2008-2010 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -20,9 +20,7 @@ #include <QTextStream> #include <QTextCodec> - #include <qmmp/metadatamanager.h> - #include "cueparser.h" CUEParser::CUEParser(const QByteArray &array, const QString &fileName) @@ -32,7 +30,6 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) textStream.setCodec("UTF-8"); m_filePath = fileName; QString artist; - bool skip_index = FALSE; while (!textStream.atEnd()) { QString line = textStream.readLine().trimmed(); @@ -42,18 +39,14 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) 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]); @@ -66,17 +59,22 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) path.replace("?", QString(QUrl::toPercentEncoding("?"))); FileInfo info("flac://" + 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; - skip_index = FALSE; } - else if (words[0] == "INDEX") + else if (words[0] == "INDEX" && words[1] == "01") { - if (m_infoList.isEmpty() || skip_index) - continue; - m_infoList.last ().setLength(getLength(words[2])); + if (m_infoList.isEmpty()) + continue; m_offsets.last() = getLength(words[2]); - skip_index = (words[1] == "01"); //use 01 index only + int c = m_infoList.count(); + if(c > 1) + m_infoList[c - 2].setLength(m_offsets[c - 1] - m_offsets[c - 2]); } else if (words[0] == "REM") { @@ -90,26 +88,18 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) comment = words[2]; } } - //calculate length - for (int i = 0; i < m_infoList.size() - 1; ++i) - m_infoList[i].setLength(m_infoList[i+1].length() - m_infoList[i].length()); + if(m_infoList.isEmpty()) + { + qWarning("CUEParser: invalid cue file"); + return; + } //calculate last item length QList <FileInfo *> f_list = MetaDataManager::instance()->createPlayList(m_filePath, 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); - } } diff --git a/src/plugins/Input/wavpack/cueparser.cpp b/src/plugins/Input/wavpack/cueparser.cpp index cf63e41a1..00ce3d688 100644 --- a/src/plugins/Input/wavpack/cueparser.cpp +++ b/src/plugins/Input/wavpack/cueparser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Ilya Kotov * + * Copyright (C) 2008-2010 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -30,7 +30,6 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) textStream.setCodec("UTF-8"); m_filePath = fileName; QString artist; - bool skip_index = FALSE; while (!textStream.atEnd()) { QString line = textStream.readLine().trimmed(); @@ -40,18 +39,14 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) 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]); @@ -64,17 +59,22 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) path.replace("?", QString(QUrl::toPercentEncoding("?"))); FileInfo info("wvpack://" + 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; - skip_index = FALSE; } - else if (words[0] == "INDEX") + else if (words[0] == "INDEX" && words[1] == "01") { - if (m_infoList.isEmpty() || skip_index) - continue; - m_infoList.last ().setLength(getLength(words[2])); + if (m_infoList.isEmpty()) + continue; m_offsets.last() = getLength(words[2]); - skip_index = (words[1] == "01"); //use 01 index only + int c = m_infoList.count(); + if(c > 1) + m_infoList[c - 2].setLength(m_offsets[c - 1] - m_offsets[c - 2]); } else if (words[0] == "REM") { @@ -88,29 +88,20 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName) comment = words[2]; } } - //calculate length - for (int i = 0; i < m_infoList.size() - 1; ++i) - m_infoList[i].setLength(m_infoList[i+1].length() - m_infoList[i].length()); + if(m_infoList.isEmpty()) + { + qWarning("CUEParser: invalid cue file"); + return; + } //calculate last item length QList <FileInfo *> f_list = MetaDataManager::instance()->createPlayList(m_filePath, 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); - } } - CUEParser::~CUEParser() { } |
