[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / video / VideoDatabase.h
blob6c7344567b96c9289c2124185e75d3946b0d7440
1 /*
2 * Copyright (C) 2016-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.
7 */
9 #pragma once
11 #include "Bookmark.h"
12 #include "VideoInfoTag.h"
13 #include "addons/Scraper.h"
14 #include "dbwrappers/Database.h"
15 #include "utils/SortUtils.h"
16 #include "utils/UrlOptions.h"
18 #include <memory>
19 #include <set>
20 #include <utility>
21 #include <vector>
23 class CFileItem;
24 class CFileItemList;
25 class CVideoSettings;
26 class CGUIDialogProgress;
27 class CGUIDialogProgressBarHandle;
29 namespace dbiplus
31 class field_value;
32 typedef std::vector<field_value> sql_record;
35 #ifndef my_offsetof
36 #ifndef TARGET_POSIX
37 #define my_offsetof(TYPE, MEMBER) offsetof(TYPE, MEMBER)
38 #else
40 Custom version of standard offsetof() macro which can be used to get
41 offsets of members in class for non-POD types (according to the current
42 version of C++ standard offsetof() macro can't be used in such cases and
43 attempt to do so causes warnings to be emitted, OTOH in many cases it is
44 still OK to assume that all instances of the class has the same offsets
45 for the same members).
47 #define my_offsetof(TYPE, MEMBER) \
48 ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
49 #endif
50 #endif
52 typedef std::vector<CVideoInfoTag> VECMOVIES;
54 namespace VIDEO
56 class IVideoInfoScannerObserver;
57 struct SScanSettings;
60 enum VideoDbDetails
62 VideoDbDetailsNone = 0x00,
63 VideoDbDetailsRating = 0x01,
64 VideoDbDetailsTag = 0x02,
65 VideoDbDetailsShowLink = 0x04,
66 VideoDbDetailsStream = 0x08,
67 VideoDbDetailsCast = 0x10,
68 VideoDbDetailsBookmark = 0x20,
69 VideoDbDetailsUniqueID = 0x40,
70 VideoDbDetailsAll = 0xFF
71 } ;
73 // these defines are based on how many columns we have and which column certain data is going to be in
74 // when we do GetDetailsForMovie()
75 #define VIDEODB_MAX_COLUMNS 24
76 #define VIDEODB_DETAILS_FILEID 1
78 #define VIDEODB_DETAILS_MOVIE_SET_ID VIDEODB_MAX_COLUMNS + 2
79 #define VIDEODB_DETAILS_MOVIE_USER_RATING VIDEODB_MAX_COLUMNS + 3
80 #define VIDEODB_DETAILS_MOVIE_PREMIERED VIDEODB_MAX_COLUMNS + 4
81 #define VIDEODB_DETAILS_MOVIE_SET_NAME VIDEODB_MAX_COLUMNS + 5
82 #define VIDEODB_DETAILS_MOVIE_SET_OVERVIEW VIDEODB_MAX_COLUMNS + 6
83 #define VIDEODB_DETAILS_MOVIE_FILE VIDEODB_MAX_COLUMNS + 7
84 #define VIDEODB_DETAILS_MOVIE_PATH VIDEODB_MAX_COLUMNS + 8
85 #define VIDEODB_DETAILS_MOVIE_PLAYCOUNT VIDEODB_MAX_COLUMNS + 9
86 #define VIDEODB_DETAILS_MOVIE_LASTPLAYED VIDEODB_MAX_COLUMNS + 10
87 #define VIDEODB_DETAILS_MOVIE_DATEADDED VIDEODB_MAX_COLUMNS + 11
88 #define VIDEODB_DETAILS_MOVIE_RESUME_TIME VIDEODB_MAX_COLUMNS + 12
89 #define VIDEODB_DETAILS_MOVIE_TOTAL_TIME VIDEODB_MAX_COLUMNS + 13
90 #define VIDEODB_DETAILS_MOVIE_PLAYER_STATE VIDEODB_MAX_COLUMNS + 14
91 #define VIDEODB_DETAILS_MOVIE_RATING VIDEODB_MAX_COLUMNS + 15
92 #define VIDEODB_DETAILS_MOVIE_VOTES VIDEODB_MAX_COLUMNS + 16
93 #define VIDEODB_DETAILS_MOVIE_RATING_TYPE VIDEODB_MAX_COLUMNS + 17
94 #define VIDEODB_DETAILS_MOVIE_UNIQUEID_VALUE VIDEODB_MAX_COLUMNS + 18
95 #define VIDEODB_DETAILS_MOVIE_UNIQUEID_TYPE VIDEODB_MAX_COLUMNS + 19
97 #define VIDEODB_DETAILS_EPISODE_TVSHOW_ID VIDEODB_MAX_COLUMNS + 2
98 #define VIDEODB_DETAILS_EPISODE_USER_RATING VIDEODB_MAX_COLUMNS + 3
99 #define VIDEODB_DETAILS_EPISODE_SEASON_ID VIDEODB_MAX_COLUMNS + 4
100 #define VIDEODB_DETAILS_EPISODE_FILE VIDEODB_MAX_COLUMNS + 5
101 #define VIDEODB_DETAILS_EPISODE_PATH VIDEODB_MAX_COLUMNS + 6
102 #define VIDEODB_DETAILS_EPISODE_PLAYCOUNT VIDEODB_MAX_COLUMNS + 7
103 #define VIDEODB_DETAILS_EPISODE_LASTPLAYED VIDEODB_MAX_COLUMNS + 8
104 #define VIDEODB_DETAILS_EPISODE_DATEADDED VIDEODB_MAX_COLUMNS + 9
105 #define VIDEODB_DETAILS_EPISODE_TVSHOW_NAME VIDEODB_MAX_COLUMNS + 10
106 #define VIDEODB_DETAILS_EPISODE_TVSHOW_GENRE VIDEODB_MAX_COLUMNS + 11
107 #define VIDEODB_DETAILS_EPISODE_TVSHOW_STUDIO VIDEODB_MAX_COLUMNS + 12
108 #define VIDEODB_DETAILS_EPISODE_TVSHOW_AIRED VIDEODB_MAX_COLUMNS + 13
109 #define VIDEODB_DETAILS_EPISODE_TVSHOW_MPAA VIDEODB_MAX_COLUMNS + 14
110 #define VIDEODB_DETAILS_EPISODE_RESUME_TIME VIDEODB_MAX_COLUMNS + 15
111 #define VIDEODB_DETAILS_EPISODE_TOTAL_TIME VIDEODB_MAX_COLUMNS + 16
112 #define VIDEODB_DETAILS_EPISODE_PLAYER_STATE VIDEODB_MAX_COLUMNS + 17
113 #define VIDEODB_DETAILS_EPISODE_RATING VIDEODB_MAX_COLUMNS + 18
114 #define VIDEODB_DETAILS_EPISODE_VOTES VIDEODB_MAX_COLUMNS + 19
115 #define VIDEODB_DETAILS_EPISODE_RATING_TYPE VIDEODB_MAX_COLUMNS + 20
116 #define VIDEODB_DETAILS_EPISODE_UNIQUEID_VALUE VIDEODB_MAX_COLUMNS + 21
117 #define VIDEODB_DETAILS_EPISODE_UNIQUEID_TYPE VIDEODB_MAX_COLUMNS + 22
119 #define VIDEODB_DETAILS_TVSHOW_USER_RATING VIDEODB_MAX_COLUMNS + 1
120 #define VIDEODB_DETAILS_TVSHOW_DURATION VIDEODB_MAX_COLUMNS + 2
121 #define VIDEODB_DETAILS_TVSHOW_PARENTPATHID VIDEODB_MAX_COLUMNS + 3
122 #define VIDEODB_DETAILS_TVSHOW_PATH VIDEODB_MAX_COLUMNS + 4
123 #define VIDEODB_DETAILS_TVSHOW_DATEADDED VIDEODB_MAX_COLUMNS + 5
124 #define VIDEODB_DETAILS_TVSHOW_LASTPLAYED VIDEODB_MAX_COLUMNS + 6
125 #define VIDEODB_DETAILS_TVSHOW_NUM_EPISODES VIDEODB_MAX_COLUMNS + 7
126 #define VIDEODB_DETAILS_TVSHOW_NUM_WATCHED VIDEODB_MAX_COLUMNS + 8
127 #define VIDEODB_DETAILS_TVSHOW_NUM_SEASONS VIDEODB_MAX_COLUMNS + 9
128 #define VIDEODB_DETAILS_TVSHOW_RATING VIDEODB_MAX_COLUMNS + 10
129 #define VIDEODB_DETAILS_TVSHOW_VOTES VIDEODB_MAX_COLUMNS + 11
130 #define VIDEODB_DETAILS_TVSHOW_RATING_TYPE VIDEODB_MAX_COLUMNS + 12
131 #define VIDEODB_DETAILS_TVSHOW_UNIQUEID_VALUE VIDEODB_MAX_COLUMNS + 13
132 #define VIDEODB_DETAILS_TVSHOW_UNIQUEID_TYPE VIDEODB_MAX_COLUMNS + 14
134 #define VIDEODB_DETAILS_MUSICVIDEO_USER_RATING VIDEODB_MAX_COLUMNS + 2
135 #define VIDEODB_DETAILS_MUSICVIDEO_PREMIERED VIDEODB_MAX_COLUMNS + 3
136 #define VIDEODB_DETAILS_MUSICVIDEO_FILE VIDEODB_MAX_COLUMNS + 4
137 #define VIDEODB_DETAILS_MUSICVIDEO_PATH VIDEODB_MAX_COLUMNS + 5
138 #define VIDEODB_DETAILS_MUSICVIDEO_PLAYCOUNT VIDEODB_MAX_COLUMNS + 6
139 #define VIDEODB_DETAILS_MUSICVIDEO_LASTPLAYED VIDEODB_MAX_COLUMNS + 7
140 #define VIDEODB_DETAILS_MUSICVIDEO_DATEADDED VIDEODB_MAX_COLUMNS + 8
141 #define VIDEODB_DETAILS_MUSICVIDEO_RESUME_TIME VIDEODB_MAX_COLUMNS + 9
142 #define VIDEODB_DETAILS_MUSICVIDEO_TOTAL_TIME VIDEODB_MAX_COLUMNS + 10
143 #define VIDEODB_DETAILS_MUSICVIDEO_PLAYER_STATE VIDEODB_MAX_COLUMNS + 11
144 #define VIDEODB_DETAILS_MUSICVIDEO_UNIQUEID_VALUE VIDEODB_MAX_COLUMNS + 12
145 #define VIDEODB_DETAILS_MUSICVIDEO_UNIQUEID_TYPE VIDEODB_MAX_COLUMNS + 13
147 #define VIDEODB_TYPE_UNUSED 0
148 #define VIDEODB_TYPE_STRING 1
149 #define VIDEODB_TYPE_INT 2
150 #define VIDEODB_TYPE_FLOAT 3
151 #define VIDEODB_TYPE_BOOL 4
152 #define VIDEODB_TYPE_COUNT 5
153 #define VIDEODB_TYPE_STRINGARRAY 6
154 #define VIDEODB_TYPE_DATE 7
155 #define VIDEODB_TYPE_DATETIME 8
157 enum class VideoDbContentType
159 UNKNOWN = -1,
160 MOVIES = 1,
161 TVSHOWS = 2,
162 MUSICVIDEOS = 3,
163 EPISODES = 4,
164 MOVIE_SETS = 5,
165 MUSICALBUMS = 6
168 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
170 VIDEODB_ID_MIN = -1,
171 VIDEODB_ID_TITLE = 0,
172 VIDEODB_ID_PLOT = 1,
173 VIDEODB_ID_PLOTOUTLINE = 2,
174 VIDEODB_ID_TAGLINE = 3,
175 VIDEODB_ID_VOTES = 4, // unused
176 VIDEODB_ID_RATING_ID = 5,
177 VIDEODB_ID_CREDITS = 6,
178 VIDEODB_ID_YEAR = 7, // unused
179 VIDEODB_ID_THUMBURL = 8,
180 VIDEODB_ID_IDENT_ID = 9,
181 VIDEODB_ID_SORTTITLE = 10,
182 VIDEODB_ID_RUNTIME = 11,
183 VIDEODB_ID_MPAA = 12,
184 VIDEODB_ID_TOP250 = 13,
185 VIDEODB_ID_GENRE = 14,
186 VIDEODB_ID_DIRECTOR = 15,
187 VIDEODB_ID_ORIGINALTITLE = 16,
188 VIDEODB_ID_THUMBURL_SPOOF = 17,
189 VIDEODB_ID_STUDIOS = 18,
190 VIDEODB_ID_TRAILER = 19,
191 VIDEODB_ID_FANART = 20,
192 VIDEODB_ID_COUNTRY = 21,
193 VIDEODB_ID_BASEPATH = 22,
194 VIDEODB_ID_PARENTPATHID = 23,
195 VIDEODB_ID_MAX
196 } VIDEODB_IDS;
198 const struct SDbTableOffsets
200 int type;
201 size_t offset;
202 } DbMovieOffsets[] =
204 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTitle) },
205 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
206 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlotOutline) },
207 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTagLine) },
208 { VIDEODB_TYPE_UNUSED, 0 }, // unused
209 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdRating) },
210 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_writingCredits) },
211 { VIDEODB_TYPE_UNUSED, 0 }, // unused
212 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
213 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID) },
214 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strSortTitle) },
215 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_duration) },
216 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strMPAARating) },
217 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iTop250) },
218 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_genre) },
219 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_director) },
220 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strOriginalTitle) },
221 { VIDEODB_TYPE_UNUSED, 0 }, // unused
222 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_studio) },
223 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTrailer) },
224 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_fanart.m_xml) },
225 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_country) },
226 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_basePath) },
227 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_parentPathID) }
230 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
232 VIDEODB_ID_TV_MIN = -1,
233 VIDEODB_ID_TV_TITLE = 0,
234 VIDEODB_ID_TV_PLOT = 1,
235 VIDEODB_ID_TV_STATUS = 2,
236 VIDEODB_ID_TV_VOTES = 3, // unused
237 VIDEODB_ID_TV_RATING_ID = 4,
238 VIDEODB_ID_TV_PREMIERED = 5,
239 VIDEODB_ID_TV_THUMBURL = 6,
240 VIDEODB_ID_TV_THUMBURL_SPOOF = 7,
241 VIDEODB_ID_TV_GENRE = 8,
242 VIDEODB_ID_TV_ORIGINALTITLE = 9,
243 VIDEODB_ID_TV_EPISODEGUIDE = 10,
244 VIDEODB_ID_TV_FANART = 11,
245 VIDEODB_ID_TV_IDENT_ID = 12,
246 VIDEODB_ID_TV_MPAA = 13,
247 VIDEODB_ID_TV_STUDIOS = 14,
248 VIDEODB_ID_TV_SORTTITLE = 15,
249 VIDEODB_ID_TV_TRAILER = 16,
250 VIDEODB_ID_TV_MAX
251 } VIDEODB_TV_IDS;
253 const struct SDbTableOffsets DbTvShowOffsets[] =
255 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTitle) },
256 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
257 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strStatus) },
258 { VIDEODB_TYPE_UNUSED, 0 }, //unused
259 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdRating) },
260 { VIDEODB_TYPE_DATE, my_offsetof(CVideoInfoTag,m_premiered) },
261 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
262 { VIDEODB_TYPE_UNUSED, 0 }, // unused
263 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_genre) },
264 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strOriginalTitle)},
265 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strEpisodeGuide)},
266 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_fanart.m_xml)},
267 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID)},
268 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strMPAARating)},
269 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_studio)},
270 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strSortTitle)},
271 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTrailer)}
274 //! @todo is this comment valid for seasons? There is no offset structure or am I wrong?
275 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
277 VIDEODB_ID_SEASON_MIN = -1,
278 VIDEODB_ID_SEASON_ID = 0,
279 VIDEODB_ID_SEASON_TVSHOW_ID = 1,
280 VIDEODB_ID_SEASON_NUMBER = 2,
281 VIDEODB_ID_SEASON_NAME = 3,
282 VIDEODB_ID_SEASON_USER_RATING = 4,
283 VIDEODB_ID_SEASON_TVSHOW_PATH = 5,
284 VIDEODB_ID_SEASON_TVSHOW_TITLE = 6,
285 VIDEODB_ID_SEASON_TVSHOW_PLOT = 7,
286 VIDEODB_ID_SEASON_TVSHOW_PREMIERED = 8,
287 VIDEODB_ID_SEASON_TVSHOW_GENRE = 9,
288 VIDEODB_ID_SEASON_TVSHOW_STUDIO = 10,
289 VIDEODB_ID_SEASON_TVSHOW_MPAA = 11,
290 VIDEODB_ID_SEASON_EPISODES_TOTAL = 12,
291 VIDEODB_ID_SEASON_EPISODES_WATCHED = 13,
292 VIDEODB_ID_SEASON_PREMIERED = 14,
293 VIDEODB_ID_SEASON_MAX
294 } VIDEODB_SEASON_IDS;
296 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
298 VIDEODB_ID_EPISODE_MIN = -1,
299 VIDEODB_ID_EPISODE_TITLE = 0,
300 VIDEODB_ID_EPISODE_PLOT = 1,
301 VIDEODB_ID_EPISODE_VOTES = 2, // unused
302 VIDEODB_ID_EPISODE_RATING_ID = 3,
303 VIDEODB_ID_EPISODE_CREDITS = 4,
304 VIDEODB_ID_EPISODE_AIRED = 5,
305 VIDEODB_ID_EPISODE_THUMBURL = 6,
306 VIDEODB_ID_EPISODE_THUMBURL_SPOOF = 7,
307 VIDEODB_ID_EPISODE_PLAYCOUNT = 8, // unused - feel free to repurpose
308 VIDEODB_ID_EPISODE_RUNTIME = 9,
309 VIDEODB_ID_EPISODE_DIRECTOR = 10,
310 VIDEODB_ID_EPISODE_PRODUCTIONCODE = 11,
311 VIDEODB_ID_EPISODE_SEASON = 12,
312 VIDEODB_ID_EPISODE_EPISODE = 13,
313 VIDEODB_ID_EPISODE_ORIGINALTITLE = 14,
314 VIDEODB_ID_EPISODE_SORTSEASON = 15,
315 VIDEODB_ID_EPISODE_SORTEPISODE = 16,
316 VIDEODB_ID_EPISODE_BOOKMARK = 17,
317 VIDEODB_ID_EPISODE_BASEPATH = 18,
318 VIDEODB_ID_EPISODE_PARENTPATHID = 19,
319 VIDEODB_ID_EPISODE_IDENT_ID = 20,
320 VIDEODB_ID_EPISODE_MAX
321 } VIDEODB_EPISODE_IDS;
323 const struct SDbTableOffsets DbEpisodeOffsets[] =
325 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTitle) },
326 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
327 { VIDEODB_TYPE_UNUSED, 0 }, // unused
328 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdRating) },
329 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_writingCredits) },
330 { VIDEODB_TYPE_DATE, my_offsetof(CVideoInfoTag,m_firstAired) },
331 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
332 { VIDEODB_TYPE_UNUSED, 0 }, // unused
333 { VIDEODB_TYPE_UNUSED, 0 }, // unused
334 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_duration) },
335 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_director) },
336 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strProductionCode) },
337 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iSeason) },
338 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iEpisode) },
339 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strOriginalTitle)},
340 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iSpecialSortSeason) },
341 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iSpecialSortEpisode) },
342 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iBookmarkId) },
343 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_basePath) },
344 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_parentPathID) },
345 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID) }
348 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
350 VIDEODB_ID_MUSICVIDEO_MIN = -1,
351 VIDEODB_ID_MUSICVIDEO_TITLE = 0,
352 VIDEODB_ID_MUSICVIDEO_THUMBURL = 1,
353 VIDEODB_ID_MUSICVIDEO_THUMBURL_SPOOF = 2,
354 VIDEODB_ID_MUSICVIDEO_PLAYCOUNT = 3, // unused - feel free to repurpose
355 VIDEODB_ID_MUSICVIDEO_RUNTIME = 4,
356 VIDEODB_ID_MUSICVIDEO_DIRECTOR = 5,
357 VIDEODB_ID_MUSICVIDEO_STUDIOS = 6,
358 VIDEODB_ID_MUSICVIDEO_YEAR = 7, // unused
359 VIDEODB_ID_MUSICVIDEO_PLOT = 8,
360 VIDEODB_ID_MUSICVIDEO_ALBUM = 9,
361 VIDEODB_ID_MUSICVIDEO_ARTIST = 10,
362 VIDEODB_ID_MUSICVIDEO_GENRE = 11,
363 VIDEODB_ID_MUSICVIDEO_TRACK = 12,
364 VIDEODB_ID_MUSICVIDEO_BASEPATH = 13,
365 VIDEODB_ID_MUSICVIDEO_PARENTPATHID = 14,
366 VIDEODB_ID_MUSICVIDEO_IDENT_ID = 15,
367 VIDEODB_ID_MUSICVIDEO_MAX
368 } VIDEODB_MUSICVIDEO_IDS;
370 const struct SDbTableOffsets DbMusicVideoOffsets[] =
372 { VIDEODB_TYPE_STRING, my_offsetof(class CVideoInfoTag,m_strTitle) },
373 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
374 { VIDEODB_TYPE_UNUSED, 0 }, // unused
375 { VIDEODB_TYPE_UNUSED, 0 }, // unused
376 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_duration) },
377 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_director) },
378 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_studio) },
379 { VIDEODB_TYPE_UNUSED, 0 }, // unused
380 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
381 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strAlbum) },
382 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_artist) },
383 { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_genre) },
384 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iTrack) },
385 { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_basePath) },
386 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_parentPathID) },
387 { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID)}
390 #define COMPARE_PERCENTAGE 0.90f // 90%
391 #define COMPARE_PERCENTAGE_MIN 0.50f // 50%
393 class CVideoDatabase : public CDatabase
395 public:
397 class CActor // used for actor retrieval for non-master users
399 public:
400 std::string name;
401 std::string thumb;
402 int playcount;
403 int appearances;
406 class CSeason // used for season retrieval for non-master users
408 public:
409 std::string path;
410 std::vector<std::string> genre;
411 int numEpisodes;
412 int numWatched;
413 int id;
416 class CSetInfo
418 public:
419 std::string name;
420 VECMOVIES movies;
421 DatabaseResults results;
424 CVideoDatabase(void);
425 ~CVideoDatabase(void) override;
427 bool Open() override;
428 bool CommitTransaction() override;
430 int AddNewEpisode(int idShow, CVideoInfoTag& details);
432 // editing functions
433 /*! \brief Set the playcount of an item, update last played time
434 Sets the playcount and last played date to a given value
435 \param item CFileItem to set the playcount for
436 \param count The playcount to set.
437 \param date The date the file was last viewed (does not denote the video was watched to completion).
438 If empty we use current datetime (if count > 0) or never viewed (if count = 0).
439 \return on success, the new last played time set, invalid datetime otherwise.
440 \sa GetPlayCount, IncrementPlayCount, UpdateLastPlayed
442 CDateTime SetPlayCount(const CFileItem& item, int count, const CDateTime& date = CDateTime());
444 /*! \brief Increment the playcount of an item
445 Increments the playcount and updates the last played date
446 \param item CFileItem to increment the playcount for
447 \return on success, the new last played time set, invalid datetime otherwise.
448 \sa GetPlayCount, SetPlayCount, GetPlayCounts
450 CDateTime IncrementPlayCount(const CFileItem& item);
452 /*! \brief Get the playcount of an item
453 \param item CFileItem to get the playcount for
454 \return the playcount of the item, or -1 on error
455 \sa SetPlayCount, IncrementPlayCount, GetPlayCounts
457 int GetPlayCount(const CFileItem &item);
459 /*! \brief Get the playcount of a filename and path
460 \param strFilenameAndPath filename and path to get the playcount for
461 \return the playcount of the item, or -1 on error
462 \sa SetPlayCount, IncrementPlayCount, GetPlayCounts
464 int GetPlayCount(const std::string& strFilenameAndPath);
466 /*! \brief Get the last played time of a filename and path
467 \param strFilenameAndPath filename and path to get the last played time for
468 \return the last played time of the item, or an invalid CDateTime on error
469 \sa UpdateLastPlayed
471 CDateTime GetLastPlayed(const std::string& strFilenameAndPath);
473 /*! \brief Update the last played time of an item
474 Updates the last played date
475 \param item CFileItem to update the last played time for
476 \return on success, the last played time set, invalid datetime otherwise.
477 \sa GetPlayCount, SetPlayCount, IncrementPlayCount, GetPlayCounts
479 CDateTime UpdateLastPlayed(const CFileItem& item);
481 /*! \brief Get the playcount and resume point of a list of items
482 Note that if the resume point is already set on an item, it won't be overridden.
483 \param path the path to fetch videos from
484 \param items CFileItemList to fetch the playcounts for
485 \sa GetPlayCount, SetPlayCount, IncrementPlayCount
487 bool GetPlayCounts(const std::string &path, CFileItemList &items);
489 void UpdateMovieTitle(int idMovie,
490 const std::string& strNewMovieTitle,
491 VideoDbContentType iType = VideoDbContentType::MOVIES);
492 bool UpdateVideoSortTitle(int idDb,
493 const std::string& strNewSortTitle,
494 VideoDbContentType iType = VideoDbContentType::MOVIES);
496 bool HasMovieInfo(const std::string& strFilenameAndPath);
497 bool HasTvShowInfo(const std::string& strFilenameAndPath);
498 bool HasEpisodeInfo(const std::string& strFilenameAndPath);
499 bool HasMusicVideoInfo(const std::string& strFilenameAndPath);
501 void GetFilePathById(int idMovie, std::string& filePath, VideoDbContentType iType);
502 std::string GetGenreById(int id);
503 std::string GetCountryById(int id);
504 std::string GetSetById(int id);
505 std::string GetTagById(int id);
506 std::string GetPersonById(int id);
507 std::string GetStudioById(int id);
508 std::string GetTvShowTitleById(int id);
509 std::string GetMusicVideoAlbumById(int id);
510 int GetTvShowForEpisode(int idEpisode);
511 int GetSeasonForEpisode(int idEpisode);
513 bool LoadVideoInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int getDetails = VideoDbDetailsAll);
514 bool GetMovieInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idMovie = -1, int getDetails = VideoDbDetailsAll);
515 bool GetTvShowInfo(const std::string& strPath, CVideoInfoTag& details, int idTvShow = -1, CFileItem* item = NULL, int getDetails = VideoDbDetailsAll);
516 bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, CFileItem* item);
517 bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, bool allDetails = true);
518 bool GetEpisodeBasicInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1);
519 bool GetEpisodeInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1, int getDetails = VideoDbDetailsAll);
520 bool GetMusicVideoInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idMVideo = -1, int getDetails = VideoDbDetailsAll);
521 bool GetSetInfo(int idSet, CVideoInfoTag& details, CFileItem* item = nullptr);
522 bool GetFileInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idFile = -1);
524 int GetPathId(const std::string& strPath);
525 int GetTvShowId(const std::string& strPath);
526 int GetEpisodeId(const std::string& strFilenameAndPath, int idEpisode=-1, int idSeason=-1); // idEpisode, idSeason are used for multipart episodes as hints
527 int GetSeasonId(int idShow, int season);
529 void GetEpisodesByFile(const std::string& strFilenameAndPath, std::vector<CVideoInfoTag>& episodes);
531 int SetDetailsForItem(CVideoInfoTag& details, const std::map<std::string, std::string> &artwork);
532 int SetDetailsForItem(int id, const MediaType& mediaType, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork);
534 int SetDetailsForMovie(CVideoInfoTag& details,
535 const std::map<std::string, std::string>& artwork,
536 int idMovie = -1);
537 int SetDetailsForMovieSet(const CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, int idSet = -1);
539 /*! \brief add a tvshow to the library, setting metadata detail
540 First checks for whether this TV Show is already in the database (based on idTvShow, or via GetMatchingTvShow)
541 and if present adds the paths to the show. If not present, we add a new show and set the show metadata.
542 \param paths a vector<string,string> list of the path(s) and parent path(s) for the show.
543 \param details a CVideoInfoTag filled with the metadata for the show.
544 \param artwork the artwork map for the show.
545 \param seasonArt the artwork map for seasons.
546 \param idTvShow the database id of the tvshow if known (defaults to -1)
547 \return the id of the tvshow.
549 int SetDetailsForTvShow(const std::vector< std::pair<std::string, std::string> > &paths, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, const std::map<int, std::map<std::string, std::string> > &seasonArt, int idTvShow = -1);
550 bool UpdateDetailsForTvShow(int idTvShow, CVideoInfoTag &details, const std::map<std::string, std::string> &artwork, const std::map<int, std::map<std::string, std::string> > &seasonArt);
551 int SetDetailsForSeason(const CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, int idShow, int idSeason = -1);
552 int SetDetailsForEpisode(CVideoInfoTag& details,
553 const std::map<std::string, std::string>& artwork,
554 int idShow,
555 int idEpisode = -1);
556 int SetDetailsForMusicVideo(CVideoInfoTag& details,
557 const std::map<std::string, std::string>& artwork,
558 int idMVideo = -1);
559 void SetStreamDetailsForFile(const CStreamDetails& details, const std::string &strFileNameAndPath);
560 void SetStreamDetailsForFileId(const CStreamDetails& details, int idFile);
562 bool SetSingleValue(VideoDbContentType type, int dbId, int dbField, const std::string& strValue);
563 bool SetSingleValue(VideoDbContentType type,
564 int dbId,
565 Field dbField,
566 const std::string& strValue);
567 bool SetSingleValue(const std::string &table, const std::string &fieldName, const std::string &strValue,
568 const std::string &conditionName = "", int conditionValue = -1);
570 int UpdateDetailsForMovie(int idMovie, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, const std::set<std::string> &updatedDetails);
572 void DeleteMovie(int idMovie, bool bKeepId = false);
573 void DeleteTvShow(int idTvShow, bool bKeepId = false);
574 void DeleteTvShow(const std::string& strPath);
575 void DeleteSeason(int idSeason, bool bKeepId = false);
576 void DeleteEpisode(int idEpisode, bool bKeepId = false);
577 void DeleteMusicVideo(int idMusicVideo, bool bKeepId = false);
578 void DeleteDetailsForTvShow(int idTvShow);
579 void DeleteStreamDetails(int idFile);
580 void RemoveContentForPath(const std::string& strPath,CGUIDialogProgress *progress = NULL);
581 void UpdateFanart(const CFileItem& item, VideoDbContentType type);
582 void DeleteSet(int idSet);
583 void DeleteTag(int idTag, VideoDbContentType mediaType);
585 /*! \brief Get video settings for the specified file id
586 \param idFile file id to get the settings for
587 \return true if video settings found, false otherwise
588 \sa SetVideoSettings
590 bool GetVideoSettings(int idFile, CVideoSettings &settings);
592 /*! \brief Get video settings for the specified file item
593 \param item item to get the settings for
594 \return true if video settings found, false otherwise
595 \sa SetVideoSettings
597 bool GetVideoSettings(const CFileItem &item, CVideoSettings &settings);
599 /*! \brief Get video settings for the specified file path
600 \param filePath filepath to get the settings for
601 \return true if video settings found, false otherwise
602 \sa SetVideoSettings
604 bool GetVideoSettings(const std::string &filePath, CVideoSettings &settings);
606 /*! \brief Set video settings for the specified file path
607 \param fileItem to set the settings for
608 \sa GetVideoSettings
610 void SetVideoSettings(const CFileItem &item, const CVideoSettings &settings);
612 /*! \brief Set video settings for the specified file path
613 \param fileId to set the settings for
614 \sa GetVideoSettings
616 void SetVideoSettings(int idFile, const CVideoSettings &settings);
619 * Erases video settings for file item
620 * @param fileitem
622 void EraseVideoSettings(const CFileItem &item);
625 * Erases all video settings
627 void EraseAllVideoSettings();
630 * Erases video settings for files starting with path
631 * @param path pattern
633 void EraseAllVideoSettings(const std::string& path);
636 * Erases all entries for files starting with path, including the files and path entries
637 * @param path pattern
639 void EraseAllForPath(const std::string& path);
641 bool GetStackTimes(const std::string &filePath, std::vector<uint64_t> &times);
642 void SetStackTimes(const std::string &filePath, const std::vector<uint64_t> &times);
644 void GetBookMarksForFile(const std::string& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type = CBookmark::STANDARD, bool bAppend=false, long partNumber=0);
645 void AddBookMarkToFile(const std::string& strFilenameAndPath, const CBookmark &bookmark, CBookmark::EType type = CBookmark::STANDARD);
646 bool GetResumeBookMark(const std::string& strFilenameAndPath, CBookmark &bookmark);
647 void DeleteResumeBookMark(const CFileItem& item);
648 void ClearBookMarkOfFile(const std::string& strFilenameAndPath, CBookmark& bookmark, CBookmark::EType type = CBookmark::STANDARD);
649 void ClearBookMarksOfFile(const std::string& strFilenameAndPath, CBookmark::EType type = CBookmark::STANDARD);
650 void ClearBookMarksOfFile(int idFile, CBookmark::EType type = CBookmark::STANDARD);
651 bool GetBookMarkForEpisode(const CVideoInfoTag& tag, CBookmark& bookmark);
652 void AddBookMarkForEpisode(const CVideoInfoTag& tag, const CBookmark& bookmark);
653 void DeleteBookMarkForEpisode(const CVideoInfoTag& tag);
654 bool GetResumePoint(CVideoInfoTag& tag);
655 bool GetStreamDetails(CFileItem& item);
656 bool GetStreamDetails(CVideoInfoTag& tag) const;
657 bool GetDetailsByTypeAndId(CFileItem& item, VideoDbContentType type, int id);
658 CVideoInfoTag GetDetailsByTypeAndId(VideoDbContentType type, int id);
660 // scraper settings
661 void SetScraperForPath(const std::string& filePath, const ADDON::ScraperPtr& info, const VIDEO::SScanSettings& settings);
662 ADDON::ScraperPtr GetScraperForPath(const std::string& strPath);
663 ADDON::ScraperPtr GetScraperForPath(const std::string& strPath, VIDEO::SScanSettings& settings);
665 /*! \brief Retrieve the scraper and settings we should use for the specified path
666 If the scraper is not set on this particular path, we'll recursively check parent folders.
667 \param strPath path to start searching in.
668 \param settings [out] scan settings for this folder.
669 \param foundDirectly [out] true if a scraper was found directly for strPath, false if it was in a parent path.
670 \return A ScraperPtr containing the scraper information. Returns NULL if a trivial (Content == CONTENT_NONE)
671 scraper or no scraper is found.
673 ADDON::ScraperPtr GetScraperForPath(const std::string& strPath, VIDEO::SScanSettings& settings, bool& foundDirectly);
675 /*! \brief Retrieve the content type of videos in the given path
676 If content is set on the folder, we return the given content type, except in the case of tvshows,
677 where we first check for whether we have episodes directly in the path (thus return episodes) or whether
678 we've found a scraper directly (shows). Any folders inbetween are treated as seasons (regardless of whether
679 they actually are seasons). Note that any subfolders in movies will be treated as movies.
680 \param strPath path to start searching in.
681 \return A content type string for the current path.
683 std::string GetContentForPath(const std::string& strPath);
685 /*! \brief Get videos of the given content type from the given path
686 \param content the content type to fetch.
687 \param path the path to fetch videos from.
688 \param items the returned items
689 \return true if items are found, false otherwise.
691 bool GetItemsForPath(const std::string &content, const std::string &path, CFileItemList &items);
693 /*! \brief Check whether a given scraper is in use.
694 \param scraperID the scraper to check for.
695 \return true if the scraper is in use, false otherwise.
697 bool ScraperInUse(const std::string &scraperID) const;
699 // scanning hashes and paths scanned
700 bool SetPathHash(const std::string &path, const std::string &hash);
701 bool GetPathHash(const std::string &path, std::string &hash);
702 bool GetPaths(std::set<std::string> &paths);
703 bool GetPathsForTvShow(int idShow, std::set<int>& paths);
705 /*! \brief return the paths linked to a tvshow.
706 \param idShow the id of the tvshow.
707 \param paths [out] the list of paths associated with the show.
708 \return true on success, false on failure.
710 bool GetPathsLinkedToTvShow(int idShow, std::vector<std::string> &paths);
712 /*! \brief retrieve subpaths of a given path. Assumes a hierarchical folder structure
713 \param basepath the root path to retrieve subpaths for
714 \param subpaths the returned subpaths
715 \return true if we successfully retrieve subpaths (may be zero), false on error
717 bool GetSubPaths(const std::string& basepath, std::vector< std::pair<int, std::string> >& subpaths);
719 bool GetSourcePath(const std::string &path, std::string &sourcePath);
720 bool GetSourcePath(const std::string &path, std::string &sourcePath, VIDEO::SScanSettings& settings);
722 // for music + musicvideo linkups - if no album and title given it will return the artist id, else the id of the matching video
723 int GetMatchingMusicVideo(const std::string& strArtist, const std::string& strAlbum = "", const std::string& strTitle = "");
725 // searching functions
726 void GetMoviesByActor(const std::string& strActor, CFileItemList& items);
727 void GetTvShowsByActor(const std::string& strActor, CFileItemList& items);
728 void GetEpisodesByActor(const std::string& strActor, CFileItemList& items);
730 void GetMusicVideosByArtist(const std::string& strArtist, CFileItemList& items);
731 void GetMusicVideosByAlbum(const std::string& strAlbum, CFileItemList& items);
733 void GetMovieGenresByName(const std::string& strSearch, CFileItemList& items);
734 void GetTvShowGenresByName(const std::string& strSearch, CFileItemList& items);
735 void GetMusicVideoGenresByName(const std::string& strSearch, CFileItemList& items);
737 void GetMovieCountriesByName(const std::string& strSearch, CFileItemList& items);
739 void GetMusicVideoAlbumsByName(const std::string& strSearch, CFileItemList& items);
741 void GetMovieActorsByName(const std::string& strSearch, CFileItemList& items);
742 void GetTvShowsActorsByName(const std::string& strSearch, CFileItemList& items);
743 void GetMusicVideoArtistsByName(const std::string& strSearch, CFileItemList& items);
745 void GetMovieDirectorsByName(const std::string& strSearch, CFileItemList& items);
746 void GetTvShowsDirectorsByName(const std::string& strSearch, CFileItemList& items);
747 void GetMusicVideoDirectorsByName(const std::string& strSearch, CFileItemList& items);
749 void GetMoviesByName(const std::string& strSearch, CFileItemList& items);
750 void GetTvShowsByName(const std::string& strSearch, CFileItemList& items);
751 void GetEpisodesByName(const std::string& strSearch, CFileItemList& items);
752 void GetMusicVideosByName(const std::string& strSearch, CFileItemList& items);
754 void GetEpisodesByPlot(const std::string& strSearch, CFileItemList& items);
755 void GetMoviesByPlot(const std::string& strSearch, CFileItemList& items);
757 bool LinkMovieToTvshow(int idMovie, int idShow, bool bRemove);
758 bool IsLinkedToTvshow(int idMovie);
759 bool GetLinksToTvShow(int idMovie, std::vector<int>& ids);
761 // general browsing
762 bool GetGenresNav(const std::string& strBaseDir,
763 CFileItemList& items,
764 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
765 const Filter& filter = Filter(),
766 bool countOnly = false);
767 bool GetCountriesNav(const std::string& strBaseDir,
768 CFileItemList& items,
769 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
770 const Filter& filter = Filter(),
771 bool countOnly = false);
772 bool GetStudiosNav(const std::string& strBaseDir,
773 CFileItemList& items,
774 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
775 const Filter& filter = Filter(),
776 bool countOnly = false);
777 bool GetYearsNav(const std::string& strBaseDir,
778 CFileItemList& items,
779 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
780 const Filter& filter = Filter());
781 bool GetActorsNav(const std::string& strBaseDir,
782 CFileItemList& items,
783 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
784 const Filter& filter = Filter(),
785 bool countOnly = false);
786 bool GetDirectorsNav(const std::string& strBaseDir,
787 CFileItemList& items,
788 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
789 const Filter& filter = Filter(),
790 bool countOnly = false);
791 bool GetWritersNav(const std::string& strBaseDir,
792 CFileItemList& items,
793 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
794 const Filter& filter = Filter(),
795 bool countOnly = false);
796 bool GetSetsNav(const std::string& strBaseDir,
797 CFileItemList& items,
798 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
799 const Filter& filter = Filter(),
800 bool ignoreSingleMovieSets = false);
801 bool GetTagsNav(const std::string& strBaseDir,
802 CFileItemList& items,
803 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
804 const Filter& filter = Filter(),
805 bool countOnly = false);
806 bool GetMusicVideoAlbumsNav(const std::string& strBaseDir, CFileItemList& items, int idArtist, const Filter &filter = Filter(), bool countOnly = false);
808 bool GetMoviesNav(const std::string& strBaseDir, CFileItemList& items, int idGenre=-1, int idYear=-1, int idActor=-1, int idDirector=-1, int idStudio=-1, int idCountry=-1, int idSet=-1, int idTag=-1, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
809 bool GetTvShowsNav(const std::string& strBaseDir, CFileItemList& items, int idGenre=-1, int idYear=-1, int idActor=-1, int idDirector=-1, int idStudio=-1, int idTag=-1, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
810 bool GetSeasonsNav(const std::string& strBaseDir, CFileItemList& items, int idActor=-1, int idDirector=-1, int idGenre=-1, int idYear=-1, int idShow=-1, bool getLinkedMovies = true);
811 bool GetEpisodesNav(const std::string& strBaseDir, CFileItemList& items, int idGenre=-1, int idYear=-1, int idActor=-1, int idDirector=-1, int idShow=-1, int idSeason=-1, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
812 bool GetMusicVideosNav(const std::string& strBaseDir, CFileItemList& items, int idGenre=-1, int idYear=-1, int idArtist=-1, int idDirector=-1, int idStudio=-1, int idAlbum=-1, int idTag=-1, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
814 bool GetRecentlyAddedMoviesNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
815 bool GetRecentlyAddedEpisodesNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
816 bool GetRecentlyAddedMusicVideosNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
817 bool GetInProgressTvShowsNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
819 bool HasContent();
820 bool HasContent(VideoDbContentType type);
821 bool HasSets() const;
823 void CleanDatabase(CGUIDialogProgressBarHandle* handle = NULL, const std::set<int>& paths = std::set<int>(), bool showProgress = true);
825 /*! \brief Add a file to the database, if necessary
826 If the file is already in the database, we simply return its id.
827 \param url - full path of the file to add.
828 \param parentPath the parent path of the path to add. If empty, URIUtils::GetParentPath() will determine the path.
829 \param dateAdded datetime when the file was added to the filesystem/database
830 \param playcount the playcount of the file to add.
831 \param lastPlayed the date and time when the file to add was last played.
832 \return id of the file, -1 if it could not be added.
834 int AddFile(const std::string& url,
835 const std::string& parentPath = "",
836 const CDateTime& dateAdded = CDateTime(),
837 int playcount = 0,
838 const CDateTime& lastPlayed = CDateTime());
840 /*! \brief Add a file to the database, if necessary
841 Works for both videodb:// items and normal fileitems
842 \param item CFileItem to add.
843 \return id of the file, -1 if it could not be added.
845 int AddFile(const CFileItem& item);
847 /*! \brief Add a file to the database, if necessary
848 Works for both videodb:// items and normal fileitems
849 \param url full path of the file to add.
850 \param details details of the item to add.
851 \return id of the file, -1 if it could not be added.
853 int AddFile(const CVideoInfoTag& details, const std::string& parentPath = "");
855 /*! \brief Add a path to the database, if necessary
856 If the path is already in the database, we simply return its id.
857 \param strPath the path to add
858 \param parentPath the parent path of the path to add. If empty, URIUtils::GetParentPath() will determine the path.
859 \param dateAdded datetime when the path was added to the filesystem/database
860 \return id of the file, -1 if it could not be added.
862 int AddPath(const std::string& strPath, const std::string &parentPath = "", const CDateTime& dateAdded = CDateTime());
864 /*! \brief Updates the dateAdded field in the files table for the file
865 with the given idFile and the given path based on the files modification date
866 \param details details of the video file
868 void UpdateFileDateAdded(CVideoInfoTag& details);
870 void ExportToXML(const std::string &path, bool singleFile = true, bool images=false, bool actorThumbs=false, bool overwrite=false);
871 void ExportActorThumbs(const std::string &path, const CVideoInfoTag& tag, bool singleFiles, bool overwrite=false);
872 void ImportFromXML(const std::string &path);
873 void DumpToDummyFiles(const std::string &path);
874 bool ImportArtFromXML(const TiXmlNode *node, std::map<std::string, std::string> &artwork);
876 // smart playlists and main retrieval work in these functions
877 bool GetMoviesByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
878 bool GetSetsByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, bool ignoreSingleMovieSets = false);
879 bool GetTvShowsByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
880 bool GetSeasonsByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, bool appendFullShowPath = true, const SortDescription &sortDescription = SortDescription());
881 bool GetEpisodesByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, bool appendFullShowPath = true, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
882 bool GetMusicVideosByWhere(const std::string &baseDir, const Filter &filter, CFileItemList& items, bool checkLocks = true, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
884 // retrieve sorted and limited items
885 bool GetSortedVideos(const MediaType &mediaType, const std::string& strBaseDir, const SortDescription &sortDescription, CFileItemList& items, const Filter &filter = Filter());
887 // retrieve a list of items
888 bool GetItems(const std::string &strBaseDir, CFileItemList &items, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription());
889 bool GetItems(const std::string &strBaseDir, const std::string &mediaType, const std::string &itemType, CFileItemList &items, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription());
890 bool GetItems(const std::string& strBaseDir,
891 VideoDbContentType mediaType,
892 const std::string& itemType,
893 CFileItemList& items,
894 const Filter& filter = Filter(),
895 const SortDescription& sortDescription = SortDescription());
896 std::string GetItemById(const std::string &itemType, int id);
898 // partymode
899 /*! \brief Gets music video IDs in random order that match the where clause
900 \param strWhere the SQL where clause to apply in the query
901 \param songIDs a vector of <2, id> pairs suited to party mode use
902 \return count of music video IDs found.
904 unsigned int GetRandomMusicVideoIDs(const std::string& strWhere, std::vector<std::pair<int, int> > &songIDs);
906 static void VideoContentTypeToString(VideoDbContentType type, std::string& out)
908 switch (type)
910 case VideoDbContentType::MOVIES:
911 out = MediaTypeMovie;
912 break;
913 case VideoDbContentType::TVSHOWS:
914 out = MediaTypeTvShow;
915 break;
916 case VideoDbContentType::EPISODES:
917 out = MediaTypeEpisode;
918 break;
919 case VideoDbContentType::MUSICVIDEOS:
920 out = MediaTypeMusicVideo;
921 break;
922 default:
923 break;
927 void SetArtForItem(int mediaId, const MediaType &mediaType, const std::string &artType, const std::string &url);
928 void SetArtForItem(int mediaId, const MediaType &mediaType, const std::map<std::string, std::string> &art);
929 bool GetArtForItem(int mediaId, const MediaType &mediaType, std::map<std::string, std::string> &art);
930 std::string GetArtForItem(int mediaId, const MediaType &mediaType, const std::string &artType);
931 bool HasArtForItem(int mediaId, const MediaType &mediaType);
932 bool RemoveArtForItem(int mediaId, const MediaType &mediaType, const std::string &artType);
933 bool RemoveArtForItem(int mediaId, const MediaType &mediaType, const std::set<std::string> &artTypes);
934 bool GetTvShowSeasons(int showId, std::map<int, int> &seasons);
935 bool GetTvShowNamedSeasons(int showId, std::map<int, std::string> &seasons);
936 bool GetTvShowSeasonArt(int mediaId, std::map<int, std::map<std::string, std::string> > &seasonArt);
937 bool GetArtTypes(const MediaType &mediaType, std::vector<std::string> &artTypes);
939 /*! \brief Fetch the distinct types of available-but-unassigned art held in the
940 database for a specific media item.
941 \param mediaId the id in the media table.
942 \param mediaType the type of media, which corresponds to the table the item resides in.
943 \return the types of art e.g. "thumb", "fanart", etc.
945 std::vector<std::string> GetAvailableArtTypesForItem(int mediaId, const MediaType& mediaType);
947 /*! \brief Fetch the list of available-but-unassigned art URLs held in the
948 database for a specific media item and art type.
949 \param mediaId the id in the media table.
950 \param mediaType corresponds to the table the item resides in.
951 \param artType e.g. "thumb", "fanart", etc.
952 \return list of URLs
954 std::vector<CScraperUrl::SUrlEntry> GetAvailableArtForItem(
955 int mediaId, const MediaType& mediaType, const std::string& artType);
957 int AddTag(const std::string &tag);
958 void AddTagToItem(int idItem, int idTag, const std::string &type);
959 void RemoveTagFromItem(int idItem, int idTag, const std::string &type);
960 void RemoveTagsFromItem(int idItem, const std::string &type);
962 bool GetFilter(CDbUrl &videoUrl, Filter &filter, SortDescription &sorting) override;
964 /*! \brief Will check if the season exists and if that is not the case add it to the database.
965 \param showID The id of the show in question.
966 \param season The season number we want to add.
967 \return The dbId of the season.
969 int AddSeason(int showID, int season, const std::string& name = "");
970 int AddSet(const std::string& strSet, const std::string& strOverview = "");
971 void ClearMovieSet(int idMovie);
972 void SetMovieSet(int idMovie, int idSet);
973 bool SetVideoUserRating(int dbId, int rating, const MediaType& mediaType);
974 bool GetUseAllExternalAudioForVideo(const std::string& videoPath);
976 protected:
977 int AddNewMovie(CVideoInfoTag& details);
978 int AddNewMusicVideo(CVideoInfoTag& details);
980 int GetMovieId(const std::string& strFilenameAndPath);
981 int GetMusicVideoId(const std::string& strFilenameAndPath);
983 /*! \brief Get the id of this fileitem
984 Works for both videodb:// items and normal fileitems
985 \param item CFileItem to grab the fileid of
986 \return id of the file, -1 if it is not in the db.
988 int GetFileId(const CFileItem &item);
989 int GetFileId(const CVideoInfoTag& details);
991 /*! \brief Get the id of the file of this item and store it in the item
992 \param details CVideoInfoTag for which to get and store the id of the file
993 \return id of the file, -1 if it is not in the db.
995 int GetAndFillFileId(CVideoInfoTag& details);
997 /*! \brief Get the id of a file from path
998 \param url full path to the file
999 \return id of the file, -1 if it is not in the db.
1001 int GetFileId(const std::string& url);
1003 int AddToTable(const std::string& table, const std::string& firstField, const std::string& secondField, const std::string& value);
1004 int UpdateRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating);
1005 int AddRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating);
1006 int UpdateUniqueIDs(int mediaId, const char *mediaType, const CVideoInfoTag& details);
1007 int AddUniqueIDs(int mediaId, const char *mediaType, const CVideoInfoTag& details);
1008 int AddActor(const std::string& strActor, const std::string& thumbURL, const std::string &thumb = "");
1010 int AddTvShow();
1012 /*! \brief Adds a path to the tvshow link table.
1013 \param idShow the id of the show.
1014 \param path the path to add.
1015 \param parentPath the parent path of the path to add.
1016 \param dateAdded date/time when the path was added
1017 \return true if successfully added, false otherwise.
1019 bool AddPathToTvShow(int idShow, const std::string &path, const std::string &parentPath, const CDateTime& dateAdded = CDateTime());
1021 /*! \brief Check whether a show is already in the library.
1022 Matches on unique identifier or matching title and premiered date.
1023 \param show the details of the show to check for.
1024 \return the show id if found, else -1.
1026 int GetMatchingTvShow(const CVideoInfoTag &show);
1028 // link functions - these two do all the work
1029 void AddLinkToActor(int mediaId, const char *mediaType, int actorId, const std::string &role, int order);
1030 void AddToLinkTable(int mediaId, const std::string& mediaType, const std::string& table, int valueId, const char *foreignKey = NULL);
1031 void RemoveFromLinkTable(int mediaId, const std::string& mediaType, const std::string& table, int valueId, const char *foreignKey = NULL);
1033 void AddLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1034 void UpdateLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1035 void AddActorLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1036 void UpdateActorLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1038 void AddCast(int mediaId, const char *mediaType, const std::vector<SActorInfo> &cast);
1040 CVideoInfoTag GetDetailsForMovie(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1041 CVideoInfoTag GetDetailsForMovie(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1042 CVideoInfoTag GetDetailsForTvShow(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone, CFileItem* item = NULL);
1043 CVideoInfoTag GetDetailsForTvShow(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone, CFileItem* item = NULL);
1044 CVideoInfoTag GetBasicDetailsForEpisode(std::unique_ptr<dbiplus::Dataset> &pDS);
1045 CVideoInfoTag GetBasicDetailsForEpisode(const dbiplus::sql_record* const record);
1046 CVideoInfoTag GetDetailsForEpisode(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1047 CVideoInfoTag GetDetailsForEpisode(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1048 CVideoInfoTag GetDetailsForMusicVideo(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1049 CVideoInfoTag GetDetailsForMusicVideo(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1050 bool GetPeopleNav(const std::string& strBaseDir,
1051 CFileItemList& items,
1052 const char* type,
1053 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
1054 const Filter& filter = Filter(),
1055 bool countOnly = false);
1056 bool GetNavCommon(const std::string& strBaseDir,
1057 CFileItemList& items,
1058 const char* type,
1059 VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
1060 const Filter& filter = Filter(),
1061 bool countOnly = false);
1062 void GetCast(int media_id, const std::string &media_type, std::vector<SActorInfo> &cast);
1063 void GetTags(int media_id, const std::string &media_type, std::vector<std::string> &tags);
1064 void GetRatings(int media_id, const std::string &media_type, RatingMap &ratings);
1065 void GetUniqueIDs(int media_id, const std::string &media_type, CVideoInfoTag& details);
1067 void GetDetailsFromDB(std::unique_ptr<dbiplus::Dataset> &pDS, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
1068 void GetDetailsFromDB(const dbiplus::sql_record* const record, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
1069 std::string GetValueString(const CVideoInfoTag &details, int min, int max, const SDbTableOffsets *offsets) const;
1071 private:
1072 void CreateTables() override;
1073 void CreateAnalytics() override;
1074 void UpdateTables(int version) override;
1075 void CreateLinkIndex(const char *table);
1076 void CreateForeignLinkIndex(const char *table, const char *foreignkey);
1078 /*! \brief (Re)Create the generic database views for movies, tvshows,
1079 episodes and music videos
1081 virtual void CreateViews();
1083 /*! \brief Helper to get a database id given a query.
1084 Returns an integer, -1 if not found, and greater than 0 if found.
1085 \param query the SQL that will retrieve a database id.
1086 \return -1 if not found, else a valid database id (i.e. > 0)
1088 int GetDbId(const std::string &query);
1090 /*! \brief Run a query on the main dataset and return the number of rows
1091 If no rows are found we close the dataset and return 0.
1092 \param sql the sql query to run
1093 \return the number of rows, -1 for an error.
1095 int RunQuery(const std::string &sql);
1097 void AppendIdLinkFilter(const char* field, const char *table, const MediaType& mediaType, const char *view, const char *viewKey, const CUrlOptions::UrlOptions& options, Filter &filter);
1098 void AppendLinkFilter(const char* field, const char *table, const MediaType& mediaType, const char *view, const char *viewKey, const CUrlOptions::UrlOptions& options, Filter &filter);
1100 /*! \brief Determine whether the path is using lookup using folders
1101 \param path the path to check
1102 \param shows whether this path is from a tvshow (defaults to false)
1104 bool LookupByFolders(const std::string &path, bool shows = false);
1106 /*! \brief Get the playcount for a file id
1107 \param iFileId file id to get the playcount for
1108 \return the playcount of the item, or -1 on error
1109 \sa SetPlayCount, IncrementPlayCount, GetPlayCounts
1111 int GetPlayCount(int iFileId);
1113 /*! \brief Get the last played time of a filename and path
1114 \param iFileId file id to get the playcount for
1115 \return the last played time of the item, or an invalid CDateTime on error
1116 \sa UpdateLastPlayed
1118 CDateTime GetLastPlayed(int iFileId);
1120 bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, bool allDetails, CFileItem* item);
1122 int GetMinSchemaVersion() const override { return 75; }
1123 int GetSchemaVersion() const override;
1124 virtual int GetExportVersion() const { return 1; }
1125 const char* GetBaseDBName() const override { return "MyVideos"; }
1127 void ConstructPath(std::string& strDest, const std::string& strPath, const std::string& strFileName);
1128 void SplitPath(const std::string& strFileNameAndPath, std::string& strPath, std::string& strFileName);
1129 void InvalidatePathHash(const std::string& strPath);
1131 /*! \brief Get a safe filename from a given string
1132 \param dir directory to use for the file
1133 \param name movie, show name, or actor to get a safe filename for
1134 \return safe filename based on this title
1136 std::string GetSafeFile(const std::string &dir, const std::string &name) const;
1138 std::vector<int> CleanMediaType(const std::string &mediaType, const std::string &cleanableFileIDs,
1139 std::map<int, bool> &pathsDeleteDecisions, std::string &deletedFileIDs, bool silent);
1141 static void AnnounceRemove(const std::string& content, int id, bool scanning = false);
1142 static void AnnounceUpdate(const std::string& content, int id);
1144 static CDateTime GetDateAdded(const std::string& filename, CDateTime dateAdded = CDateTime());