PageRenderTime 203ms CodeModel.GetById 100ms app.highlight 5ms RepoModel.GetById 96ms app.codeStats 0ms

/thirdparty/liblastfm2/src/types/FingerprintId.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 55 lines | 29 code | 7 blank | 19 comment | 2 complexity | 439a0092ea1d6de5f2a68fc50a8100f8 MD5 | raw file
 1/*
 2   Copyright 2009 Last.fm Ltd. 
 3      - Primarily authored by Max Howell, Jono Cole and Doug Mansell
 4
 5   This file is part of liblastfm.
 6
 7   liblastfm is free software: you can redistribute it and/or modify
 8   it under the terms of the GNU General Public License as published by
 9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   liblastfm is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19*/
20#include "FingerprintId.h"
21#include "../ws/ws.h"
22#include <QtNetwork>
23#include <QtXml>
24 
25
26QNetworkReply*
27lastfm::FingerprintId::getSuggestions() const
28{
29    if (isNull()) return 0;
30    
31    QUrl const url( "http://ws.audioscrobbler.com/fingerprint/" + QString(*this) + ".xml" );
32    QNetworkRequest const request( url );
33    return lastfm::nam()->get( request );
34}
35
36
37QMap<float, lastfm::Track> //static
38lastfm::FingerprintId::getSuggestions( QNetworkReply* reply )
39{
40    QDomDocument xml;
41    xml.setContent( reply->readAll() );
42    QDomNodeList nodes = xml.documentElement().elementsByTagName( "track" );
43    
44    QMap<float, Track> tracks;
45    for (int x = 0; x < nodes.count(); ++x)
46    {
47        QDomElement const e = nodes.at(x).toElement();
48
49        MutableTrack t;
50        t.setTitle( e.firstChildElement( "title" ).text() );
51        t.setArtist( e.firstChildElement( "artist" ).text() );
52        tracks.insert( e.attribute( "confidence", "0.0" ).toFloat(), t );
53    }
54    return tracks;
55}