-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Spotify extension #43
Conversation
nice! but do this extension depends on QT 5.15?
|
Hello! To be honest I don't know right now. I'm on vacation and I will take a look when I come back. 😉 |
@Bierchermuesli According to the docs, |
just a Problem of outdated Qt version in some distros :-) Debian 11 (soon stable) has Qt 5.14 and Ubuntu >20.10 has Qt5.14 |
a5d13d8
to
ee55048
Compare
Is there anything I can do to help you merge this @ManuelSchneid3r? Or are you working on some breaking changes in the core that will require adaptation? I've used this extension for more than one year and didn't notice a single problem. |
currently albert is backward compatible until ubuntu 18.04 i.e. 5.9. 20.04 uses 5.12.. I strive to be one or two years backward compatible. Therefore I decided to always support the latest two ubuntu LTS. Unfortunately this means that the newest lib you can use is 5.12. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sorry, but this is in bad shape.
} | ||
|
||
SpotifyWebAPI::~SpotifyWebAPI() { | ||
delete manager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You pass this
as parent which should then take care of this. (Except when you leak it in the query handler)
if (query->string().trimmed().isEmpty()) | ||
return; | ||
|
||
d->api->manager = new QNetworkAccessManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this happening? Also there is no parent specified. I strongly suspect a memory leak here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use unique_ptr to avoid memory leaks
d->api->manager = new QNetworkAccessManager(); | ||
|
||
// If there is no internet connection, make one alerting item to let the user know. | ||
if (!d->api->testInternetConnection()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ManuelSchneid3r When do we like network access in the handler? Is this an acceptable case? Wasn't there something about async queries? I forgot.
Also on a separate note; why test the connection? Nothing is gained here. Better to handle connection errors when they occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it is accessing a web api, hence it's necessary. I agree please use (short) timeouts
auto filename = QString("%1/%2.jpeg").arg(d->cacheDirectory, track.albumId); | ||
|
||
// Download cover image of the album. | ||
d->api->downloadImage(track.imageUrl, filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There sure is a lot happening in the query handler...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately yes, but in this case we can't get better than the lag introduces by the requests
d->spotifyExecutable = settings().value("spotify_executable").toString(); | ||
d->cacheDirectory = settings().value("cache_directory").toString(); | ||
|
||
if (d->numberOfResults == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QSettings::value supports a default argument
connect(this, SIGNAL(deviceReady(QString, QString)), this, SLOT(play(QString, QString))); | ||
|
||
QtConcurrent::run([=]() { | ||
manager = new QNetworkAccessManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you just plaster this line everywhere where you had a threading problem when testing... This really needs to be fixed. (Last time I mention threads and managers, but there are still more occurrences)
return jsonObject; | ||
} | ||
|
||
void SpotifyWebAPI::waitForSignal_(const QObject *sender, const char *signal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you don't want to go async.
} | ||
|
||
QString SpotifyWebAPI::getFirstDeviceId() { | ||
QVector<Device> *devices_ = getDevices(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is leaked.
auto results = d->api->searchTracks(query->string(), d->numberOfResults); | ||
|
||
// Get available Spotify devices. | ||
auto *devices = d->api->getDevices(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not only leaked, but its ownership is all over the place.
QString SEARCH_URL = "https://api.spotify.com/v1/search?q=%1&type=%2&limit=%3"; | ||
QString PLAY_URL = "https://api.spotify.com/v1/me/player/play?device_id=%1"; | ||
QString ADD_ITEM_URL = "https://api.spotify.com/v1/me/player/queue?uri=%1"; | ||
QString DEVICES_URL = "https://api.spotify.com/v1/me/player/devices"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These all look very const despite none of them are.
Please port it to 0.18. Looking forward to finally use this one :D |
b991b95
to
3b125e5
Compare
Will a subset of features work withou a premium account? |
2951883
to
9832cf1
Compare
@BlueManCZ do you still want this plugin to be merged? |
Excuse me for not replying sooner.
Thank you for the code review @idkCpp, I will try to refactor this when porting to the new Albert core. You were right, that ton of managers was indeed a threading problem.
As soon as I get Qt6 and build working on Gentoo, I will try to port it.
I'm not sure. I can't imagine what that subset would be. Based on the sentence from API documentation:
I do, but I still don't have Qt6 on Gentoo to port this to the new Albert core. But I keep this in mind and watch Telegram for news. |
@BlueManCZ my ebuild for Qt6 Albert is ready and working. I just have to commit it, and do a pull request on gentoo repository. |
Here is my pull request on gentoo repository gentoo/gentoo#30405 |
@BlueManCZ ill close this one for now. Please reopen or make a new one if it is time for it. |
New plugin available here: #138
Old extension:
I created a Spotify extension for Albert launcher. It allows user to search and play tracks, add them to the queue and choose particular Spotify client.
This code needs review and testing. It works without any problems for me, but there may be unpredictable situational problems, that I'm currently not aware of.
For all people willing to use this extension, please read README.md first. I describe there how to configure Spotify Web API connection in this extension.
It is
QueryHandler::ExecutionType::Realtime
and currently containsspotify
andplay
triggers.YouTube video: https://youtu.be/fCpvYUWIsBs
Instructions for building and running this PR: