1 /**************************************************************************************** 2 * Copyright (c) 2010-2012 Leo Franchi <lfranchi@kde.org> * 3 * * 4 * This program is free software; you can redistribute it and/or modify it under * 5 * the terms of the GNU General Public License as published by the Free Software * 6 * Foundation; either version 2 of the License, or (at your option) any later * 7 * version. * 8 * * 9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 12 * * 13 * You should have received a copy of the GNU General Public License along with * 14 * this program. If not, see <http://www.gnu.org/licenses/>. * 15 ****************************************************************************************/ 16 17 #ifndef ECHONEST_PARSING_P_H 18 #define ECHONEST_PARSING_P_H 19 20 #include "Config.h" 21 22 #include "Song.h" 23 #include "Artist.h" 24 #include "Catalog.h" 25 #include "Playlist.h" 26 #include "Genre.h" 27 28 #include <QXmlStreamReader> 29 30 class QNetworkReply; 31 32 namespace Echonest 33 { 34 namespace Parser 35 { 36 /** 37 * Internal helper parsing functions for QXmlStreamParser 38 */ 39 40 void checkForErrors( QNetworkReply* reply ) throw( ParseError ); 41 42 // read the start element and then the status element, throwing 43 // if the result code is not Success 44 void readStatus( QXmlStreamReader& xml ) throw( ParseError ); 45 46 // parses a <songs></songs> block and turns them into a list of Song object 47 QVector< Song > parseSongList( QXmlStreamReader& xml ) throw( ParseError ); 48 49 // parses a <song></song> block 50 Song parseSong( QXmlStreamReader& xml ) throw( ParseError ); 51 52 // parses a <artist_location> block 53 ArtistLocation parseSongArtistLocation( QXmlStreamReader& xml ) throw( ParseError ); 54 55 // parses a <track></track> block 56 Track parseTrack( QXmlStreamReader& xml ) throw( ParseError ); 57 58 // parses a <tracks> chunk when asking for a song with tracks bucket 59 Tracks parseSongTrackBucket( QXmlStreamReader& xml ) throw( ParseError ); 60 61 // parses an <audio_summary> chunk 62 AudioSummary parseAudioSummary( QXmlStreamReader& xml ) throw( ParseError ); 63 // parses the json of the detailed audio summary 64 void parseDetailedAudioSummary( QNetworkReply* reply, AudioSummary& summary ) throw( ParseError ); 65 66 // parses a list of artists in an <artists></artists> block 67 Echonest::Artists parseArtists( QXmlStreamReader& xml ) throw( ParseError ); 68 69 // parses the contents of an artist fetch result, expects to be positioned after the readStatus() call 70 // it could be a profile query, in which case it has a bunch of different artist attributes 71 // or it could be a single fetch, in which case it starts with result number and offset. 72 // the results are saved back into the artist 73 int parseArtistInfoOrProfile( QXmlStreamReader&, Echonest::Artist& artist ) throw( ParseError ); 74 75 // parse the individual artist attributes 76 void parseArtistInfo( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 77 78 // parse each type of artist attribute 79 void parseAudio( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 80 void parseBiographies( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 81 void parseImages( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 82 void parseNewsOrBlogs( QXmlStreamReader& xml, Echonest::Artist& artist, bool news = true ) throw( ParseError ); 83 void parseReviews( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 84 void parseTerms( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 85 void parseUrls( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 86 void parseArtistSong( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 87 void parseVideos( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 88 void parseForeignArtistIds( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 89 void parseArtistGenres( QXmlStreamReader& xml, Echonest::Artist& artist ) throw( ParseError ); 90 91 // parse a list of terms 92 TermList parseTopTermList( QXmlStreamReader& xml ) throw( ParseError ); 93 QVector< QString > parseTermList( QXmlStreamReader& xml ) throw( ParseError ); 94 95 //parse a list of genres 96 QVector< QString > parseGenreListStrings( QXmlStreamReader& xml ) throw( ParseError ); 97 98 Echonest::Genres parseGenres( QXmlStreamReader& xml ) throw( ParseError ); 99 Echonest::Genre parseGenre( QXmlStreamReader& xml ) throw( ParseError ); 100 101 Artists parseArtistSuggestList( QXmlStreamReader& xml ) throw( ParseError ); 102 103 License parseLicense( QXmlStreamReader& xml ) throw( ParseError ); 104 105 QByteArray parsePlaylistSessionId( QXmlStreamReader& xml ) throw( ParseError ); 106 SongList parseDynamicLookahead( QXmlStreamReader& xml ) throw( ParseError ); 107 108 // Catalog functions 109 Catalogs parseCatalogList( QXmlStreamReader& xml ) throw( ParseError ); 110 Catalog parseCatalog( QXmlStreamReader& xml, bool justOne = false /* the catalog API is ugly :( */ ) throw( ParseError ); 111 QList<CatalogItem*> parseCatalogItems( QXmlStreamReader& xml ) throw( ParseError ); 112 void parseCatalogRequestItem( QXmlStreamReader& xml, Echonest::CatalogArtist&, Echonest::CatalogSong& ) throw( ParseError ); 113 void saveArtistList( Catalog& catalog, QList<CatalogItem*>& ); 114 void saveSongList( Catalog& catalog, QList<CatalogItem*>& ); 115 Echonest::CatalogStatus parseCatalogStatus( QXmlStreamReader& xml ) throw( ParseError ); 116 Echonest::CatalogStatusItem parseTicketUpdateInfo( QXmlStreamReader& xml ) throw( ParseError ); 117 QByteArray parseCatalogTicket( QXmlStreamReader& xml ) throw( ParseError ); 118 Catalog parseNewCatalog( QXmlStreamReader& xml ) throw( ParseError ); 119 120 // parses a <tracks> chunk when asking for a song with tracks bucket in a catalog.read call 121 Tracks parseCatalogSongTracks( QXmlStreamReader& xml ) throw( ParseError ); 122 123 SessionInfo parseSessionInfo( QXmlStreamReader& xml ) throw( ParseError ); 124 QVector< QString > parseRulesList( QXmlStreamReader& xml ) throw( ParseError ); 125 // QVector< SessionItem > parseSessionSongItem( QXmlStreamReader& xml, const QString& type ) throw( ParseError ); 126 127 } 128 } 129 130 #endif 131