kodi
VideoInfoTag.h
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 enum class VideoAssetType;
28 
29 struct SActorInfo
30 {
31  bool operator<(const SActorInfo &right) const
32  {
33  return order < right.order;
34  }
35  std::string strName;
36  std::string strRole;
37  CScraperUrl thumbUrl;
38  std::string thumb;
39  int order = -1;
40 };
41 
42 class CRating
43 {
44 public:
45  CRating() = default;
46  explicit CRating(float r): rating(r) {}
47  CRating(float r, int v): rating(r), votes(v) {}
48  float rating = 0.0f;
49  int votes = 0;
50 };
51 typedef std::map<std::string, CRating> RatingMap;
52 
53 class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
54 {
55 public:
56  CVideoInfoTag() { Reset(); }
57  virtual ~CVideoInfoTag() = default;
58  void Reset();
59  /* \brief Load information to a videoinfotag from an XML element
60  There are three types of tags supported:
61  1. Single-value tags, such as <title>. These are set if available, else are left untouched.
62  2. Additive tags, such as <set> or <genre>. These are appended to or replaced (if available) based on the value
63  of the prioritise parameter. In addition, a clear attribute is available in the XML to clear the current value prior
64  to appending.
65  3. Image tags such as <thumb> and <fanart>. If the prioritise value is specified, any additional values are prepended
66  to the existing values.
67 
68  \param element the root XML element to parse.
69  \param append whether information should be added to the existing tag, or whether it should be reset first.
70  \param prioritise if appending, whether additive tags should be prioritised (i.e. replace or prepend) over existing values. Defaults to false.
71 
72  \sa ParseNative
73  */
74  bool Load(const TiXmlElement *element, bool append = false, bool prioritise = false);
75  bool Save(TiXmlNode *node, const std::string &tag, bool savePathInfo = true, const TiXmlElement *additionalNode = NULL);
76  void Merge(CVideoInfoTag& other);
77  void Archive(CArchive& ar) override;
78  void Serialize(CVariant& value) const override;
79  void ToSortable(SortItem& sortable, Field field) const override;
80  const CRating GetRating(std::string type = "") const;
81  const std::string& GetDefaultRating() const;
82  const std::string GetUniqueID(std::string type = "") const;
83  const std::map<std::string, std::string>& GetUniqueIDs() const;
84  const std::string& GetDefaultUniqueID() const;
85  bool HasUniqueID() const;
86  virtual bool HasYear() const;
87  virtual int GetYear() const;
88  bool HasPremiered() const;
89  const CDateTime& GetPremiered() const;
90  const CDateTime& GetFirstAired() const;
91  const std::string GetCast(bool bIncludeRole = false) const;
92  bool HasStreamDetails() const;
93  bool IsEmpty() const;
94 
95  const std::string& GetPath() const
96  {
97  if (m_strFileNameAndPath.empty())
98  return m_strPath;
99  return m_strFileNameAndPath;
100  };
101 
105  void SetDuration(int duration);
106 
110  unsigned int GetDuration() const;
111 
115  unsigned int GetStaticDuration() const;
116 
121  static unsigned int GetDurationFromMinuteString(const std::string &runtime);
122 
123  void SetBasePath(std::string basePath);
124  void SetDirector(std::vector<std::string> director);
125  void SetWritingCredits(std::vector<std::string> writingCredits);
126  void SetGenre(std::vector<std::string> genre);
127  void SetCountry(std::vector<std::string> country);
128  void SetTagLine(std::string tagLine);
129  void SetPlotOutline(std::string plotOutline);
130  void SetTrailer(std::string trailer);
131  void SetPlot(std::string plot);
132  std::string const& GetTitle() const;
133  void SetTitle(std::string title);
134  void SetSortTitle(std::string sortTitle);
135  void SetPictureURL(CScraperUrl &pictureURL);
136  void SetRating(float rating, int votes, const std::string& type = "", bool def = false);
137  void SetRating(CRating rating, const std::string& type = "", bool def = false);
138  void SetRating(float rating, const std::string& type = "", bool def = false);
139  void RemoveRating(const std::string& type);
140  void SetRatings(RatingMap ratings, const std::string& defaultRating = "");
141  void SetVotes(int votes, const std::string& type = "");
142  void SetUniqueIDs(std::map<std::string, std::string> uniqueIDs);
143  void SetPremiered(const CDateTime& premiered);
144  void SetPremieredFromDBDate(const std::string& premieredString);
145  virtual void SetYear(int year);
146  void SetArtist(std::vector<std::string> artist);
147  void SetSet(std::string set);
148  void SetSetOverview(std::string setOverview);
149  void SetTags(std::vector<std::string> tags);
150  void SetFile(std::string file);
151  void SetPath(std::string path);
152  void SetMPAARating(std::string mpaaRating);
153  void SetFileNameAndPath(std::string fileNameAndPath);
154  void SetOriginalTitle(std::string originalTitle);
155  void SetEpisodeGuide(std::string episodeGuide);
156  void SetStatus(std::string status);
157  void SetProductionCode(std::string productionCode);
158  void SetShowTitle(std::string showTitle);
159  void SetStudio(std::vector<std::string> studio);
160  void SetAlbum(std::string album);
161  void SetShowLink(std::vector<std::string> showLink);
162  void SetUniqueID(const std::string& uniqueid, const std::string& type = "", bool def = false);
163  void RemoveUniqueID(const std::string& type);
164  void SetNamedSeasons(std::map<int, std::string> namedSeasons);
165  void SetUserrating(int userrating);
166 
171  virtual int GetPlayCount() const;
172 
178  virtual bool SetPlayCount(int count);
179 
184  virtual bool IncrementPlayCount();
185 
189  virtual void ResetPlayCount();
190 
195  virtual bool IsPlayCountSet() const;
196 
201  virtual CBookmark GetResumePoint() const;
202 
208  virtual bool SetResumePoint(const CBookmark &resumePoint);
209 
211  {
212  public:
216  void Clear();
217 
222  void Archive(CArchive& ar);
223 
228  void Save(TiXmlNode* movie);
229 
234  void ParseNative(const TiXmlElement* movie);
235 
240  void Merge(CAssetInfo& other);
241 
246  void Serialize(CVariant& value) const;
247 
252  const std::string& GetTitle() const { return m_title; }
253 
258  void SetTitle(const std::string& assetTitle);
259 
264  int GetId() const { return m_id; }
265 
270  void SetId(int assetId);
271 
276  VideoAssetType GetType() const { return m_type; }
277 
282  void SetType(VideoAssetType assetType);
283 
284  private:
285  std::string m_title;
286  int m_id{-1};
287  VideoAssetType m_type{-1};
288  };
289 
294  const CAssetInfo& GetAssetInfo() const { return m_assetInfo; }
295  CAssetInfo& GetAssetInfo() { return m_assetInfo; }
296 
301  bool HasVideoVersions() const { return m_hasVideoVersions; }
302 
307  void SetHasVideoVersions(bool hasVersions);
308 
313  bool HasVideoExtras() const { return m_hasVideoExtras; }
314 
319  void SetHasVideoExtras(bool hasExtras);
320 
325  bool IsDefaultVideoVersion() const { return m_isDefaultVideoVersion; }
326 
331  void SetIsDefaultVideoVersion(bool isDefaultVideoVersion);
332 
338  bool GetUpdateSetOverview() const { return m_updateSetOverview; }
339 
347  virtual bool SetResumePoint(double timeInSeconds, double totalTimeInSeconds, const std::string &playerState);
348 
349  std::string m_basePath; // the base path of the video, for folder-based lookups
350  int m_parentPathID; // the parent path id where the base path of the video lies
351  std::vector<std::string> m_director;
352  std::vector<std::string> m_writingCredits;
353  std::vector<std::string> m_genre;
354  std::vector<std::string> m_country;
355  std::string m_strTagLine;
356  std::string m_strPlotOutline;
357  std::string m_strTrailer;
358  std::string m_strPlot;
359  CScraperUrl m_strPictureURL;
360  std::string m_strTitle;
361  std::string m_strSortTitle;
362  std::vector<std::string> m_artist;
363  std::vector< SActorInfo > m_cast;
364  typedef std::vector< SActorInfo >::const_iterator iCast;
365  struct SetInfo
366  {
367  std::string title;
368  int id;
369  std::string overview;
370  };
372  std::vector<std::string> m_tags;
373  std::string m_strFile;
374  std::string m_strPath;
375  std::string m_strMPAARating;
376  std::string m_strFileNameAndPath;
377  std::string m_strOriginalTitle;
378  std::string m_strEpisodeGuide;
379  CDateTime m_premiered;
380  bool m_bHasPremiered;
381  std::string m_strStatus;
382  std::string m_strProductionCode;
383  CDateTime m_firstAired;
384  std::string m_strShowTitle;
385  std::vector<std::string> m_studio;
386  std::string m_strAlbum;
387  CDateTime m_lastPlayed;
388  std::vector<std::string> m_showLink;
389  std::map<int, std::string> m_namedSeasons;
390  int m_iTop250;
391  int m_year;
392  int m_iSeason;
393  int m_iEpisode;
394  int m_iIdUniqueID;
395  int m_iDbId;
396  int m_iFileId;
397  int m_iSpecialSortSeason;
398  int m_iSpecialSortEpisode;
399  int m_iTrack;
400  RatingMap m_ratings;
401  int m_iIdRating;
402  int m_iUserRating;
403  CBookmark m_EpBookmark;
404  int m_iBookmarkId;
405  int m_iIdShow;
406  int m_iIdSeason;
407  CFanart m_fanart;
408  CStreamDetails m_streamDetails;
409  CDateTime m_dateAdded;
410  MediaType m_type;
411  int m_relevance; // Used for actors' number of appearances
412  int m_parsedDetails;
413  std::vector<EmbeddedArtInfo> m_coverArt;
414 
415  // TODO: cannot be private, because of 'struct SDbTableOffsets'
416  unsigned int m_duration;
417 
418 private:
419  /* \brief Parse our native XML format for video info.
420  See Load for a description of the available tag types.
421 
422  \param element the root XML element to parse.
423  \param prioritise whether additive tags should be replaced (or prepended) by the content of the tags, or appended to.
424  \sa Load
425  */
426  void ParseNative(const TiXmlElement* element, bool prioritise);
427 
428  std::string m_strDefaultRating;
429  std::string m_strDefaultUniqueID;
430  std::map<std::string, std::string> m_uniqueIDs;
431  std::string Trim(std::string &&value);
432  std::vector<std::string> Trim(std::vector<std::string> &&items);
433 
434  int m_playCount;
435  CBookmark m_resumePoint;
436  static const int PLAYCOUNT_NOT_SET = -1;
437 
438  CAssetInfo m_assetInfo;
439  bool m_hasVideoVersions{false};
440  bool m_hasVideoExtras{false};
441  bool m_isDefaultVideoVersion{false};
442 
443  bool m_updateSetOverview{true};
444 };
445 
446 typedef std::vector<CVideoInfoTag> VECMOVIES;
const CAssetInfo & GetAssetInfo() const
Get the video&#39;s asset info.
Definition: VideoInfoTag.h:294
int id
ID of movie set in database.
Definition: VideoInfoTag.h:368
std::vector< EmbeddedArtInfo > m_coverArt
art information
Definition: VideoInfoTag.h:413
Definition: VideoInfoTag.h:42
bool HasVideoExtras() const
Whether the item has video extras.
Definition: VideoInfoTag.h:313
SetInfo m_set
Assigned movie set.
Definition: VideoInfoTag.h:371
/brief CFanart is the core of fanart support and contains all fanart data for a specific show ...
Definition: Fanart.h:30
const std::string & GetTitle() const
Get the video&#39;s asset title.
Definition: VideoInfoTag.h:252
Definition: Bookmark.h:14
Definition: VideoInfoTag.h:210
< Struct holding information about a movie set
Definition: VideoInfoTag.h:365
std::string overview
Overview/description of the movie set.
Definition: VideoInfoTag.h:369
Definition: StreamDetails.h:92
Definition: Variant.h:31
VideoAssetType GetType() const
Get the video&#39;s asset type.
Definition: VideoInfoTag.h:276
bool IsDefaultVideoVersion() const
Whether the item is the default video version.
Definition: VideoInfoTag.h:325
Definition: ISerializable.h:13
Definition: Archive.h:29
Definition: VideoInfoTag.h:29
bool GetUpdateSetOverview() const
Get whether the Set Overview should be updated. If an NFO contains a <name> but no <overview> then th...
Definition: VideoInfoTag.h:338
bool HasVideoVersions() const
Whether the item has multiple video versions.
Definition: VideoInfoTag.h:301
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Definition: ISortable.h:15
int GetId() const
Get the video&#39;s asset id.
Definition: VideoInfoTag.h:264
unsigned int m_duration
duration in seconds
Definition: VideoInfoTag.h:416
Definition: VideoInfoTag.h:53
std::string title
Title of the movie set.
Definition: VideoInfoTag.h:367
Definition: IArchivable.h:13
Definition: ScraperUrl.h:21