2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
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"
27 enum class VideoAssetType
;
31 bool operator<(const SActorInfo
&right
) const
33 return order
< right
.order
;
46 explicit CRating(float r
): rating(r
) {}
47 CRating(float r
, int v
): rating(r
), votes(v
) {}
51 typedef std::map
<std::string
, CRating
> RatingMap
;
53 class CVideoInfoTag
: public IArchivable
, public ISerializable
, public ISortable
56 CVideoInfoTag() { Reset(); }
57 virtual ~CVideoInfoTag() = default;
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
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.
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.
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;
95 const std::string
& GetPath() const
97 if (m_strFileNameAndPath
.empty())
99 return m_strFileNameAndPath
;
102 /*! \brief set the duration in seconds
103 \param duration the duration to set
105 void SetDuration(int duration
);
107 /*! \brief retrieve the duration in seconds.
108 Prefers the duration from stream details if available.
110 unsigned int GetDuration() const;
112 /*! \brief retrieve the duration in seconds.
113 Ignores the duration from stream details even if available.
115 unsigned int GetStaticDuration() const;
117 /*! \brief get the duration in seconds from a minute string
118 \param runtime the runtime string from a scraper or similar
119 \return the time in seconds, if decipherable.
121 static unsigned int GetDurationFromMinuteString(const std::string
&runtime
);
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
);
168 * @brief Get this videos's play count.
169 * @return the play count.
171 virtual int GetPlayCount() const;
174 * @brief Set this videos's play count.
175 * @param count play count.
176 * @return True if play count was set successfully, false otherwise.
178 virtual bool SetPlayCount(int count
);
181 * @brief Increment this videos's play count.
182 * @return True if play count was increased successfully, false otherwise.
184 virtual bool IncrementPlayCount();
187 * @brief Reset playcount
189 virtual void ResetPlayCount();
192 * @brief Check if the playcount is set
193 * @return True if play count value is set
195 virtual bool IsPlayCountSet() const;
198 * @brief Get this videos's resume point.
199 * @return the resume point.
201 virtual CBookmark
GetResumePoint() const;
204 * @brief Set this videos's resume point.
205 * @param resumePoint resume point.
206 * @return True if resume point was set successfully, false otherwise.
208 virtual bool SetResumePoint(const CBookmark
&resumePoint
);
214 * @brief Clear all data.
219 * @brief Archive all data.
220 * @param ar The archive to write the data to / to read the data from.
222 void Archive(CArchive
& ar
);
225 * @brief Store all data to XML.
226 * @param movie The XML element to write the data to.
228 void Save(TiXmlNode
* movie
);
231 * @brief Restore all data from XML.
232 * @param movie The XML element containing the data.
234 void ParseNative(const TiXmlElement
* movie
);
237 * @brief Merge in all valid data from another asset info.
238 * @param other The other asset info.
240 void Merge(CAssetInfo
& other
);
243 * @brief Serialize all data.
244 * @param value The container to write the data to.
246 void Serialize(CVariant
& value
) const;
249 * @brief Get the video's asset title.
250 * @return The title or an empty string if the item has no video asset.
252 const std::string
& GetTitle() const { return m_title
; }
255 * @brief Set this videos's asset title.
256 * @param assetTitle The title.
258 void SetTitle(const std::string
& assetTitle
);
261 * @brief Get the video's asset id.
262 * @return The id or -1 if the item has no video asset.
264 int GetId() const { return m_id
; }
267 * @brief Set this videos's asset id.
268 * @param assetId The id.
270 void SetId(int assetId
);
273 * @brief Get the video's asset type.
274 * @return The type or VideoAssetType::UNKNOWN if the item has no video asset.
276 VideoAssetType
GetType() const { return m_type
; }
279 * @brief Set this videos's asset type.
280 * @param assetType The type.
282 void SetType(VideoAssetType assetType
);
287 VideoAssetType m_type
{-1};
291 * @brief Get the video's asset info.
294 const CAssetInfo
& GetAssetInfo() const { return m_assetInfo
; }
295 CAssetInfo
& GetAssetInfo() { return m_assetInfo
; }
298 * @brief Whether the item has multiple video versions.
299 * @return True if the item has multiple video versions, false otherwise.
301 bool HasVideoVersions() const { return m_hasVideoVersions
; }
304 * @brief Set whether this video has video versions.
305 * @param hasVersion The versions flag.
307 void SetHasVideoVersions(bool hasVersions
);
310 * @brief Whether the item has video extras.
311 * @return True if the item has video extras, false otherwise.
313 bool HasVideoExtras() const { return m_hasVideoExtras
; }
316 * @brief Set whether this video has video extras.
317 * @param hasExtras The extras flag.
319 void SetHasVideoExtras(bool hasExtras
);
322 * @brief Whether the item is the default video version.
323 * @return True if the item is the default version, false otherwise.
325 bool IsDefaultVideoVersion() const { return m_isDefaultVideoVersion
; }
328 * @brief Set whether the item is the default version.
329 * @param isDefaultVideoVersion The default flag.
331 void SetIsDefaultVideoVersion(bool isDefaultVideoVersion
);
334 * @brief Get whether the Set Overview should be updated. If an NFO contains a <name> but no <overview> then
335 * this allows the current Overview to be kept. Otherwise it is overwritten. Default is true - so if updated
336 * by a scraper the Overview will be overwritten.
338 bool GetUpdateSetOverview() const { return m_updateSetOverview
; }
341 * @brief Set this videos's resume point.
342 * @param timeInSeconds the time of the resume point
343 * @param totalTimeInSeconds the total time of the video
344 * @param playerState the player state
345 * @return True if resume point was set successfully, false otherwise.
347 virtual bool SetResumePoint(double timeInSeconds
, double totalTimeInSeconds
, const std::string
&playerState
);
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
//!< Struct holding information about a movie set
367 std::string title
; //!< Title of the movie set
368 int id
; //!< ID of movie set in database
369 std::string overview
; //!< Overview/description of the movie set
371 SetInfo m_set
; //!< Assigned movie set
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
;
397 int m_iSpecialSortSeason
;
398 int m_iSpecialSortEpisode
;
403 CBookmark m_EpBookmark
;
408 CStreamDetails m_streamDetails
;
409 CDateTime m_dateAdded
;
411 int m_relevance
; // Used for actors' number of appearances
413 std::vector
<EmbeddedArtInfo
> m_coverArt
; ///< art information
415 // TODO: cannot be private, because of 'struct SDbTableOffsets'
416 unsigned int m_duration
; ///< duration in seconds
419 /* \brief Parse our native XML format for video info.
420 See Load for a description of the available tag types.
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.
426 void ParseNative(const TiXmlElement
* element
, bool prioritise
);
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
);
435 CBookmark m_resumePoint
;
436 static const int PLAYCOUNT_NOT_SET
= -1;
438 CAssetInfo m_assetInfo
;
439 bool m_hasVideoVersions
{false};
440 bool m_hasVideoExtras
{false};
441 bool m_isDefaultVideoVersion
{false};
443 bool m_updateSetOverview
{true};
446 typedef std::vector
<CVideoInfoTag
> VECMOVIES
;