Sayonara Player
SoundcloudJsonParser.h
1 /* SoundcloudJsonParser.h */
2 
3 /* Copyright (C) 2011-2017 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 #ifndef SOUNDCLOUDJSONPARSER_H
22 #define SOUNDCLOUDJSONPARSER_H
23 
24 #include <QList>
25 
26 #include <QByteArray>
27 #include <QJsonDocument>
28 #include <QJsonParseError>
29 #include <QJsonObject>
30 #include <QJsonArray>
31 #include <QObject>
32 
33 class MetaData;
34 class MetaDataList;
35 class Artist;
36 class Album;
37 class ArtistList;
38 class AlbumList;
39 
40 class SoundcloudJsonParser : public QObject
41 {
42  Q_OBJECT
43 
44 private:
45  QJsonDocument _json_doc;
46  QByteArray _content;
47 
48  enum class SCJsonItemType : quint8
49  {
50  Track=0,
51  Artist,
52  Playlist
53  };
54 
55 private:
56  bool parse_artist_list(ArtistList& artists, QJsonArray arr);
57  bool parse_track_list(ArtistList& artists, MetaDataList& v_md, QJsonArray arr);
58  bool parse_playlist_list(ArtistList& artists, AlbumList& albums, MetaDataList& v_md, QJsonArray arr);
59 
60  bool parse_artist(Artist& artist, QJsonObject object);
61  bool parse_playlist(ArtistList& artists, Album& album, MetaDataList& v_md, QJsonObject object);
62  bool parse_track(Artist& artist, MetaData& md, QJsonObject object);
63 
64  QString create_link(const QString& name, const QString& target);
65 
66 
67 public:
68  explicit SoundcloudJsonParser(const QByteArray& content);
70 
71  bool get_string(const QString& key, const QJsonObject& object, QString& str);
72  bool get_int(const QString& key, const QJsonObject& object, int& i);
73  bool get_array(const QString& key, const QJsonObject& object, QJsonArray& arr);
74  bool get_object(const QString& key, const QJsonObject& object, QJsonObject& o);
75 
76  bool parse_artists(ArtistList& artists);
77  bool parse_tracks(ArtistList& artists, MetaDataList& v_md);
78  bool parse_playlists(ArtistList& artists, AlbumList& albums, MetaDataList& v_md);
79 };
80 
81 #endif // SOUNDCLOUDJSONPARSER_H
The MetaData class.
Definition: MetaData.h:55
Definition: MetaDataList.h:39
The AlbumList class.
Definition: Album.h:78
ArtistList.
Definition: Artist.h:60
The Album class.
Definition: Album.h:38
Definition: SoundcloudJsonParser.h:40
The Artist class.
Definition: Artist.h:33
Definition: PlaylistFwd.h:47