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

« back to all changes in this revision

Viewing changes to kid3/musicbrainzreleaseclient.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 "musicbrainzreleaseclient.h"
28
28
#include "importsourceconfig.h"
29
 
#include <qregexp.h>
30
 
#include <qurl.h>
31
29
 
32
30
/**
33
31
 * Constructor.
44
42
}
45
43
 
46
44
/**
47
 
 * Construct a query command in m_request to search on the server.
 
45
 * Send a query command to search on the server.
48
46
 *
49
47
 * @param cfg      import source configuration
50
48
 * @param artist   artist to search
51
49
 * @param album    album to search
52
 
 * @param dest     the server to connect to is returned hera
53
 
 * @param destPort the port of the server is returned here
54
50
 */
55
 
void MusicBrainzReleaseClient::constructFindQuery(
 
51
void MusicBrainzReleaseClient::sendFindQuery(
56
52
        const ImportSourceConfig* cfg,
57
 
        const QString& artist, const QString& album,
58
 
        QString& dest, int& destPort)
 
53
        const QString& artist, const QString& album)
59
54
{
60
55
        /*
61
56
         * Query looks like this:
62
57
         * http://musicbrainz.org/ws/1/release/?type=xml&artist=wizard&title=odin
63
58
         */
64
 
        QString destNamePort(getProxyOrDest(cfg->m_server));
65
 
        splitNamePort(destNamePort, dest, destPort);
66
 
        QString serverName;
67
 
        int serverPort;
68
 
        splitNamePort(cfg->m_server, serverName, serverPort);
69
 
        QString encArtist(artist);
70
 
        encArtist.replace(QRegExp(" +"), " "); // collapse spaces
71
 
        QCM_QUrl_encode(encArtist);
72
 
        encArtist.replace("%20", "+"); // replace spaces by '+'
73
 
        QString encAlbum(album);
74
 
        encAlbum.replace(QRegExp(" +"), " "); // collapse spaces
75
 
        QCM_QUrl_encode(encAlbum);
76
 
        encAlbum.replace("%20", "+"); // replace spaces by '+'
77
 
        m_request = "GET ";
78
 
        if (dest != serverName) {
79
 
                m_request += "http://";
80
 
                m_request += serverName;
81
 
                if (serverPort != 80) {
82
 
                        m_request += ':';
83
 
                        m_request += QString::number(serverPort);
84
 
                }
85
 
        }
86
 
        m_request += "/ws/1/release/?type=xml&artist=";
87
 
        m_request += encArtist;
88
 
        m_request += "&title=";
89
 
        m_request += encAlbum;
90
 
        m_request += " HTTP/1.1\r\nUser-Agent: Kid3/" VERSION "\r\nHost: ";
91
 
        m_request += serverName;
92
 
        m_request += "\r\nConnection: close\r\n\r\n";
 
59
        sendRequest(cfg->m_server,
 
60
                                                        QString("/ws/1/release/?type=xml&artist=") +
 
61
                                                        encodeUrlQuery(artist) +
 
62
                                                        "&title=" + encodeUrlQuery(album));
93
63
}
94
64
 
95
65
/**
96
 
 * Construct a query command in m_request to fetch the track list
 
66
 * Send a query command to fetch the track list
97
67
 * from the server.
98
68
 *
99
69
 * @param cfg      import source configuration
100
70
 * @param cat      category
101
71
 * @param id       ID
102
 
 * @param dest     the server to connect to is returned hera
103
 
 * @param destPort the port of the server is returned here
104
72
 */
105
 
void MusicBrainzReleaseClient::constructTrackListQuery(
106
 
        const ImportSourceConfig* cfg, const QString& cat, const QString& id,
107
 
        QString& dest, int& destPort)
 
73
void MusicBrainzReleaseClient::sendTrackListQuery(
 
74
        const ImportSourceConfig* cfg, const QString& cat, const QString& id)
108
75
{
109
76
        /*
110
77
         * Query looks like this:
111
78
         * http://musicbrainz.org/ws/1/release/978c7ed1-a854-4ef2-bd4e-e7c1317be854/?type=xml&inc=artist+tracks
112
79
         */
113
 
        QString destNamePort(getProxyOrDest(cfg->m_server));
114
 
        splitNamePort(destNamePort, dest, destPort);
115
 
        QString serverName;
116
 
        int serverPort;
117
 
        splitNamePort(cfg->m_server, serverName, serverPort);
118
 
        m_request = "GET ";
119
 
        if (dest != serverName) {
120
 
                m_request += "http://";
121
 
                m_request += serverName;
122
 
                if (serverPort != 80) {
123
 
                        m_request += ':';
124
 
                        m_request += QString::number(serverPort);
125
 
                }
126
 
        }
127
 
        m_request += "/ws/1/";
128
 
        m_request += cat;
129
 
        m_request += '/';
130
 
        m_request += id;
131
 
        m_request += "/?type=xml&inc=artist+tracks";
 
80
        QString path("/ws/1/");
 
81
        path += cat;
 
82
        path += '/';
 
83
        path += id;
 
84
        path += "/?type=xml&inc=artist+tracks";
132
85
        if (cfg->m_additionalTags) {
133
 
                m_request += "+release-events+artist-rels+release-rels+track-rels+"
 
86
                path += "+release-events+artist-rels+release-rels+track-rels+"
134
87
                        "track-level-rels+labels";
135
88
        }
136
 
        m_request += " HTTP/1.1\r\nUser-Agent: Kid3/" VERSION "\r\nHost: ";
137
 
        m_request += serverName;
138
 
        m_request += "\r\nConnection: close\r\n\r\n";
 
89
        if (cfg->m_coverArt) {
 
90
                path += "+url-rels";
 
91
        }
 
92
        sendRequest(cfg->m_server, path);
139
93
}