Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add google play music #4860

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions data/data.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
<file>providers/musicbrainz.png</file>
<file>providers/mygpo32.png</file>
<file>providers/myspace.png</file>
<file>providers/playmusic.png</file>
<file>providers/podcast16.png</file>
<file>providers/podcast32.png</file>
<file>providers/radiogfm.png</file>
Expand Down
Binary file added data/providers/playmusic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ set(SOURCES
globalsearch/simplesearchprovider.cpp
globalsearch/somafmsearchprovider.cpp
globalsearch/soundcloudsearchprovider.cpp
globalsearch/playmusicsearchprovider.cpp
globalsearch/spotifysearchprovider.cpp
globalsearch/suggestionwidget.cpp
globalsearch/urlsearchprovider.cpp
Expand Down Expand Up @@ -198,6 +199,9 @@ set(SOURCES
internet/subsonic/subsonicservice.cpp
internet/subsonic/subsonicsettingspage.cpp
internet/subsonic/subsonicurlhandler.cpp
internet/playmusic/playmusicservice.cpp
internet/playmusic/playmusicsettingspage.cpp
internet/playmusic/playmusicurlhandler.cpp

library/groupbydialog.cpp
library/library.cpp
Expand Down Expand Up @@ -462,6 +466,7 @@ set(HEADERS
globalsearch/searchprovider.h
globalsearch/simplesearchprovider.h
globalsearch/soundcloudsearchprovider.h
globalsearch/playmusicsearchprovider.h
globalsearch/spotifysearchprovider.h
globalsearch/suggestionwidget.h

Expand Down Expand Up @@ -501,6 +506,9 @@ set(HEADERS
internet/subsonic/subsonicservice.h
internet/subsonic/subsonicsettingspage.h
internet/subsonic/subsonicurlhandler.h
internet/playmusic/playmusicservice.h
internet/playmusic/playmusicsettingspage.h
internet/playmusic/playmusicurlhandler.h

library/groupbydialog.h
library/library.h
Expand Down Expand Up @@ -694,6 +702,7 @@ set(UI
internet/soundcloud/soundcloudsettingspage.ui
internet/spotify/spotifysettingspage.ui
internet/subsonic/subsonicsettingspage.ui
internet/playmusic/playmusicsettingspage.ui

library/groupbydialog.ui
library/libraryfilterwidget.ui
Expand Down
89 changes: 89 additions & 0 deletions src/globalsearch/playmusicsearchprovider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* This file is part of Clementine.
Copyright 2015, Marco Kirchner <kirchnermarco@gmail.com>
Copyright 2011, David Sansome <me@davidsansome.com>

Clementine 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.

Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/

#include "playmusicsearchprovider.h"

#include <QIcon>

#include "core/application.h"
#include "core/logging.h"
#include "covers/albumcoverloader.h"
#include "internet/playmusic/playmusicservice.h"

PlayMusicSearchProvider::PlayMusicSearchProvider(Application* app,
QObject* parent)
: SearchProvider(app, parent), service_(nullptr) {}

void PlayMusicSearchProvider::Init(PlayMusicService* service) {
service_ = service;
SearchProvider::Init(
"Google Play Music", "playmusic", QIcon(":providers/playmusic.png"),
WantsDelayedQueries | ArtIsProbablyRemote | CanShowConfig);

connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
SLOT(SearchDone(int, SongList)));

cover_loader_options_.desired_height_ = kArtHeight;
cover_loader_options_.pad_output_image_ = true;
cover_loader_options_.scale_output_image_ = true;

connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)),
SLOT(AlbumArtLoaded(quint64, QImage)));
}

void PlayMusicSearchProvider::SearchAsync(int id, const QString& query) {
const int service_id = service_->SimpleSearch(query);
pending_searches_[service_id] = PendingState(id, TokenizeQuery(query));
}

void PlayMusicSearchProvider::SearchDone(int id, const SongList& songs) {
// Map back to the original id.
const PendingState state = pending_searches_.take(id);
const int global_search_id = state.orig_id_;

ResultList ret;
for (const Song& song : songs) {
Result result(this);
result.metadata_ = song;

ret << result;
}

emit ResultsAvailable(global_search_id, ret);
MaybeSearchFinished(global_search_id);
}

void PlayMusicSearchProvider::MaybeSearchFinished(int id) {
if (pending_searches_.keys(PendingState(id, QStringList())).isEmpty()) {
emit SearchFinished(id);
}
}

void PlayMusicSearchProvider::LoadArtAsync(int id, const Result& result) {
quint64 loader_id = app_->album_cover_loader()->LoadImageAsync(
cover_loader_options_, result.metadata_);
cover_loader_tasks_[loader_id] = id;
}

void PlayMusicSearchProvider::AlbumArtLoaded(quint64 id, const QImage& image) {
if (!cover_loader_tasks_.contains(id)) {
return;
}
int original_id = cover_loader_tasks_.take(id);
emit ArtLoaded(original_id, image);
}
54 changes: 54 additions & 0 deletions src/globalsearch/playmusicsearchprovider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* This file is part of Clementine.
Copyright 2015, Marco Kirchner <kirchnermarco@gmail.com>
Copyright 2012, David Sansome <me@davidsansome.com>

Clementine 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.

Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PLAYMUSICSEARCHPROVIDER_H
#define PLAYMUSICSEARCHPROVIDER_H

#include "searchprovider.h"
#include "covers/albumcoverloaderoptions.h"
#include "internet/playmusic/playmusicservice.h"

class AlbumCoverLoader;

class PlayMusicSearchProvider : public SearchProvider {
Q_OBJECT

public:
explicit PlayMusicSearchProvider(Application* app, QObject* parent = nullptr);
void Init(PlayMusicService* service);

// SearchProvider
void SearchAsync(int id, const QString& query);
void LoadArtAsync(int id, const Result& result);
InternetService* internet_service() { return service_; }

private slots:
void AlbumArtLoaded(quint64 id, const QImage& image);
void SearchDone(int id, const SongList& songs);

private:
void MaybeSearchFinished(int id);

PlayMusicService* service_;
QMap<int, PendingState> pending_searches_;

AlbumCoverLoaderOptions cover_loader_options_;
QMap<quint64, int> cover_loader_tasks_;
};

#endif
2 changes: 2 additions & 0 deletions src/internet/core/internetmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "internet/internetradio/savedradio.h"
#include "internet/somafm/somafmservice.h"
#include "internet/soundcloud/soundcloudservice.h"
#include "internet/playmusic/playmusicservice.h"
#include "internet/spotify/spotifyservice.h"
#include "internet/subsonic/subsonicservice.h"
#include "core/closure.h"
Expand Down Expand Up @@ -98,6 +99,7 @@ InternetModel::InternetModel(Application* app, QObject* parent)
AddService(new RadioTunesService(app, this));
AddService(new SomaFMService(app, this));
AddService(new SoundCloudService(app, this));
AddService(new PlayMusicService(app, this));
AddService(new SpotifyService(app, this));
AddService(new SubsonicService(app, this));
#ifdef HAVE_BOX
Expand Down