~ubuntu-branches/ubuntu/karmic/kid3/karmic

« back to all changes in this revision

Viewing changes to kid3/discogsclient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2009-05-20 16:12:30 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20090520161230-qetp532r8ydujkz2
Tags: upstream-1.2
Import upstream version 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * \author Urs Fleisch
7
7
 * \date 13 Oct 2006
8
8
 *
9
 
 * Copyright (C) 2006-2007  Urs Fleisch
 
9
 * Copyright (C) 2006-2009  Urs Fleisch
10
10
 *
11
11
 * This file is part of Kid3.
12
12
 *
26
26
 
27
27
#include "discogsclient.h"
28
28
#include "importsourceconfig.h"
29
 
#include <qregexp.h>
30
 
#include <qurl.h>
31
29
 
32
30
static const char discogsServer[] = "www.discogs.com:80";
33
31
 
46
44
}
47
45
 
48
46
/**
49
 
 * Construct a query command in m_request to search on the server.
 
47
 * Send a query command to search on the server.
50
48
 *
51
49
 * @param cfg      import source configuration
52
50
 * @param artist   artist to search
53
51
 * @param album    album to search
54
 
 * @param dest     the server to connect to is returned here
55
 
 * @param destPort the port of the server is returned here
56
52
 */
57
 
void DiscogsClient::constructFindQuery(
 
53
void DiscogsClient::sendFindQuery(
58
54
        const ImportSourceConfig*,
59
 
        const QString& artist, const QString& album,
60
 
        QString& dest, int& destPort)
 
55
        const QString& artist, const QString& album)
61
56
{
62
57
        /*
63
58
         * Query looks like this:
64
59
         * http://www.discogs.com/search?type=releases&q=amon+amarth+avenger&btn=Search
65
60
         */
66
 
        QString server(discogsServer);
67
 
        QString what = artist + " " + album;
68
 
        QString destNamePort(getProxyOrDest(server));
69
 
        splitNamePort(destNamePort, dest, destPort);
70
 
        QString serverName;
71
 
        int serverPort;
72
 
        splitNamePort(server, serverName, serverPort);
73
 
        what.replace(QRegExp(" +"), " "); // collapse spaces
74
 
        QCM_QUrl_encode(what);
75
 
        what.replace("%20", "+"); // replace spaces by '+'
76
 
        m_request = "GET ";
77
 
        if (dest != serverName) {
78
 
                m_request += "http://";
79
 
                m_request += serverName;
80
 
                if (serverPort != 80) {
81
 
                        m_request += ':';
82
 
                        m_request += QString::number(serverPort);
83
 
                }
84
 
        }
85
 
        m_request += "/search?type=releases&q=";
86
 
        m_request += what;
87
 
        m_request += "&btn=Search HTTP/1.0\r\nUser-Agent: Kid3/" VERSION "\r\nHost: ";
88
 
        m_request += serverName;
89
 
        m_request += "\r\nConnection: close\r\n\r\n";
 
61
        sendRequest(discogsServer,
 
62
                                                        QString("/search?type=releases&q=") +
 
63
                                                        encodeUrlQuery(artist + " " + album) + "&btn=Search");
90
64
}
91
65
 
92
66
/**
93
 
 * Construct a query command in m_request to fetch the track list
 
67
 * Send a query command to fetch the track list
94
68
 * from the server.
95
69
 *
96
70
 * @param cfg      import source configuration
97
71
 * @param cat      category
98
72
 * @param id       ID
99
 
 * @param dest     the server to connect to is returned here
100
 
 * @param destPort the port of the server is returned here
101
73
 */
102
 
void DiscogsClient::constructTrackListQuery(
103
 
        const ImportSourceConfig*, const QString& cat, const QString& id,
104
 
        QString& dest, int& destPort)
 
74
void DiscogsClient::sendTrackListQuery(
 
75
        const ImportSourceConfig*, const QString& cat, const QString& id)
105
76
{
106
77
        /*
107
78
         * Query looks like this:
108
79
         * http://www.discogs.com/release/761529
109
80
         */
110
 
        QString server(discogsServer);
111
 
        QString destNamePort(getProxyOrDest(server));
112
 
        splitNamePort(destNamePort, dest, destPort);
113
 
        QString serverName;
114
 
        int serverPort;
115
 
        splitNamePort(server, serverName, serverPort);
116
 
        m_request = "GET ";
117
 
        if (dest != serverName) {
118
 
                m_request += "http://";
119
 
                m_request += serverName;
120
 
                if (serverPort != 80) {
121
 
                        m_request += ':';
122
 
                        m_request += QString::number(serverPort);
123
 
                }
124
 
        }
125
 
        m_request += '/';
126
 
        m_request += cat;
127
 
        m_request += '/';
128
 
        m_request += id;
129
 
        m_request += " HTTP/1.0\r\nUser-Agent: Kid3/" VERSION "\r\nHost: ";
130
 
        m_request += serverName;
131
 
        m_request += "\r\nConnection: close\r\n\r\n";
 
81
        sendRequest(discogsServer, QString("/") + cat + '/' + id);
132
82
}