1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 /*!
12  \file Album.h
13 \brief
14 */
15 
16 #include "Artist.h"
17 #include "Song.h"
18 #include "XBDateTime.h"
19 #include "utils/ScraperUrl.h"
20 
21 #include <map>
22 #include <vector>
23 
24 class TiXmlNode;
25 class CFileItem;
26 class CAlbum
27 {
28 public:
29   explicit CAlbum(const CFileItem& item);
30   CAlbum() = default;
31   bool operator<(const CAlbum &a) const;
32   void MergeScrapedAlbum(const CAlbum& album, bool override = true);
33 
Reset()34   void Reset()
35   {
36     idAlbum = -1;
37     strAlbum.clear();
38     strMusicBrainzAlbumID.clear();
39     strReleaseGroupMBID.clear();
40     artistCredits.clear();
41     strArtistDesc.clear();
42     strArtistSort.clear();
43     genre.clear();
44     thumbURL.Clear();
45     moods.clear();
46     styles.clear();
47     themes.clear();
48     art.clear();
49     strReview.clear();
50     strLabel.clear();
51     strType.clear();
52     strReleaseStatus.clear();
53     strPath.clear();
54     fRating = -1;
55     iUserrating = -1;
56     iVotes = -1;
57     strOrigReleaseDate.clear();
58     strReleaseDate.clear();
59     bCompilation = false;
60     bBoxedSet = false;
61     iTimesPlayed = 0;
62     dateAdded.Reset();
63     dateUpdated.Reset();
64     dateNew.Reset();
65     lastPlayed.Reset();
66     iTotalDiscs = -1;
67     songs.clear();
68     releaseType = Album;
69     strLastScraped.clear();
70     bScrapedMBID = false;
71     bArtistSongMerge = false;
72     iAlbumDuration = 0;
73   }
74 
75   /*! \brief Get album artist names from the vector of artistcredits objects
76   \return album artist names as a vector of strings
77   */
78   const std::vector<std::string> GetAlbumArtist() const;
79 
80   /*! \brief Get album artist MusicBrainz IDs from the vector of artistcredits objects
81   \return album artist MusicBrainz IDs as a vector of strings
82   */
83   const std::vector<std::string> GetMusicBrainzAlbumArtistID() const;
84   std::string GetGenreString() const;
85 
86   /*! \brief Get album artist names from the artist description string (if it exists)
87              or concatenated from the vector of artistcredits objects
88   \return album artist names as a single string
89   */
90   const std::string GetAlbumArtistString() const;
91 
92   /*! \brief Get album artist sort name from the artist sort string (if it exists)
93   or concatenated from the vector of artistcredits objects
94   \return album artist sort names as a single string
95   */
96   const std::string GetAlbumArtistSort() const;
97 
98   /*! \brief Get album artist IDs (for json rpc) from the vector of artistcredits objects
99   \return album artist IDs as a vector of integers
100   */
101   const std::vector<int> GetArtistIDArray() const;
102 
103   typedef enum ReleaseType {
104     Album = 0,
105     Single
106   } ReleaseType;
107 
108   std::string GetReleaseType() const;
109   void SetReleaseType(const std::string& strReleaseType);
110   void SetDateAdded(const std::string& strDateAdded);
111   void SetDateUpdated(const std::string& strDateUpdated);
112   void SetDateNew(const std::string& strDateNew);
113   void SetLastPlayed(const std::string& strLastPlayed);
114 
115   static std::string ReleaseTypeToString(ReleaseType releaseType);
116   static ReleaseType ReleaseTypeFromString(const std::string& strReleaseType);
117 
118   /*! \brief Set album artist credits using the arrays of tag values.
119    If strArtistSort (as from ALBUMARTISTSORT tag) is already set then individual
120    artist sort names are also processed.
121    \param names       String vector of albumartist names (as from ALBUMARTIST tag)
122    \param hints       String vector of albumartist name hints (as from ALBUMARTISTS tag)
123    \param mbids       String vector of albumartist Musicbrainz IDs (as from MUSICBRAINZABUMARTISTID tag)
124    \param artistnames String vector of artist names (as from ARTIST tag)
125    \param artisthints String vector of artist name hints (as from ARTISTS tag)
126    \param artistmbids String vector of artist Musicbrainz IDs (as from MUSICBRAINZARTISTID tag)
127   */
128   void SetArtistCredits(const std::vector<std::string>& names, const std::vector<std::string>& hints,
129                         const std::vector<std::string>& mbids,
130                         const std::vector<std::string>& artistnames = std::vector<std::string>(),
131                         const std::vector<std::string>& artisthints = std::vector<std::string>(),
132                         const std::vector<std::string>& artistmbids = std::vector<std::string>());
133 
134   /*! \brief Load album information from an XML file.
135    See CVideoInfoTag::Load for a description of the types of elements we load.
136    \param element    the root XML element to parse.
137    \param append     whether information should be added to the existing tag, or whether it should be reset first.
138    \param prioritise if appending, whether additive tags should be prioritised (i.e. replace or prepend) over existing values. Defaults to false.
139    \sa CVideoInfoTag::Load
140    */
141   bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
142   bool Save(TiXmlNode *node, const std::string &tag, const std::string& strPath);
143 
144   int idAlbum = -1;
145   std::string strAlbum;
146   std::string strMusicBrainzAlbumID;
147   std::string strReleaseGroupMBID;
148   std::string strArtistDesc;
149   std::string strArtistSort;
150   VECARTISTCREDITS artistCredits;
151   std::vector<std::string> genre;
152   CScraperUrl thumbURL;
153   std::vector<std::string> moods;
154   std::vector<std::string> styles;
155   std::vector<std::string> themes;
156   std::map<std::string, std::string> art;
157   std::string strReview;
158   std::string strLabel;
159   std::string strType;
160   std::string strReleaseStatus;
161   std::string strPath;
162   float fRating = -1;
163   int iUserrating = -1;
164   int iVotes = -1;
165   std::string strReleaseDate;
166   std::string strOrigReleaseDate;
167   bool bBoxedSet = false;
168   bool bCompilation = false;
169   int iTimesPlayed = 0;
170   CDateTime dateAdded; // From related file creation or modification times, or when (re-)scanned
171   CDateTime dateUpdated; // Time db record Last modified
172   CDateTime dateNew;  // Time db record created
173   CDateTime lastPlayed;
174   int iTotalDiscs = -1;
175   VECSONGS songs;     ///< Local songs
176   ReleaseType releaseType = Album;
177   std::string strLastScraped;
178   bool bScrapedMBID = false;
179   bool bArtistSongMerge = false;
180   int iAlbumDuration = 0;
181 };
182 
183 typedef std::vector<CAlbum> VECALBUMS;
184