2
* \file tracktypeimporter.cpp
3
* TrackType.org importer.
9
* Copyright (C) 2007-2013 Urs Fleisch
11
* This file is part of Kid3.
13
* Kid3 is free software; you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation; either version 2 of the License, or
16
* (at your option) any later version.
18
* Kid3 is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include "tracktypeimporter.h"
28
#include "serverimporterconfig.h"
29
#include "freedbconfig.h"
32
static const char trackTypeServer[] = "tracktype.org:80";
37
* @param netMgr network access manager
38
* @param trackDataModel track data to be filled with imported values
40
TrackTypeImporter::TrackTypeImporter(QNetworkAccessManager* netMgr,
41
TrackDataModel *trackDataModel) :
42
FreedbImporter(netMgr, trackDataModel)
44
setObjectName(QLatin1String("TrackTypeImporter"));
50
TrackTypeImporter::~TrackTypeImporter()
55
* Name of import source.
58
const char* TrackTypeImporter::name() const {
59
return QT_TRANSLATE_NOOP("@default", "TrackType.org");
62
/** NULL-terminated array of server strings, 0 if not used */
63
const char** TrackTypeImporter::serverList() const
65
static const char* servers[] = {
72
/** default server, 0 to disable */
73
const char* TrackTypeImporter::defaultServer() const { return "tracktype.org:80"; }
75
/** configuration, 0 if not used */
76
ServerImporterConfig* TrackTypeImporter::config() const { return &TrackTypeConfig::instance(); }
79
* Process finished findCddbAlbum request.
81
* @param searchStr search data received
83
void TrackTypeImporter::parseFindResults(const QByteArray& searchStr)
86
210 exact matches found
91
211 close matches found
92
rock 920b810c Catharsis / Imago
94
theoretically, but never seen
95
200 categ discid dtitle
97
QString str = QString::fromUtf8(searchStr);
98
QRegExp catIdTitleRe(QLatin1String("([a-z]+)\\s+([0-9a-f]+)\\s+([^/]+ / .+)"));
99
QStringList lines = str.split(QRegExp(QLatin1String("[\\r\\n]+")));
100
bool inEntries = false;
101
m_albumListModel->clear();
102
for (QStringList::const_iterator it = lines.begin(); it != lines.end(); ++it) {
103
if (*it == QLatin1String(".")) {
107
if (catIdTitleRe.exactMatch(*it)) {
108
m_albumListModel->appendRow(new AlbumListItem(
111
catIdTitleRe.cap(2)));
114
if ((*it).startsWith(QLatin1String("21")) && (*it).indexOf(QLatin1String(" match")) != -1) {
116
} else if ((*it).startsWith(QLatin1String("200 "))) {
117
if (catIdTitleRe.exactMatch((*it).mid(4))) {
118
m_albumListModel->appendRow(new AlbumListItem(
121
catIdTitleRe.cap(2)));
129
* Send a query command to search on the server.
131
* @param cfg import source configuration
132
* @param artist artist to search
133
* @param album album to search
135
void TrackTypeImporter::sendFindQuery(
136
const ServerImporterConfig* cfg,
137
const QString& artist, const QString& album)
139
// At the moment, only TrackType.org recognizes cddb album commands,
140
// so we always use this server for find queries.
141
sendRequest(QString::fromLatin1(trackTypeServer),
142
cfg->m_cgiPath + QLatin1String("?cmd=cddb+album+") +
143
encodeUrlQuery(artist + QLatin1String(" / ") + album) +
144
QLatin1String("&hello=noname+localhost+Kid3+" VERSION "&proto=6"));