1 /*
2  * Strawberry Music Player
3  * Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
4  *
5  * Strawberry is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Strawberry is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Strawberry.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef TIDALSTREAMURLREQUEST_H
21 #define TIDALSTREAMURLREQUEST_H
22 
23 #include "config.h"
24 
25 #include <QtGlobal>
26 #include <QObject>
27 #include <QVariant>
28 #include <QString>
29 #include <QStringList>
30 #include <QUrl>
31 
32 #include "core/song.h"
33 #include "tidalservice.h"
34 #include "tidalbaserequest.h"
35 #include "settings/tidalsettingspage.h"
36 
37 class QNetworkReply;
38 class NetworkAccessManager;
39 
40 class TidalStreamURLRequest : public TidalBaseRequest {
41   Q_OBJECT
42 
43  public:
44   explicit TidalStreamURLRequest(TidalService *service, NetworkAccessManager *network, const QUrl &original_url, const int id, QObject *parent = nullptr);
45   ~TidalStreamURLRequest() override;
46 
47   void GetStreamURL();
48   void Process();
49   void Cancel();
50 
oauth()51   bool oauth() { return service_->oauth(); }
stream_url_method()52   TidalSettingsPage::StreamUrlMethod stream_url_method() { return service_->stream_url_method(); }
original_url()53   QUrl original_url() { return original_url_; }
song_id()54   int song_id() { return song_id_; }
55 
set_need_login()56   void set_need_login() override { need_login_ = true; }
need_login()57   bool need_login() { return need_login_; }
58 
59  signals:
60   void TryLogin();
61   void StreamURLFinished(int id, QUrl original_url, QUrl stream_url, Song::FileType filetype, int samplerate, int bit_depth, qint64 duration, QString error = QString());
62 
63  private slots:
64   void StreamURLReceived();
65 
66  public slots:
67   void LoginComplete(const bool success, const QString &error = QString());
68 
69  private:
70   void Error(const QString &error, const QVariant &debug = QVariant()) override;
71 
72   TidalService *service_;
73   QNetworkReply *reply_;
74   QUrl original_url_;
75   int id_;
76   int song_id_;
77   int tries_;
78   bool need_login_;
79   QStringList errors_;
80 
81 };
82 
83 #endif  // TIDALSTREAMURLREQUEST_H
84