Sayonara Player
SoundcloudJsonParser.h
1 /* SoundcloudJsonParser.h */
2 
3 /* Copyright (C) 2011-2016 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 
23 #ifndef SOUNDCLOUDJSONPARSER_H
24 #define SOUNDCLOUDJSONPARSER_H
25 
26 
27 
28 #include "SoundcloudGlobal.h"
29 #include "Helper/Logger/Logger.h"
30 
31 #include <QList>
32 #include <QString>
33 #include <QByteArray>
34 #include <QObject>
35 #include <QJsonDocument>
36 #include <QObject>
37 
38 #include <QJsonParseError>
39 #include <QJsonObject>
40 #include <QJsonArray>
41 
42 
43 class MetaData;
44 class MetaDataList;
45 class Artist;
46 class Album;
47 class ArtistList;
48 class AlbumList;
49 
50 
51 class SoundcloudJsonParser : public QObject
52 {
53 
54  Q_OBJECT
55 
56 private:
57  QJsonDocument _json_doc;
58  QByteArray _content;
59 
60  enum class SCJsonItemType : quint8
61  {
62  Track=0,
63  Artist,
64  Playlist
65  };
66 
67 private:
68 
69  bool parse_artist_list(ArtistList& artists, QJsonArray arr);
70  bool parse_track_list(ArtistList& artists, MetaDataList& v_md, QJsonArray arr);
71  bool parse_playlist_list(ArtistList& artists, AlbumList& albums, MetaDataList& v_md, QJsonArray arr);
72 
73  bool parse_artist(Artist& artist, QJsonObject object);
74  bool parse_playlist(ArtistList& artists, Album& album, MetaDataList& v_md, QJsonObject object);
75  bool parse_track(Artist& artist, MetaData& md, QJsonObject object);
76 
77 
78  QString create_link(const QString& name, const QString& target);
79 
80 
81 public:
82  SoundcloudJsonParser(const QByteArray& content);
84 
85 
86  bool get_string(const QString& key, const QJsonObject& object, QString& str);
87  bool get_int(const QString& key, const QJsonObject& object, int& i);
88  bool get_double(const QString& key, const QJsonObject& object, double& d);
89  bool get_bool(const QString& key, const QJsonObject& object, bool& b);
90  bool get_array(const QString& key, const QJsonObject& object, QJsonArray& arr);
91  bool get_object(const QString& key, const QJsonObject& object, QJsonObject& o);
92 
93  bool parse_artists(ArtistList& artists);
94  bool parse_tracks(ArtistList& artists, MetaDataList& v_md);
95  bool parse_playlists(ArtistList& artists, AlbumList& albums, MetaDataList& v_md);
96 
97 };
98 
99 
100 
101 #endif // SOUNDCLOUDJSONPARSER_H
Definition: MetaData.h:49
Definition: MetaDataList.h:44
The AlbumList class.
Definition: Album.h:72
ArtistList.
Definition: Artist.h:64
The Album class.
Definition: Album.h:40
Definition: SoundcloudJsonParser.h:51
The Playlist class.
Definition: Playlist.h:39
The Artist class.
Definition: Artist.h:36