1 /* SoundcloudJsonParser.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (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 <QJsonObject>
25 #include <QJsonArray>
26 #include <QObject>
27 
28 #include "Utils/Pimpl.h"
29 
30 class MetaData;
31 class MetaDataList;
32 class Artist;
33 class Album;
34 class ArtistList;
35 class AlbumList;
36 
37 class QByteArray;
38 namespace SC
39 {
40 	class JsonParser : public QObject
41 	{
42 		Q_OBJECT
43 		PIMPL(JsonParser)
44 
45 	private:
46 		enum class SCJsonItemType : uint8_t
47 		{
48 			Track=0,
49 			Artist,
50 			Playlist
51 		};
52 
53 	public:
54 		explicit JsonParser(const QByteArray& content);
55 		~JsonParser();
56 
57 		bool	parseArtistList(ArtistList& artists, QJsonArray arr);
58 		bool	parseTrackList(ArtistList& artists, MetaDataList& v_md, QJsonArray arr);
59 		bool	parsePlaylistList(ArtistList& artists, AlbumList& albums, MetaDataList& v_md, QJsonArray arr);
60 
61 		bool	parseArtist(Artist& artist, QJsonObject object);
62 		bool	parsePlaylist(ArtistList& artists, Album& album, MetaDataList& v_md, QJsonObject object);
63 		bool	parseTrack(Artist& artist, MetaData& md, QJsonObject object);
64 
65 		QString	createLink(const QString& name, const QString& target);
66 
67 		bool	getString(const QString& key, const QJsonObject& object, QString& str);
68 		bool	getInt(const QString& key, const QJsonObject& object, int& i);
69 		bool	getArray(const QString& key, const QJsonObject& object, QJsonArray& arr);
70 		bool	getObject(const QString& key, const QJsonObject& object, QJsonObject& o);
71 
72 		bool	parseArtists(ArtistList& artists);
73 		bool	parseTracks(ArtistList& artists, MetaDataList& v_md);
74 		bool	parsePlaylists(ArtistList& artists, AlbumList& albums, MetaDataList& v_md);
75 	};
76 }
77 
78 #endif // SOUNDCLOUDJSONPARSER_H
79