~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to src/plugins/freedbimport/tracktypeimporter.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell, Patrick Matthäi, Mark Purcell
  • Date: 2013-11-30 15:44:59 UTC
  • mfrom: (1.1.16) (2.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20131130154459-s6lpalx8yy2zq7gx
Tags: 3.0.2-1
* New upstream release 

[ Patrick Matthäi ]
* New upstream release.
  - Add new libreadline-dev build dependency.
* Don't explicitly request xz compression - dpkg 1.17 does this by default.
* Bump Standards-Version to 3.9.5 (no changes needed).
* Fix Vcs-Browser control field.

[ Mark Purcell ]
* Switch to dh - reduce debian/rules bloat
* kid3 Replaces kid3-qt - low popcon, reduce archive bloat
* Fix vcs-field-not-canonical
* debian/compat -> 9
* Update Description:

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file tracktypeimporter.cpp
 
3
 * TrackType.org importer.
 
4
 *
 
5
 * \b Project: Kid3
 
6
 * \author Urs Fleisch
 
7
 * \date 26 Apr 2007
 
8
 *
 
9
 * Copyright (C) 2007-2013  Urs Fleisch
 
10
 *
 
11
 * This file is part of Kid3.
 
12
 *
 
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.
 
17
 *
 
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.
 
22
 *
 
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/>.
 
25
 */
 
26
 
 
27
#include "tracktypeimporter.h"
 
28
#include "serverimporterconfig.h"
 
29
#include "freedbconfig.h"
 
30
#include "config.h"
 
31
 
 
32
static const char trackTypeServer[] = "tracktype.org:80";
 
33
 
 
34
/**
 
35
 * Constructor.
 
36
 *
 
37
 * @param netMgr network access manager
 
38
 * @param trackDataModel track data to be filled with imported values
 
39
 */
 
40
TrackTypeImporter::TrackTypeImporter(QNetworkAccessManager* netMgr,
 
41
                                     TrackDataModel *trackDataModel) :
 
42
  FreedbImporter(netMgr, trackDataModel)
 
43
{
 
44
  setObjectName(QLatin1String("TrackTypeImporter"));
 
45
}
 
46
 
 
47
/**
 
48
 * Destructor.
 
49
 */
 
50
TrackTypeImporter::~TrackTypeImporter()
 
51
{
 
52
}
 
53
 
 
54
/**
 
55
 * Name of import source.
 
56
 * @return name.
 
57
 */
 
58
const char* TrackTypeImporter::name() const {
 
59
  return QT_TRANSLATE_NOOP("@default", "TrackType.org");
 
60
}
 
61
 
 
62
/** NULL-terminated array of server strings, 0 if not used */
 
63
const char** TrackTypeImporter::serverList() const
 
64
{
 
65
  static const char* servers[] = {
 
66
    "tracktype.org:80",
 
67
    0                  // end of StrList
 
68
  };
 
69
  return servers;
 
70
}
 
71
 
 
72
/** default server, 0 to disable */
 
73
const char* TrackTypeImporter::defaultServer() const { return "tracktype.org:80"; }
 
74
 
 
75
/** configuration, 0 if not used */
 
76
ServerImporterConfig* TrackTypeImporter::config() const { return &TrackTypeConfig::instance(); }
 
77
 
 
78
/**
 
79
 * Process finished findCddbAlbum request.
 
80
 *
 
81
 * @param searchStr search data received
 
82
 */
 
83
void TrackTypeImporter::parseFindResults(const QByteArray& searchStr)
 
84
{
 
85
/*
 
86
210 exact matches found
 
87
categ discid dtitle
 
88
(more matches...)
 
89
.
 
90
or
 
91
211 close matches found
 
92
rock 920b810c Catharsis / Imago
 
93
.
 
94
theoretically, but never seen
 
95
200 categ discid dtitle
 
96
*/
 
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(".")) {
 
104
      break;
 
105
    }
 
106
    if (inEntries) {
 
107
      if (catIdTitleRe.exactMatch(*it)) {
 
108
        m_albumListModel->appendRow(new AlbumListItem(
 
109
          catIdTitleRe.cap(3),
 
110
          catIdTitleRe.cap(1),
 
111
          catIdTitleRe.cap(2)));
 
112
      }
 
113
    } else {
 
114
      if ((*it).startsWith(QLatin1String("21")) && (*it).indexOf(QLatin1String(" match")) != -1) {
 
115
        inEntries = true;
 
116
      } else if ((*it).startsWith(QLatin1String("200 "))) {
 
117
        if (catIdTitleRe.exactMatch((*it).mid(4))) {
 
118
          m_albumListModel->appendRow(new AlbumListItem(
 
119
            catIdTitleRe.cap(3),
 
120
            catIdTitleRe.cap(1),
 
121
            catIdTitleRe.cap(2)));
 
122
        }
 
123
      }
 
124
    }
 
125
  }
 
126
}
 
127
 
 
128
/**
 
129
 * Send a query command to search on the server.
 
130
 *
 
131
 * @param cfg      import source configuration
 
132
 * @param artist   artist to search
 
133
 * @param album    album to search
 
134
 */
 
135
void TrackTypeImporter::sendFindQuery(
 
136
  const ServerImporterConfig* cfg,
 
137
  const QString& artist, const QString& album)
 
138
{
 
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"));
 
145
}