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 #include "XBDateTime.h"
12 #include "utils/EmbeddedArt.h"
13 #include "utils/Fanart.h"
14 #include "utils/ISortable.h"
15 #include "utils/ScraperUrl.h"
16 #include "utils/StreamDetails.h"
17 #include "video/Bookmark.h"
18 
19 #include <string>
20 #include <vector>
21 
22 class CArchive;
23 class TiXmlNode;
24 class TiXmlElement;
25 class CVariant;
26 
27 struct SActorInfo
28 {
29   bool operator<(const SActorInfo &right) const
30   {
31     return order < right.order;
32   }
33   std::string strName;
34   std::string strRole;
35   CScraperUrl thumbUrl;
36   std::string thumb;
37   int        order = -1;
38 };
39 
40 class CRating
41 {
42 public:
43   CRating() = default;
CRating(float r)44   explicit CRating(float r): rating(r) {}
CRating(float r,int v)45   CRating(float r, int v): rating(r), votes(v) {}
46   float rating = 0.0f;
47   int votes = 0;
48 };
49 typedef std::map<std::string, CRating> RatingMap;
50 
51 class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
52 {
53 public:
CVideoInfoTag()54   CVideoInfoTag() { Reset(); };
55   virtual ~CVideoInfoTag() = default;
56   void Reset();
57   /* \brief Load information to a videoinfotag from an XML element
58    There are three types of tags supported:
59     1. Single-value tags, such as <title>.  These are set if available, else are left untouched.
60     2. Additive tags, such as <set> or <genre>.  These are appended to or replaced (if available) based on the value
61        of the prioritise parameter.  In addition, a clear attribute is available in the XML to clear the current value prior
62        to appending.
63     3. Image tags such as <thumb> and <fanart>.  If the prioritise value is specified, any additional values are prepended
64        to the existing values.
65 
66    \param element    the root XML element to parse.
67    \param append     whether information should be added to the existing tag, or whether it should be reset first.
68    \param prioritise if appending, whether additive tags should be prioritised (i.e. replace or prepend) over existing values. Defaults to false.
69 
70    \sa ParseNative
71    */
72   bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
73   bool Save(TiXmlNode *node, const std::string &tag, bool savePathInfo = true, const TiXmlElement *additionalNode = NULL);
74   void Merge(CVideoInfoTag& other);
75   void Archive(CArchive& ar) override;
76   void Serialize(CVariant& value) const override;
77   void ToSortable(SortItem& sortable, Field field) const override;
78   const CRating GetRating(std::string type = "") const;
79   const std::string& GetDefaultRating() const;
80   const std::string GetUniqueID(std::string type = "") const;
81   const std::map<std::string, std::string>& GetUniqueIDs() const;
82   const std::string& GetDefaultUniqueID() const;
83   bool HasUniqueID() const;
84   virtual bool HasYear() const;
85   virtual int GetYear() const;
86   bool HasPremiered() const;
87   const CDateTime& GetPremiered() const;
88   const CDateTime& GetFirstAired() const;
89   const std::string GetCast(bool bIncludeRole = false) const;
90   bool HasStreamDetails() const;
91   bool IsEmpty() const;
92 
GetPath()93   const std::string& GetPath() const
94   {
95     if (m_strFileNameAndPath.empty())
96       return m_strPath;
97     return m_strFileNameAndPath;
98   };
99 
100   /*! \brief set the duration in seconds
101    \param duration the duration to set
102    */
103   void SetDuration(int duration);
104 
105   /*! \brief retrieve the duration in seconds.
106    Prefers the duration from stream details if available.
107    */
108   unsigned int GetDuration() const;
109 
110   /*! \brief retrieve the duration in seconds.
111    Ignores the duration from stream details even if available.
112    */
113   unsigned int GetStaticDuration() const;
114 
115   /*! \brief get the duration in seconds from a minute string
116    \param runtime the runtime string from a scraper or similar
117    \return the time in seconds, if decipherable.
118    */
119   static unsigned int GetDurationFromMinuteString(const std::string &runtime);
120 
121   void SetBasePath(std::string basePath);
122   void SetDirector(std::vector<std::string> director);
123   void SetWritingCredits(std::vector<std::string> writingCredits);
124   void SetGenre(std::vector<std::string> genre);
125   void SetCountry(std::vector<std::string> country);
126   void SetTagLine(std::string tagLine);
127   void SetPlotOutline(std::string plotOutline);
128   void SetTrailer(std::string trailer);
129   void SetPlot(std::string plot);
130   std::string const &GetTitle();
131   void SetTitle(std::string title);
132   void SetSortTitle(std::string sortTitle);
133   void SetPictureURL(CScraperUrl &pictureURL);
134   void SetRating(float rating, int votes, const std::string& type = "", bool def = false);
135   void SetRating(CRating rating, const std::string& type = "", bool def = false);
136   void SetRating(float rating, const std::string& type = "", bool def = false);
137   void RemoveRating(const std::string& type);
138   void SetRatings(RatingMap ratings);
139   void SetVotes(int votes, const std::string& type = "");
140   void SetUniqueIDs(std::map<std::string, std::string> uniqueIDs);
141   void SetPremiered(const CDateTime& premiered);
142   void SetPremieredFromDBDate(const std::string& premieredString);
143   virtual void SetYear(int year);
144   void SetArtist(std::vector<std::string> artist);
145   void SetSet(std::string set);
146   void SetSetOverview(std::string setOverview);
147   void SetTags(std::vector<std::string> tags);
148   void SetFile(std::string file);
149   void SetPath(std::string path);
150   void SetMPAARating(std::string mpaaRating);
151   void SetFileNameAndPath(std::string fileNameAndPath);
152   void SetOriginalTitle(std::string originalTitle);
153   void SetEpisodeGuide(std::string episodeGuide);
154   void SetStatus(std::string status);
155   void SetProductionCode(std::string productionCode);
156   void SetShowTitle(std::string showTitle);
157   void SetStudio(std::vector<std::string> studio);
158   void SetAlbum(std::string album);
159   void SetShowLink(std::vector<std::string> showLink);
160   void SetUniqueID(const std::string& uniqueid, const std::string& type = "", bool def = false);
161   void RemoveUniqueID(const std::string& type);
162   void SetNamedSeasons(std::map<int, std::string> namedSeasons);
163   void SetUserrating(int userrating);
164 
165   /*!
166    * @brief Get this videos's play count.
167    * @return the play count.
168    */
169   virtual int GetPlayCount() const;
170 
171   /*!
172    * @brief Set this videos's play count.
173    * @param count play count.
174    * @return True if play count was set successfully, false otherwise.
175    */
176   virtual bool SetPlayCount(int count);
177 
178   /*!
179    * @brief Increment this videos's play count.
180    * @return True if play count was increased successfully, false otherwise.
181    */
182   virtual bool IncrementPlayCount();
183 
184   /*!
185   * @brief Reset playcount
186   */
187   virtual void ResetPlayCount();
188 
189   /*!
190   * @brief Check if the playcount is set
191   * @return True if play count value is set
192   */
193   virtual bool IsPlayCountSet() const;
194 
195   /*!
196    * @brief Get this videos's resume point.
197    * @return the resume point.
198    */
199   virtual CBookmark GetResumePoint() const;
200 
201   /*!
202    * @brief Set this videos's resume point.
203    * @param resumePoint resume point.
204    * @return True if resume point was set successfully, false otherwise.
205    */
206   virtual bool SetResumePoint(const CBookmark &resumePoint);
207 
208   /*!
209    * @brief Set this videos's resume point.
210    * @param timeInSeconds the time of the resume point
211    * @param totalTimeInSeconds the total time of the video
212    * @param playerState the player state
213    * @return True if resume point was set successfully, false otherwise.
214    */
215   virtual bool SetResumePoint(double timeInSeconds, double totalTimeInSeconds, const std::string &playerState);
216 
217   std::string m_basePath; // the base path of the video, for folder-based lookups
218   int m_parentPathID;      // the parent path id where the base path of the video lies
219   std::vector<std::string> m_director;
220   std::vector<std::string> m_writingCredits;
221   std::vector<std::string> m_genre;
222   std::vector<std::string> m_country;
223   std::string m_strTagLine;
224   std::string m_strPlotOutline;
225   std::string m_strTrailer;
226   std::string m_strPlot;
227   CScraperUrl m_strPictureURL;
228   std::string m_strTitle;
229   std::string m_strSortTitle;
230   std::vector<std::string> m_artist;
231   std::vector< SActorInfo > m_cast;
232   typedef std::vector< SActorInfo >::const_iterator iCast;
233   struct SetInfo //!< Struct holding information about a movie set
234   {
235     std::string title; //!< Title of the movie set
236     int id; //!< ID of movie set in database
237     std::string overview; //!< Overview/description of the movie set
238   };
239   SetInfo m_set; //!< Assigned movie set
240   std::vector<std::string> m_tags;
241   std::string m_strFile;
242   std::string m_strPath;
243   std::string m_strMPAARating;
244   std::string m_strFileNameAndPath;
245   std::string m_strOriginalTitle;
246   std::string m_strEpisodeGuide;
247   CDateTime m_premiered;
248   bool m_bHasPremiered;
249   std::string m_strStatus;
250   std::string m_strProductionCode;
251   CDateTime m_firstAired;
252   std::string m_strShowTitle;
253   std::vector<std::string> m_studio;
254   std::string m_strAlbum;
255   CDateTime m_lastPlayed;
256   std::vector<std::string> m_showLink;
257   std::map<int, std::string> m_namedSeasons;
258   int m_iTop250;
259   int m_year;
260   int m_iSeason;
261   int m_iEpisode;
262   int m_iIdUniqueID;
263   int m_iDbId;
264   int m_iFileId;
265   int m_iSpecialSortSeason;
266   int m_iSpecialSortEpisode;
267   int m_iTrack;
268   RatingMap m_ratings;
269   int m_iIdRating;
270   int m_iUserRating;
271   CBookmark m_EpBookmark;
272   int m_iBookmarkId;
273   int m_iIdShow;
274   int m_iIdSeason;
275   CFanart m_fanart;
276   CStreamDetails m_streamDetails;
277   CDateTime m_dateAdded;
278   MediaType m_type;
279   int m_relevance; // Used for actors' number of appearances
280   int m_parsedDetails;
281   std::vector<EmbeddedArtInfo> m_coverArt; ///< art information
282 
283   // TODO: cannot be private, because of 'struct SDbTableOffsets'
284   unsigned int m_duration; ///< duration in seconds
285 
286 private:
287   /* \brief Parse our native XML format for video info.
288    See Load for a description of the available tag types.
289 
290    \param element    the root XML element to parse.
291    \param prioritise whether additive tags should be replaced (or prepended) by the content of the tags, or appended to.
292    \sa Load
293    */
294   void ParseNative(const TiXmlElement* element, bool prioritise);
295 
296   std::string m_strDefaultRating;
297   std::string m_strDefaultUniqueID;
298   std::map<std::string, std::string> m_uniqueIDs;
299   std::string Trim(std::string &&value);
300   std::vector<std::string> Trim(std::vector<std::string> &&items);
301 
302   int m_playCount;
303   CBookmark m_resumePoint;
304   static const int PLAYCOUNT_NOT_SET = -1;
305 };
306 
307 typedef std::vector<CVideoInfoTag> VECMOVIES;
308