Improve URL handler, return error for encrypted Tidal streams
This commit is contained in:
@@ -211,7 +211,6 @@ TidalService::~TidalService() {
|
||||
while (!stream_url_requests_.isEmpty()) {
|
||||
std::shared_ptr<TidalStreamURLRequest> stream_url_req = stream_url_requests_.take(stream_url_requests_.firstKey());
|
||||
QObject::disconnect(stream_url_req.get(), nullptr, this, nullptr);
|
||||
stream_url_req->deleteLater();
|
||||
}
|
||||
|
||||
artists_collection_backend_->deleteLater();
|
||||
@@ -987,37 +986,50 @@ void TidalService::SearchResultsReceived(const int id, const SongMap &songs, con
|
||||
emit SearchResults(id, songs, error);
|
||||
}
|
||||
|
||||
void TidalService::GetStreamURL(const QUrl &url) {
|
||||
uint TidalService::GetStreamURL(const QUrl &url, QString &error) {
|
||||
|
||||
if (!authenticated()) {
|
||||
if (oauth_) {
|
||||
emit StreamURLFinished(url, url, Song::FileType_Stream, -1, -1, -1, tr("Not authenticated with Tidal."));
|
||||
return;
|
||||
error = tr("Not authenticated with Tidal.");
|
||||
return 0;
|
||||
}
|
||||
else if (api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit StreamURLFinished(url, url, Song::FileType_Stream, -1, -1, -1, tr("Missing Tidal API token, username or password."));
|
||||
return;
|
||||
error = tr("Missing Tidal API token, username or password.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const int id = ++next_stream_url_request_id_;
|
||||
uint id = 0;
|
||||
while (id == 0) id = ++next_stream_url_request_id_;
|
||||
std::shared_ptr<TidalStreamURLRequest> stream_url_req = std::make_shared<TidalStreamURLRequest>(this, network_, url, id);
|
||||
stream_url_requests_.insert(id, stream_url_req);
|
||||
|
||||
QObject::connect(stream_url_req.get(), &TidalStreamURLRequest::TryLogin, this, &TidalService::TryLogin);
|
||||
QObject::connect(stream_url_req.get(), &TidalStreamURLRequest::StreamURLFinished, this, &TidalService::HandleStreamURLFinished);
|
||||
QObject::connect(stream_url_req.get(), &TidalStreamURLRequest::StreamURLFailure, this, &TidalService::HandleStreamURLFailure);
|
||||
QObject::connect(stream_url_req.get(), &TidalStreamURLRequest::StreamURLSuccess, this, &TidalService::HandleStreamURLSuccess);
|
||||
QObject::connect(this, &TidalService::LoginComplete, stream_url_req.get(), &TidalStreamURLRequest::LoginComplete);
|
||||
|
||||
stream_url_req->Process();
|
||||
|
||||
return id;
|
||||
|
||||
}
|
||||
|
||||
void TidalService::HandleStreamURLFinished(const int id, const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration, const QString &error) {
|
||||
void TidalService::HandleStreamURLFailure(const uint id, const QUrl &original_url, const QString &error) {
|
||||
|
||||
if (!stream_url_requests_.contains(id)) return;
|
||||
std::shared_ptr<TidalStreamURLRequest> stream_url_req = stream_url_requests_.take(id);
|
||||
|
||||
emit StreamURLFinished(original_url, stream_url, filetype, samplerate, bit_depth, duration, error);
|
||||
emit StreamURLFailure(id, original_url, error);
|
||||
|
||||
}
|
||||
|
||||
void TidalService::HandleStreamURLSuccess(const uint id, const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration) {
|
||||
|
||||
if (!stream_url_requests_.contains(id)) return;
|
||||
std::shared_ptr<TidalStreamURLRequest> stream_url_req = stream_url_requests_.take(id);
|
||||
|
||||
emit StreamURLSuccess(id, original_url, stream_url, filetype, samplerate, bit_depth, duration);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user