[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / music / MusicDatabase.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program 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 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program 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 XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20 /*!
21  \file MusicDatabase.h
22 \brief
23 */
24 #pragma once
25 #include "dbwrappers/Database.h"
26 #include "Album.h"
27 #include "addons/Scraper.h"
28 #include "utils/SortUtils.h"
29 #include "MusicDbUrl.h"
30
31 class CArtist;
32 class CFileItem;
33
34 namespace dbiplus
35 {
36   class field_value;
37   typedef std::vector<field_value> sql_record;
38 }
39
40 #include <set>
41
42 // return codes of Cleaning up the Database
43 // numbers are strings from strings.xml
44 #define ERROR_OK     317
45 #define ERROR_CANCEL    0
46 #define ERROR_DATABASE    315
47 #define ERROR_REORG_SONGS   319
48 #define ERROR_REORG_ARTIST   321
49 #define ERROR_REORG_GENRE   323
50 #define ERROR_REORG_PATH   325
51 #define ERROR_REORG_ALBUM   327
52 #define ERROR_WRITING_CHANGES  329
53 #define ERROR_COMPRESSING   332
54
55 #define NUM_SONGS_BEFORE_COMMIT 500
56
57 /*!
58  \ingroup music
59  \brief A set of CStdString objects, used for CMusicDatabase
60  \sa ISETPATHES, CMusicDatabase
61  */
62 typedef std::set<CStdString> SETPATHES;
63
64 /*!
65  \ingroup music
66  \brief The SETPATHES iterator
67  \sa SETPATHES, CMusicDatabase
68  */
69 typedef std::set<CStdString>::iterator ISETPATHES;
70
71 class CGUIDialogProgress;
72 class CFileItemList;
73
74 /*!
75  \ingroup music
76  \brief Class to store and read tag information
77
78  CMusicDatabase can be used to read and store
79  tag information for faster access. It is based on
80  sqlite (http://www.sqlite.org).
81
82  Here is the database layout:
83   \image html musicdatabase.png
84
85  \sa CAlbum, CSong, VECSONGS, CMapSong, VECARTISTS, VECALBUMS, VECGENRES
86  */
87 class CMusicDatabase : public CDatabase
88 {
89   friend class DatabaseUtils;
90   friend class TestDatabaseUtilsHelper;
91
92 public:
93   CMusicDatabase(void);
94   virtual ~CMusicDatabase(void);
95
96   virtual bool Open();
97   virtual bool CommitTransaction();
98   void EmptyCache();
99   void Clean();
100   int  Cleanup(CGUIDialogProgress *pDlgProgress=NULL);
101   bool LookupCDDBInfo(bool bRequery=false);
102   void DeleteCDDBInfo();
103
104   /////////////////////////////////////////////////
105   // Song CRUD
106   /////////////////////////////////////////////////
107   /*! \brief Add a song to the database
108    \param idAlbum [in] the database ID of the album for the song
109    \param strTitle [in] the title of the song (required to be non-empty)
110    \param strMusicBrainzTrackID [in] the MusicBrainz track ID of the song
111    \param strPathAndFileName [in] the path and filename to the song
112    \param strComment [in] the ids of the added songs
113    \param strThumb [in] the ids of the added songs
114    \param artistString [in] the assembled artist string, denormalized from CONCAT(strArtist||strJoinPhrase)
115    \param genres [in] a vector of genres to which this song belongs
116    \param iTrack [in] the track number and disc number of the song
117    \param iDuration [in] the duration of the song
118    \param iYear [in] the year of the song
119    \param iTimesPlayed [in] the number of times the song has been played
120    \param iStartOffset [in] the start offset of the song (when using a single audio file with a .cue)
121    \param iEndOffset [in] the end offset of the song (when using a single audio file with .cue)
122    \param dtLastPlayed [in] the time the song was last played
123    \param rating [in] a rating for the song
124    \param iKaraokeNumber [in] the karaoke id of the song
125    \return the id of the song
126    */
127   int AddSong(const int idAlbum,
128               const CStdString& strTitle,
129               const CStdString& strMusicBrainzTrackID,
130               const CStdString& strPathAndFileName,
131               const CStdString& strComment,
132               const CStdString& strThumb,
133               const std::string &artistString, const std::vector<std::string>& genres,
134               int iTrack, int iDuration, int iYear,
135               const int iTimesPlayed, int iStartOffset, int iEndOffset,
136               const CDateTime& dtLastPlayed,
137               char rating, int iKaraokeNumber);
138   bool GetSong(int idSong, CSong& song);
139
140   /*! \brief Update a song in the database.
141
142    NOTE: This function assumes that song.artist contains the artist string to be concatenated.
143          Most internal functions should instead use the long-form function as the artist string
144          should be constructed from the artist credits.
145          This function will eventually be demised.
146
147    \param idSong  the database ID of the song to update
148    \param song the song
149    \return the id of the song.
150    */
151   int UpdateSong(int idSong, const CSong &song);
152
153   /*! \brief Update a song in the database
154    \param idSong [in] the database ID of the song to update
155    \param strTitle [in] the title of the song (required to be non-empty)
156    \param strMusicBrainzTrackID [in] the MusicBrainz track ID of the song
157    \param strPathAndFileName [in] the path and filename to the song
158    \param strComment [in] the ids of the added songs
159    \param strThumb [in] the ids of the added songs
160    \param artistString [in] the full artist string, denormalized from CONCAT(song_artist.strArtist || song_artist.strJoinPhrase)
161    \param genres [in] a vector of genres to which this song belongs
162    \param iTrack [in] the track number and disc number of the song
163    \param iDuration [in] the duration of the song
164    \param iYear [in] the year of the song
165    \param iTimesPlayed [in] the number of times the song has been played
166    \param iStartOffset [in] the start offset of the song (when using a single audio file with a .cue)
167    \param iEndOffset [in] the end offset of the song (when using a single audio file with .cue)
168    \param dtLastPlayed [in] the time the song was last played
169    \param rating [in] a rating for the song
170    \param iKaraokeNumber [in] the karaoke id of the song
171    \return the id of the song
172    */
173   int UpdateSong(int idSong,
174                  const CStdString& strTitle, const CStdString& strMusicBrainzTrackID,
175                  const CStdString& strPathAndFileName, const CStdString& strComment,
176                  const CStdString& strThumb,
177                  const std::string& artistString, const std::vector<std::string>& genres,
178                  int iTrack, int iDuration, int iYear,
179                  int iTimesPlayed, int iStartOffset, int iEndOffset,
180                  const CDateTime& dtLastPlayed,
181                  char rating, int iKaraokeNumber);
182   // bool DeleteSong(int idSong);
183
184   //// Misc Song
185   bool GetSongByFileName(const CStdString& strFileName, CSong& song, int startOffset = 0);
186   bool GetSongsByPath(const CStdString& strPath, MAPSONGS& songs, bool bAppendToMap = false);
187   bool Search(const CStdString& search, CFileItemList &items);
188   bool RemoveSongsFromPath(const CStdString &path, MAPSONGS& songs, bool exact=true);
189   bool SetSongRating(const CStdString &filePath, char rating);
190   int  GetSongByArtistAndAlbumAndTitle(const CStdString& strArtist, const CStdString& strAlbum, const CStdString& strTitle);
191
192   /////////////////////////////////////////////////
193   // Album
194   /////////////////////////////////////////////////
195   bool AddAlbum(CAlbum& album);
196   /*! \brief Update an album and all its nested entities (artists, songs, infoSongs, etc)
197    \param album the album to update
198    \return true or false
199    */
200   bool UpdateAlbum(CAlbum& album);
201
202   /*! \brief Add an album and all its songs to the database
203    \param album the album to add
204    \param songIDs [out] the ids of the added songs
205    \return the id of the album
206    */
207   int  AddAlbum(const CStdString& strAlbum, const CStdString& strMusicBrainzAlbumID,
208                 const CStdString& strArtist, const CStdString& strGenre,
209                 int year, bool bCompilation);
210   /*! \brief retrieve an album, optionally with all songs.
211    \param idAlbum the database id of the album.
212    \param album [out] the album to fill.
213    \param getSongs whether or not to retrieve songs, defaults to true.
214    \return true if the album is retrieved, false otherwise.
215    */
216   bool GetAlbum(int idAlbum, CAlbum& album, bool getSongs = true);
217   int  UpdateAlbum(int idAlbum, const CAlbum &album);
218   int  UpdateAlbum(int idAlbum,
219                    const CStdString& strAlbum, const CStdString& strMusicBrainzAlbumID,
220                    const CStdString& strArtist, const CStdString& strGenre,
221                    const CStdString& strMoods, const CStdString& strStyles,
222                    const CStdString& strThemes, const CStdString& strReview,
223                    const CStdString& strImage, const CStdString& strLabel,
224                    const CStdString& strType,
225                    int iRating, int iYear, bool bCompilation);
226   bool DeleteAlbum(int idAlbum);
227   bool ClearAlbumLastScrapedTime(int idAlbum);
228   bool HasAlbumBeenScraped(int idAlbum);
229   int  AddAlbumInfoSong(int idAlbum, const CSong& song);
230
231   /*! \brief Checks if the given path is inside a folder that has already been scanned into the library
232    \param path the path we want to check
233    */
234   bool InsideScannedPath(const CStdString& path);
235
236   //// Misc Album
237   int  GetAlbumIdByPath(const CStdString& path);
238   bool GetAlbumFromSong(int idSong, CAlbum &album);
239   int  GetAlbumByName(const CStdString& strAlbum, const CStdString& strArtist="");
240   int  GetAlbumByName(const CStdString& strAlbum, const std::vector<std::string>& artist);
241   CStdString GetAlbumById(int id);
242
243   /////////////////////////////////////////////////
244   // Artist CRUD
245   /////////////////////////////////////////////////
246   bool UpdateArtist(const CArtist& artist);
247
248   int  AddArtist(const CStdString& strArtist, const CStdString& strMusicBrainzArtistID);
249   bool GetArtist(int idArtist, CArtist& artist, bool fetchAll = true);
250   int  UpdateArtist(int idArtist,
251                     const CStdString& strArtist, const CStdString& strMusicBrainzArtistID,
252                     const CStdString& strBorn, const CStdString& strFormed,
253                     const CStdString& strGenres, const CStdString& strMoods,
254                     const CStdString& strStyles, const CStdString& strInstruments,
255                     const CStdString& strBiography, const CStdString& strDied,
256                     const CStdString& strDisbanded, const CStdString& strYearsActive,
257                     const CStdString& strImage, const CStdString& strFanart);
258   bool DeleteArtist(int idArtist);
259   bool HasArtistBeenScraped(int idArtist);
260   bool ClearArtistLastScrapedTime(int idArtist);
261   int  AddArtistDiscography(int idArtist, const CStdString& strAlbum, const CStdString& strYear);
262   bool DeleteArtistDiscography(int idArtist);
263
264   CStdString GetArtistById(int id);
265   int GetArtistByName(const CStdString& strArtist);
266
267   /////////////////////////////////////////////////
268   // Paths
269   /////////////////////////////////////////////////
270   int AddPath(const CStdString& strPath);
271
272   bool GetPaths(std::set<std::string> &paths);
273   bool SetPathHash(const CStdString &path, const CStdString &hash);
274   bool GetPathHash(const CStdString &path, CStdString &hash);
275   bool GetAlbumPath(int idAlbum, CStdString &path);
276   bool GetArtistPath(int idArtist, CStdString &path);
277
278   /////////////////////////////////////////////////
279   // Genres
280   /////////////////////////////////////////////////
281   int AddGenre(const CStdString& strGenre);
282   CStdString GetGenreById(int id);
283   int GetGenreByName(const CStdString& strGenre);
284
285   /////////////////////////////////////////////////
286   // Link tables
287   /////////////////////////////////////////////////
288   bool AddAlbumArtist(int idArtist, int idAlbum, std::string strArtist, std::string joinPhrase, bool featured, int iOrder);
289   bool GetAlbumsByArtist(int idArtist, bool includeFeatured, std::vector<int>& albums);
290   bool GetArtistsByAlbum(int idAlbum, bool includeFeatured, std::vector<int>& artists);
291   bool DeleteAlbumArtistsByAlbum(int idAlbum);
292
293   bool AddSongArtist(int idArtist, int idSong, std::string strArtist, std::string joinPhrase, bool featured, int iOrder);
294   bool GetSongsByArtist(int idArtist, bool includeFeatured, std::vector<int>& songs);
295   bool GetArtistsBySong(int idSong, bool includeFeatured, std::vector<int>& artists);
296   bool DeleteSongArtistsBySong(int idSong);
297
298   bool AddSongGenre(int idGenre, int idSong, int iOrder);
299   bool GetGenresBySong(int idSong, std::vector<int>& genres);
300   bool DeleteSongGenresBySong(int idSong);
301
302   bool AddAlbumGenre(int idGenre, int idAlbum, int iOrder);
303   bool GetGenresByAlbum(int idAlbum, std::vector<int>& genres);
304   bool DeleteAlbumGenresByAlbum(int idAlbum);
305
306   /////////////////////////////////////////////////
307   // Top 100
308   /////////////////////////////////////////////////
309   bool GetTop100(const CStdString& strBaseDir, CFileItemList& items);
310   bool GetTop100Albums(VECALBUMS& albums);
311   bool GetTop100AlbumSongs(const CStdString& strBaseDir, CFileItemList& item);
312
313   /////////////////////////////////////////////////
314   // Recently added
315   /////////////////////////////////////////////////
316   bool GetRecentlyAddedAlbums(VECALBUMS& albums, unsigned int limit=0);
317   bool GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CFileItemList& item, unsigned int limit=0);
318   bool GetRecentlyPlayedAlbums(VECALBUMS& albums);
319   bool GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, CFileItemList& item);
320
321   /////////////////////////////////////////////////
322   // Compilations
323   /////////////////////////////////////////////////
324   bool GetCompilationAlbums(const CStdString& strBaseDir, CFileItemList& items);
325   bool GetCompilationSongs(const CStdString& strBaseDir, CFileItemList& items);
326   int  GetCompilationAlbumsCount();
327   bool GetVariousArtistsAlbums(const CStdString& strBaseDir, CFileItemList& items);
328   bool GetVariousArtistsAlbumsSongs(const CStdString& strBaseDir, CFileItemList& items);
329   int GetVariousArtistsAlbumsCount();
330   
331   /*! \brief Increment the playcount of an item
332    Increments the playcount and updates the last played date
333    \param item CFileItem to increment the playcount for
334    */
335   void IncrementPlayCount(const CFileItem &item);
336   bool CleanupOrphanedItems();
337
338   /////////////////////////////////////////////////
339   // VIEWS
340   /////////////////////////////////////////////////
341   bool GetGenresNav(const CStdString& strBaseDir, CFileItemList& items, const Filter &filter = Filter(), bool countOnly = false);
342   bool GetYearsNav(const CStdString& strBaseDir, CFileItemList& items, const Filter &filter = Filter());
343   bool GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, bool albumArtistsOnly = false, int idGenre = -1, int idAlbum = -1, int idSong = -1, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription(), bool countOnly = false);
344   bool GetCommonNav(const CStdString &strBaseDir, const CStdString &table, const CStdString &labelField, CFileItemList &items, const Filter &filter /* = Filter() */, bool countOnly /* = false */);
345   bool GetAlbumTypesNav(const CStdString &strBaseDir, CFileItemList &items, const Filter &filter = Filter(), bool countOnly = false);
346   bool GetMusicLabelsNav(const CStdString &strBaseDir, CFileItemList &items, const Filter &filter = Filter(), bool countOnly = false);
347   bool GetAlbumsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre = -1, int idArtist = -1, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription(), bool countOnly = false);
348   bool GetAlbumsByYear(const CStdString &strBaseDir, CFileItemList& items, int year);
349   bool GetSongsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, int idArtist,int idAlbum, const SortDescription &sortDescription = SortDescription());
350   bool GetSongsByYear(const CStdString& baseDir, CFileItemList& items, int year);
351   bool GetSongsByWhere(const CStdString &baseDir, const Filter &filter, CFileItemList& items, const SortDescription &sortDescription = SortDescription());
352   bool GetAlbumsByWhere(const CStdString &baseDir, const Filter &filter, CFileItemList &items, const SortDescription &sortDescription = SortDescription(), bool countOnly = false);
353   bool GetArtistsByWhere(const CStdString& strBaseDir, const Filter &filter, CFileItemList& items, const SortDescription &sortDescription = SortDescription(), bool countOnly = false);
354   bool GetRandomSong(CFileItem* item, int& idSong, const Filter &filter);
355   int GetSongsCount(const Filter &filter = Filter());
356   unsigned int GetSongIDs(const Filter &filter, std::vector<std::pair<int,int> > &songIDs);
357   virtual bool GetFilter(CDbUrl &musicUrl, Filter &filter, SortDescription &sorting);
358
359   /////////////////////////////////////////////////
360   // Scraper
361   /////////////////////////////////////////////////
362   bool SetScraperForPath(const CStdString& strPath, const ADDON::ScraperPtr& info);
363   bool GetScraperForPath(const CStdString& strPath, ADDON::ScraperPtr& info, const ADDON::TYPE &type);
364   
365   /*! \brief Check whether a given scraper is in use.
366    \param scraperID the scraper to check for.
367    \return true if the scraper is in use, false otherwise.
368    */
369   bool ScraperInUse(const CStdString &scraperID) const;
370
371   /////////////////////////////////////////////////
372   // Karaoke
373   /////////////////////////////////////////////////
374   void AddKaraokeData(int idSong, int iKaraokeNumber, DWORD crc);
375   bool GetSongByKaraokeNumber( int number, CSong& song );
376   bool SetKaraokeSongDelay( int idSong, int delay );
377   int GetKaraokeSongsCount();
378   void ExportKaraokeInfo(const CStdString &outFile, bool asHTML );
379   void ImportKaraokeInfo(const CStdString &inputFile );
380
381   /////////////////////////////////////////////////
382   // Filters
383   /////////////////////////////////////////////////
384   bool GetItems(const CStdString &strBaseDir, CFileItemList &items, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription());
385   bool GetItems(const CStdString &strBaseDir, const CStdString &itemType, CFileItemList &items, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription());
386   CStdString GetItemById(const CStdString &itemType, int id);
387
388   /////////////////////////////////////////////////
389   // XML
390   /////////////////////////////////////////////////
391   void ExportToXML(const CStdString &xmlFile, bool singleFiles = false, bool images=false, bool overwrite=false);
392   void ImportFromXML(const CStdString &xmlFile);
393
394   /////////////////////////////////////////////////
395   // Properties
396   /////////////////////////////////////////////////
397   void SetPropertiesForFileItem(CFileItem& item);
398   static void SetPropertiesFromArtist(CFileItem& item, const CArtist& artist);
399   static void SetPropertiesFromAlbum(CFileItem& item, const CAlbum& album);
400
401   /////////////////////////////////////////////////
402   // Art
403   /////////////////////////////////////////////////
404   bool SaveAlbumThumb(int idAlbum, const CStdString &thumb);
405   /*! \brief Sets art for a database item.
406    Sets a single piece of art for a database item.
407    \param mediaId the id in the media (song/artist/album) table.
408    \param mediaType the type of media, which corresponds to the table the item resides in (song/artist/album).
409    \param artType the type of art to set, e.g. "thumb", "fanart"
410    \param url the url to the art (this is the original url, not a cached url).
411    \sa GetArtForItem
412    */
413   void SetArtForItem(int mediaId, const std::string &mediaType, const std::string &artType, const std::string &url);
414
415   /*! \brief Sets art for a database item.
416    Sets multiple pieces of art for a database item.
417    \param mediaId the id in the media (song/artist/album) table.
418    \param mediaType the type of media, which corresponds to the table the item resides in (song/artist/album).
419    \param art a map of <type, url> where type is "thumb", "fanart", etc. and url is the original url of the art.
420    \sa GetArtForItem
421    */
422   void SetArtForItem(int mediaId, const std::string &mediaType, const std::map<std::string, std::string> &art);
423
424   /*! \brief Fetch art for a database item.
425    Fetches multiple pieces of art for a database item.
426    \param mediaId the id in the media (song/artist/album) table.
427    \param mediaType the type of media, which corresponds to the table the item resides in (song/artist/album).
428    \param art [out] a map of <type, url> where type is "thumb", "fanart", etc. and url is the original url of the art.
429    \return true if art is retrieved, false if no art is found.
430    \sa SetArtForItem
431    */
432   bool GetArtForItem(int mediaId, const std::string &mediaType, std::map<std::string, std::string> &art);
433
434   /*! \brief Fetch art for a database item.
435    Fetches a single piece of art for a database item.
436    \param mediaId the id in the media (song/artist/album) table.
437    \param mediaType the type of media, which corresponds to the table the item resides in (song/artist/album).
438    \param artType the type of art to retrieve, eg "thumb", "fanart".
439    \return the original URL to the piece of art, if available.
440    \sa SetArtForItem
441    */
442   std::string GetArtForItem(int mediaId, const std::string &mediaType, const std::string &artType);
443
444   /*! \brief Fetch artist art for a song or album item.
445    Fetches the art associated with the primary artist for the song or album.
446    \param mediaId the id in the media (song/album) table.
447    \param mediaType the type of media, which corresponds to the table the item resides in (song/album).
448    \param art [out] the art map <type, url> of artist art.
449    \return true if artist art is found, false otherwise.
450    \sa GetArtForItem
451    */
452   bool GetArtistArtForItem(int mediaId, const std::string &mediaType, std::map<std::string, std::string> &art);
453
454   /*! \brief Fetch artist art for a song or album item.
455    Fetches a single piece of art associated with the primary artist for the song or album.
456    \param mediaId the id in the media (song/album) table.
457    \param mediaType the type of media, which corresponds to the table the item resides in (song/album).
458    \param artType the type of art to retrieve, eg "thumb", "fanart".
459    \return the original URL to the piece of art, if available.
460    \sa GetArtForItem
461    */
462   std::string GetArtistArtForItem(int mediaId, const std::string &mediaType, const std::string &artType);
463
464 protected:
465   std::map<CStdString, int> m_artistCache;
466   std::map<CStdString, int> m_genreCache;
467   std::map<CStdString, int> m_pathCache;
468   std::map<CStdString, int> m_thumbCache;
469   std::map<CStdString, CAlbum> m_albumCache;
470
471   virtual bool CreateTables();
472   virtual int GetMinVersion() const;
473
474   const char *GetBaseDBName() const { return "MyMusic"; };
475
476
477 private:
478   /*! \brief (Re)Create the generic database views for songs and albums
479    */
480   virtual void CreateViews();
481
482   void SplitString(const CStdString &multiString, std::vector<std::string> &vecStrings, CStdString &extraStrings);
483   CSong GetSongFromDataset();
484   CSong GetSongFromDataset(const dbiplus::sql_record* const record, int offset = 0);
485   CArtist GetArtistFromDataset(dbiplus::Dataset* pDS, int offset = 0, bool needThumb = true);
486   CArtist GetArtistFromDataset(const dbiplus::sql_record* const record, int offset = 0, bool needThumb = true);
487   CAlbum GetAlbumFromDataset(dbiplus::Dataset* pDS, int offset = 0, bool imageURL = false);
488   CAlbum GetAlbumFromDataset(const dbiplus::sql_record* const record, int offset = 0, bool imageURL = false);
489   CArtistCredit GetArtistCreditFromDataset(const dbiplus::sql_record* const record, int offset = 0);
490   void GetFileItemFromDataset(CFileItem* item, const CMusicDbUrl &baseUrl);
491   void GetFileItemFromDataset(const dbiplus::sql_record* const record, CFileItem* item, const CMusicDbUrl &baseUrl);
492   CSong GetAlbumInfoSongFromDataset(const dbiplus::sql_record* const record, int offset = 0);
493   bool CleanupSongs();
494   bool CleanupSongsByIds(const CStdString &strSongIds);
495   bool CleanupPaths();
496   bool CleanupAlbums();
497   bool CleanupArtists();
498   bool CleanupGenres();
499   virtual bool UpdateOldVersion(int version);
500   bool SearchArtists(const CStdString& search, CFileItemList &artists);
501   bool SearchAlbums(const CStdString& search, CFileItemList &albums);
502   bool SearchSongs(const CStdString& strSearch, CFileItemList &songs);
503   int GetSongIDFromPath(const CStdString &filePath);
504
505   // Fields should be ordered as they
506   // appear in the songview
507   enum _SongFields
508   {
509     song_idSong=0,
510     song_strArtists,
511     song_strGenres,
512     song_strTitle,
513     song_iTrack,
514     song_iDuration,
515     song_iYear,
516     song_dwFileNameCRC,
517     song_strFileName,
518     song_strMusicBrainzTrackID,
519     song_iTimesPlayed,
520     song_iStartOffset,
521     song_iEndOffset,
522     song_lastplayed,
523     song_rating,
524     song_comment,
525     song_idAlbum,
526     song_strAlbum,
527     song_strPath,
528     song_iKarNumber,
529     song_iKarDelay,
530     song_strKarEncoding,
531     song_bCompilation,
532     song_strAlbumArtists,
533     song_enumCount // end of the enum, do not add past here
534   } SongFields;
535
536   // Fields should be ordered as they
537   // appear in the albumview
538   enum _AlbumFields
539   {
540     album_idAlbum=0,
541     album_strAlbum,
542     album_strMusicBrainzAlbumID,
543     album_strArtists,
544     album_strGenres,
545     album_iYear,
546     album_strMoods,
547     album_strStyles,
548     album_strThemes,
549     album_strReview,
550     album_strLabel,
551     album_strType,
552     album_strThumbURL,
553     album_iRating,
554     album_bCompilation,
555     album_iTimesPlayed,
556     album_enumCount // end of the enum, do not add past here
557   } AlbumFields;
558
559   enum _ArtistCreditFields
560   {
561     // used for GetAlbum to get the cascaded album/song artist credits
562     artistCredit_idEntity = 0,  // can be idSong or idAlbum depending on context
563     artistCredit_idArtist,
564     artistCredit_strArtist,
565     artistCredit_strMusicBrainzArtistID,
566     artistCredit_bFeatured,
567     artistCredit_strJoinPhrase,
568     artistCredit_iOrder,
569     artistCredit_enumCount
570   } ArtistCreditFields;
571
572   enum _ArtistFields
573   {
574     artist_idArtist=0,
575     artist_strArtist,
576     artist_strMusicBrainzArtistID,
577     artist_strBorn,
578     artist_strFormed,
579     artist_strGenres,
580     artist_strMoods,
581     artist_strStyles,
582     artist_strInstruments,
583     artist_strBiography,
584     artist_strDied,
585     artist_strDisbanded,
586     artist_strYearsActive,
587     artist_strImage,
588     artist_strFanart,
589     artist_enumCount // end of the enum, do not add past here
590   } ArtistFields;
591
592   enum _AlbumInfoSongFields
593   {
594     albumInfoSong_idAlbumInfoSong=0,
595     albumInfoSong_idAlbumInfo,
596     albumInfoSong_iTrack,
597     albumInfoSong_strTitle,
598     albumInfoSong_iDuration,
599     albumInfoSong_enumCount // end of the enum, do not add past here
600   } AlbumInfoSongFields;
601 };