Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the Library class. Mainly for library.getArtists, but the other…

… things are there and might work, if someone were to use them.
  • Loading branch information...
commit 98fe8beeec563d9f2e3722682d49df84f275aabe 1 parent c041668
@eartle eartle authored
Showing with 211 additions and 2 deletions.
  1. +4 −2 lastfm.pro
  2. +154 −0 src/Library.cpp
  3. +53 −0 src/Library.h
View
6 lastfm.pro
@@ -84,7 +84,8 @@ SOURCES += \
src/UrlBuilder.cpp \
src/misc.cpp \
src/Chart.cpp \
- src/Auth.cpp
+ src/Auth.cpp \
+ src/Library.cpp
HEADERS += \
src/ws.h \
@@ -112,7 +113,8 @@ HEADERS += \
src/UrlBuilder.h \
src/misc.h \
src/Chart.h \
- src/Auth.h
+ src/Auth.h \
+ src/Library.h
win32:SOURCES += src/win/WNetworkConnectionMonitor_win.cpp \
src/win/WmiSink.cpp \
View
154 src/Library.cpp
@@ -0,0 +1,154 @@
+/*
+ Copyright 2011 Last.fm Ltd.
+ - Primarily authored by Michael Coffey
+
+ This file is part of liblastfm.
+
+ liblastfm is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ liblastfm is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <QNetworkReply>
+
+#include "ws.h"
+
+#include "Library.h"
+
+lastfm::Library::Library()
+{
+}
+
+QNetworkReply*
+lastfm::Library::addAlbum( const QList<lastfm::Album>& albums )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.addAlbum";
+
+ for ( int i = 0 ; i < albums.count() ; ++i )
+ {
+ map["artist[" + QString::number(i) + "]"] = albums[i].artist();
+ map["album[" + QString::number(i) + "]"] = albums[i].title();
+ }
+
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::addArtist( const QList<lastfm::Artist>& artists )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.addArtist";
+
+ for ( int i = 0 ; i < artists.count() ; ++i )
+ map["artist[" + QString::number(i) + "]"] = artists[i].name();
+
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::addTrack( const Track &track )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.addTrack";
+ map["track"] = track.title();
+ map["artist"] = track.artist().name();
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::getAlbums( const QString& user, const lastfm::Artist& artist, int limit, int page )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.getAlbums";
+ map["user"] = user;
+ map["artist"] = artist.name();
+ map["limit"] = QString::number( limit );
+ map["page"] = QString::number( page );
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::getArtists( const QString& user, int limit, int page )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.getArtists";
+ map["user"] = user;
+ map["limit"] = QString::number( limit );
+ map["page"] = QString::number( page );
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::getTracks( const QString& user, const lastfm::Artist& artist, int limit, int page )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.getTracks";
+ map["user"] = user;
+ map["artist"] = artist.name();
+ map["limit"] = QString::number( limit );
+ map["page"] = QString::number( page );
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::getTracks( const QString& user, const lastfm::Album& album, int limit, int page )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.getTracks";
+ map["user"] = user;
+ map["album"] = album.title();
+ map["artist"] = album.artist().name();
+ map["limit"] = QString::number( limit );
+ map["page"] = QString::number( page );
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::removeAlbum( const lastfm::Album& album )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.removeAlbum";
+ map["album"] = album.title();
+ map["artist"] = album.artist().name();
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::removeArtist( const lastfm::Artist& artist )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.removeArtist";
+ map["artist"] = artist.name();
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::removeTrack( const lastfm::Track& track )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.removeTrack";
+ map["artist"] = track.artist().name();
+ map["track"] = track.title();
+ return ws::get( map );
+}
+
+QNetworkReply*
+lastfm::Library::removeScrobble( const lastfm::Track& track )
+{
+ QMap<QString, QString> map;
+ map["method"] = "library.removeScrobble";
+ map["artist"] = track.artist().name();
+ map["track"] = track.title();
+ map["timestamp"] = QString::number( track.timestamp().toTime_t() );
+ return ws::get( map );
+}
+
View
53 src/Library.h
@@ -0,0 +1,53 @@
+/*
+ Copyright 2011 Last.fm Ltd.
+ - Primarily authored by Michael Coffey
+
+ This file is part of liblastfm.
+
+ liblastfm is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ liblastfm is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef LASTFM_LIBRARY_H
+#define LASTFM_LIBRARY_H
+
+#include "Track.h"
+#include "Artist.h"
+#include "Album.h"
+
+namespace lastfm
+{
+ class LASTFM_DLLEXPORT Library
+ {
+ private:
+ Library();
+
+ public:
+ static class QNetworkReply* addAlbum( const QList<lastfm::Album>& albums );
+ static class QNetworkReply* addArtist( const QList<lastfm::Artist>& artists );
+ static class QNetworkReply* addTrack( const lastfm::Track& tracks );
+
+ static class QNetworkReply* getAlbums( const QString& user, const lastfm::Artist& artist = lastfm::Artist(), int limit = 1, int page = 50 );
+ static class QNetworkReply* getArtists( const QString& user, int limit = 1, int page = 50 );
+ static class QNetworkReply* getTracks( const QString& user, const lastfm::Artist& artist = lastfm::Artist(), int limit = 1, int page = 50 );
+ static class QNetworkReply* getTracks( const QString& user, const lastfm::Album& album = lastfm::Album(), int limit = 1, int page = 50 );
+
+ static class QNetworkReply* removeAlbum( const lastfm::Album& album );
+ static class QNetworkReply* removeArtist( const lastfm::Artist& artist );
+ static class QNetworkReply* removeTrack( const lastfm::Track& track );
+
+ static class QNetworkReply* removeScrobble( const lastfm::Track& track );
+ };
+}
+
+#endif // LASTFM_LIBRARY_H
+
Please sign in to comment.
Something went wrong with that request. Please try again.