xbmc
VideoDatabase.h
1 /*
2  * Copyright (C) 2016-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 "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"
17 
18 #include <memory>
19 #include <set>
20 #include <utility>
21 #include <vector>
22 
23 class CFileItem;
24 class CFileItemList;
25 class CVideoSettings;
26 class CGUIDialogProgress;
28 
29 namespace dbiplus
30 {
31  class field_value;
32  typedef std::vector<field_value> sql_record;
33 }
34 
35 #ifndef my_offsetof
36 #ifndef TARGET_POSIX
37 #define my_offsetof(TYPE, MEMBER) offsetof(TYPE, MEMBER)
38 #else
39 /*
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).
46  */
47 #define my_offsetof(TYPE, MEMBER) \
48  ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
49 #endif
50 #endif
51 
52 typedef std::vector<CVideoInfoTag> VECMOVIES;
53 
54 namespace VIDEO
55 {
56  class IVideoInfoScannerObserver;
57  struct SScanSettings;
58 }
59 
60 enum VideoDbDetails
61 {
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 } ;
72 
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
77 
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
96 
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
118 
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
133 #define VIDEODB_DETAILS_TVSHOW_NUM_INPROGRESS VIDEODB_MAX_COLUMNS + 15
134 
135 #define VIDEODB_DETAILS_MUSICVIDEO_USER_RATING VIDEODB_MAX_COLUMNS + 2
136 #define VIDEODB_DETAILS_MUSICVIDEO_PREMIERED VIDEODB_MAX_COLUMNS + 3
137 #define VIDEODB_DETAILS_MUSICVIDEO_FILE VIDEODB_MAX_COLUMNS + 4
138 #define VIDEODB_DETAILS_MUSICVIDEO_PATH VIDEODB_MAX_COLUMNS + 5
139 #define VIDEODB_DETAILS_MUSICVIDEO_PLAYCOUNT VIDEODB_MAX_COLUMNS + 6
140 #define VIDEODB_DETAILS_MUSICVIDEO_LASTPLAYED VIDEODB_MAX_COLUMNS + 7
141 #define VIDEODB_DETAILS_MUSICVIDEO_DATEADDED VIDEODB_MAX_COLUMNS + 8
142 #define VIDEODB_DETAILS_MUSICVIDEO_RESUME_TIME VIDEODB_MAX_COLUMNS + 9
143 #define VIDEODB_DETAILS_MUSICVIDEO_TOTAL_TIME VIDEODB_MAX_COLUMNS + 10
144 #define VIDEODB_DETAILS_MUSICVIDEO_PLAYER_STATE VIDEODB_MAX_COLUMNS + 11
145 #define VIDEODB_DETAILS_MUSICVIDEO_UNIQUEID_VALUE VIDEODB_MAX_COLUMNS + 12
146 #define VIDEODB_DETAILS_MUSICVIDEO_UNIQUEID_TYPE VIDEODB_MAX_COLUMNS + 13
147 
148 #define VIDEODB_TYPE_UNUSED 0
149 #define VIDEODB_TYPE_STRING 1
150 #define VIDEODB_TYPE_INT 2
151 #define VIDEODB_TYPE_FLOAT 3
152 #define VIDEODB_TYPE_BOOL 4
153 #define VIDEODB_TYPE_COUNT 5
154 #define VIDEODB_TYPE_STRINGARRAY 6
155 #define VIDEODB_TYPE_DATE 7
156 #define VIDEODB_TYPE_DATETIME 8
157 
158 enum class VideoDbContentType
159 {
160  UNKNOWN = -1,
161  MOVIES = 1,
162  TVSHOWS = 2,
163  MUSICVIDEOS = 3,
164  EPISODES = 4,
165  MOVIE_SETS = 5,
166  MUSICALBUMS = 6
167 };
168 
169 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 {
171  VIDEODB_ID_MIN = -1,
172  VIDEODB_ID_TITLE = 0,
173  VIDEODB_ID_PLOT = 1,
174  VIDEODB_ID_PLOTOUTLINE = 2,
175  VIDEODB_ID_TAGLINE = 3,
176  VIDEODB_ID_VOTES = 4, // unused
177  VIDEODB_ID_RATING_ID = 5,
178  VIDEODB_ID_CREDITS = 6,
179  VIDEODB_ID_YEAR = 7, // unused
180  VIDEODB_ID_THUMBURL = 8,
181  VIDEODB_ID_IDENT_ID = 9,
182  VIDEODB_ID_SORTTITLE = 10,
183  VIDEODB_ID_RUNTIME = 11,
184  VIDEODB_ID_MPAA = 12,
185  VIDEODB_ID_TOP250 = 13,
186  VIDEODB_ID_GENRE = 14,
187  VIDEODB_ID_DIRECTOR = 15,
188  VIDEODB_ID_ORIGINALTITLE = 16,
189  VIDEODB_ID_THUMBURL_SPOOF = 17,
190  VIDEODB_ID_STUDIOS = 18,
191  VIDEODB_ID_TRAILER = 19,
192  VIDEODB_ID_FANART = 20,
193  VIDEODB_ID_COUNTRY = 21,
194  VIDEODB_ID_BASEPATH = 22,
195  VIDEODB_ID_PARENTPATHID = 23,
196  VIDEODB_ID_MAX
197 } VIDEODB_IDS;
198 
199 const struct SDbTableOffsets
200 {
201  int type;
202  size_t offset;
203 } DbMovieOffsets[] =
204 {
205  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTitle) },
206  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
207  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlotOutline) },
208  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTagLine) },
209  { VIDEODB_TYPE_UNUSED, 0 }, // unused
210  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdRating) },
211  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_writingCredits) },
212  { VIDEODB_TYPE_UNUSED, 0 }, // unused
213  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
214  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID) },
215  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strSortTitle) },
216  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_duration) },
217  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strMPAARating) },
218  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iTop250) },
219  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_genre) },
220  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_director) },
221  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strOriginalTitle) },
222  { VIDEODB_TYPE_UNUSED, 0 }, // unused
223  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_studio) },
224  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTrailer) },
225  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_fanart.m_xml) },
226  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_country) },
227  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_basePath) },
228  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_parentPathID) }
229 };
230 
231 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 {
233  VIDEODB_ID_TV_MIN = -1,
234  VIDEODB_ID_TV_TITLE = 0,
235  VIDEODB_ID_TV_PLOT = 1,
236  VIDEODB_ID_TV_STATUS = 2,
237  VIDEODB_ID_TV_VOTES = 3, // unused
238  VIDEODB_ID_TV_RATING_ID = 4,
239  VIDEODB_ID_TV_PREMIERED = 5,
240  VIDEODB_ID_TV_THUMBURL = 6,
241  VIDEODB_ID_TV_THUMBURL_SPOOF = 7,
242  VIDEODB_ID_TV_GENRE = 8,
243  VIDEODB_ID_TV_ORIGINALTITLE = 9,
244  VIDEODB_ID_TV_EPISODEGUIDE = 10,
245  VIDEODB_ID_TV_FANART = 11,
246  VIDEODB_ID_TV_IDENT_ID = 12,
247  VIDEODB_ID_TV_MPAA = 13,
248  VIDEODB_ID_TV_STUDIOS = 14,
249  VIDEODB_ID_TV_SORTTITLE = 15,
250  VIDEODB_ID_TV_TRAILER = 16,
251  VIDEODB_ID_TV_MAX
252 } VIDEODB_TV_IDS;
253 
254 const struct SDbTableOffsets DbTvShowOffsets[] =
255 {
256  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTitle) },
257  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
258  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strStatus) },
259  { VIDEODB_TYPE_UNUSED, 0 }, //unused
260  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdRating) },
261  { VIDEODB_TYPE_DATE, my_offsetof(CVideoInfoTag,m_premiered) },
262  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
263  { VIDEODB_TYPE_UNUSED, 0 }, // unused
264  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_genre) },
265  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strOriginalTitle)},
266  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strEpisodeGuide)},
267  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_fanart.m_xml)},
268  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID)},
269  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strMPAARating)},
270  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_studio)},
271  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strSortTitle)},
272  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTrailer)}
273 };
274 
276 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 {
278  VIDEODB_ID_SEASON_MIN = -1,
279  VIDEODB_ID_SEASON_ID = 0,
280  VIDEODB_ID_SEASON_TVSHOW_ID = 1,
281  VIDEODB_ID_SEASON_NUMBER = 2,
282  VIDEODB_ID_SEASON_NAME = 3,
283  VIDEODB_ID_SEASON_USER_RATING = 4,
284  VIDEODB_ID_SEASON_TVSHOW_PATH = 5,
285  VIDEODB_ID_SEASON_TVSHOW_TITLE = 6,
286  VIDEODB_ID_SEASON_TVSHOW_PLOT = 7,
287  VIDEODB_ID_SEASON_TVSHOW_PREMIERED = 8,
288  VIDEODB_ID_SEASON_TVSHOW_GENRE = 9,
289  VIDEODB_ID_SEASON_TVSHOW_STUDIO = 10,
290  VIDEODB_ID_SEASON_TVSHOW_MPAA = 11,
291  VIDEODB_ID_SEASON_EPISODES_TOTAL = 12,
292  VIDEODB_ID_SEASON_EPISODES_WATCHED = 13,
293  VIDEODB_ID_SEASON_PREMIERED = 14,
294  VIDEODB_ID_SEASON_EPISODES_INPROGRESS = 15,
295  VIDEODB_ID_SEASON_MAX
296 } VIDEODB_SEASON_IDS;
297 
298 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
299 {
300  VIDEODB_ID_EPISODE_MIN = -1,
301  VIDEODB_ID_EPISODE_TITLE = 0,
302  VIDEODB_ID_EPISODE_PLOT = 1,
303  VIDEODB_ID_EPISODE_VOTES = 2, // unused
304  VIDEODB_ID_EPISODE_RATING_ID = 3,
305  VIDEODB_ID_EPISODE_CREDITS = 4,
306  VIDEODB_ID_EPISODE_AIRED = 5,
307  VIDEODB_ID_EPISODE_THUMBURL = 6,
308  VIDEODB_ID_EPISODE_THUMBURL_SPOOF = 7,
309  VIDEODB_ID_EPISODE_PLAYCOUNT = 8, // unused - feel free to repurpose
310  VIDEODB_ID_EPISODE_RUNTIME = 9,
311  VIDEODB_ID_EPISODE_DIRECTOR = 10,
312  VIDEODB_ID_EPISODE_PRODUCTIONCODE = 11,
313  VIDEODB_ID_EPISODE_SEASON = 12,
314  VIDEODB_ID_EPISODE_EPISODE = 13,
315  VIDEODB_ID_EPISODE_ORIGINALTITLE = 14,
316  VIDEODB_ID_EPISODE_SORTSEASON = 15,
317  VIDEODB_ID_EPISODE_SORTEPISODE = 16,
318  VIDEODB_ID_EPISODE_BOOKMARK = 17,
319  VIDEODB_ID_EPISODE_BASEPATH = 18,
320  VIDEODB_ID_EPISODE_PARENTPATHID = 19,
321  VIDEODB_ID_EPISODE_IDENT_ID = 20,
322  VIDEODB_ID_EPISODE_MAX
323 } VIDEODB_EPISODE_IDS;
324 
325 const struct SDbTableOffsets DbEpisodeOffsets[] =
326 {
327  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strTitle) },
328  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
329  { VIDEODB_TYPE_UNUSED, 0 }, // unused
330  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdRating) },
331  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_writingCredits) },
332  { VIDEODB_TYPE_DATE, my_offsetof(CVideoInfoTag,m_firstAired) },
333  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
334  { VIDEODB_TYPE_UNUSED, 0 }, // unused
335  { VIDEODB_TYPE_UNUSED, 0 }, // unused
336  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_duration) },
337  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_director) },
338  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strProductionCode) },
339  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iSeason) },
340  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iEpisode) },
341  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strOriginalTitle)},
342  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iSpecialSortSeason) },
343  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iSpecialSortEpisode) },
344  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iBookmarkId) },
345  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_basePath) },
346  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_parentPathID) },
347  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID) }
348 };
349 
350 typedef enum // this enum MUST match the offset struct further down!! and make sure to keep min and max at -1 and sizeof(offsets)
351 {
352  VIDEODB_ID_MUSICVIDEO_MIN = -1,
353  VIDEODB_ID_MUSICVIDEO_TITLE = 0,
354  VIDEODB_ID_MUSICVIDEO_THUMBURL = 1,
355  VIDEODB_ID_MUSICVIDEO_THUMBURL_SPOOF = 2,
356  VIDEODB_ID_MUSICVIDEO_PLAYCOUNT = 3, // unused - feel free to repurpose
357  VIDEODB_ID_MUSICVIDEO_RUNTIME = 4,
358  VIDEODB_ID_MUSICVIDEO_DIRECTOR = 5,
359  VIDEODB_ID_MUSICVIDEO_STUDIOS = 6,
360  VIDEODB_ID_MUSICVIDEO_YEAR = 7, // unused
361  VIDEODB_ID_MUSICVIDEO_PLOT = 8,
362  VIDEODB_ID_MUSICVIDEO_ALBUM = 9,
363  VIDEODB_ID_MUSICVIDEO_ARTIST = 10,
364  VIDEODB_ID_MUSICVIDEO_GENRE = 11,
365  VIDEODB_ID_MUSICVIDEO_TRACK = 12,
366  VIDEODB_ID_MUSICVIDEO_BASEPATH = 13,
367  VIDEODB_ID_MUSICVIDEO_PARENTPATHID = 14,
368  VIDEODB_ID_MUSICVIDEO_IDENT_ID = 15,
369  VIDEODB_ID_MUSICVIDEO_MAX
370 } VIDEODB_MUSICVIDEO_IDS;
371 
372 const struct SDbTableOffsets DbMusicVideoOffsets[] =
373 {
374  { VIDEODB_TYPE_STRING, my_offsetof(class CVideoInfoTag,m_strTitle) },
375  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPictureURL.m_data) },
376  { VIDEODB_TYPE_UNUSED, 0 }, // unused
377  { VIDEODB_TYPE_UNUSED, 0 }, // unused
378  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_duration) },
379  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_director) },
380  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_studio) },
381  { VIDEODB_TYPE_UNUSED, 0 }, // unused
382  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strPlot) },
383  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_strAlbum) },
384  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_artist) },
385  { VIDEODB_TYPE_STRINGARRAY, my_offsetof(CVideoInfoTag,m_genre) },
386  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iTrack) },
387  { VIDEODB_TYPE_STRING, my_offsetof(CVideoInfoTag,m_basePath) },
388  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_parentPathID) },
389  { VIDEODB_TYPE_INT, my_offsetof(CVideoInfoTag,m_iIdUniqueID)}
390 };
391 
392 #define COMPARE_PERCENTAGE 0.90f // 90%
393 #define COMPARE_PERCENTAGE_MIN 0.50f // 50%
394 
395 class CVideoDatabase : public CDatabase
396 {
397 public:
398 
399  class CActor // used for actor retrieval for non-master users
400  {
401  public:
402  std::string name;
403  std::string thumb;
404  int playcount;
405  int appearances;
406  };
407 
408  class CSeason // used for season retrieval for non-master users
409  {
410  public:
411  std::string path;
412  std::vector<std::string> genre;
413  int numEpisodes;
414  int numWatched;
415  int id;
416  };
417 
418  class CSetInfo
419  {
420  public:
421  std::string name;
422  VECMOVIES movies;
423  DatabaseResults results;
424  };
425 
426  CVideoDatabase(void);
427  ~CVideoDatabase(void) override;
428 
429  bool Open() override;
430  bool CommitTransaction() override;
431 
432  int AddNewEpisode(int idShow, CVideoInfoTag& details);
433 
434  // editing functions
444  CDateTime SetPlayCount(const CFileItem& item, int count, const CDateTime& date = CDateTime());
445 
452  CDateTime IncrementPlayCount(const CFileItem& item);
453 
459  int GetPlayCount(const CFileItem &item);
460 
466  int GetPlayCount(const std::string& strFilenameAndPath);
467 
473  CDateTime GetLastPlayed(const std::string& strFilenameAndPath);
474 
481  CDateTime UpdateLastPlayed(const CFileItem& item);
482 
489  bool GetPlayCounts(const std::string &path, CFileItemList &items);
490 
491  void UpdateMovieTitle(int idMovie,
492  const std::string& strNewMovieTitle,
493  VideoDbContentType iType = VideoDbContentType::MOVIES);
494  bool UpdateVideoSortTitle(int idDb,
495  const std::string& strNewSortTitle,
496  VideoDbContentType iType = VideoDbContentType::MOVIES);
497 
498  bool HasMovieInfo(const std::string& strFilenameAndPath);
499  bool HasTvShowInfo(const std::string& strFilenameAndPath);
500  bool HasEpisodeInfo(const std::string& strFilenameAndPath);
501  bool HasMusicVideoInfo(const std::string& strFilenameAndPath);
502 
503  void GetFilePathById(int idMovie, std::string& filePath, VideoDbContentType iType);
504  std::string GetGenreById(int id);
505  std::string GetCountryById(int id);
506  std::string GetSetById(int id);
507  std::string GetTagById(int id);
508  std::string GetPersonById(int id);
509  std::string GetStudioById(int id);
510  std::string GetTvShowTitleById(int id);
511  std::string GetMusicVideoAlbumById(int id);
512  int GetTvShowForEpisode(int idEpisode);
513  int GetSeasonForEpisode(int idEpisode);
514 
515  bool LoadVideoInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int getDetails = VideoDbDetailsAll);
516  bool GetMovieInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idMovie = -1, int getDetails = VideoDbDetailsAll);
517  bool GetTvShowInfo(const std::string& strPath, CVideoInfoTag& details, int idTvShow = -1, CFileItem* item = NULL, int getDetails = VideoDbDetailsAll);
518  bool GetSeasonInfo(const std::string& path, int season, CVideoInfoTag& details, CFileItem* item);
519  bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, CFileItem* item);
520  bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, bool allDetails = true);
521  bool GetEpisodeBasicInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1);
522  bool GetEpisodeInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1, int getDetails = VideoDbDetailsAll);
523  bool GetMusicVideoInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idMVideo = -1, int getDetails = VideoDbDetailsAll);
524  bool GetSetInfo(int idSet, CVideoInfoTag& details, CFileItem* item = nullptr);
525  bool GetFileInfo(const std::string& strFilenameAndPath, CVideoInfoTag& details, int idFile = -1);
526 
527  int GetPathId(const std::string& strPath);
528  int GetTvShowId(const std::string& strPath);
529  int GetEpisodeId(const std::string& strFilenameAndPath, int idEpisode=-1, int idSeason=-1); // idEpisode, idSeason are used for multipart episodes as hints
530  int GetSeasonId(int idShow, int season);
531 
532  void GetEpisodesByFile(const std::string& strFilenameAndPath, std::vector<CVideoInfoTag>& episodes);
533 
534  int SetDetailsForItem(CVideoInfoTag& details, const std::map<std::string, std::string> &artwork);
535  int SetDetailsForItem(int id, const MediaType& mediaType, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork);
536 
537  int SetDetailsForMovie(CVideoInfoTag& details,
538  const std::map<std::string, std::string>& artwork,
539  int idMovie = -1);
540  int SetDetailsForMovieSet(const CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, int idSet = -1);
541 
552  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);
553  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);
554  int SetDetailsForSeason(const CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, int idShow, int idSeason = -1);
555  int SetDetailsForEpisode(CVideoInfoTag& details,
556  const std::map<std::string, std::string>& artwork,
557  int idShow,
558  int idEpisode = -1);
559  int SetDetailsForMusicVideo(CVideoInfoTag& details,
560  const std::map<std::string, std::string>& artwork,
561  int idMVideo = -1);
562  void SetStreamDetailsForFile(const CStreamDetails& details, const std::string &strFileNameAndPath);
563  void SetStreamDetailsForFileId(const CStreamDetails& details, int idFile);
564 
565  bool SetSingleValue(VideoDbContentType type, int dbId, int dbField, const std::string& strValue);
566  bool SetSingleValue(VideoDbContentType type,
567  int dbId,
568  Field dbField,
569  const std::string& strValue);
570  bool SetSingleValue(const std::string &table, const std::string &fieldName, const std::string &strValue,
571  const std::string &conditionName = "", int conditionValue = -1);
572 
573  int UpdateDetailsForMovie(int idMovie, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, const std::set<std::string> &updatedDetails);
574 
575  void DeleteMovie(int idMovie, bool bKeepId = false);
576  void DeleteTvShow(int idTvShow, bool bKeepId = false);
577  void DeleteTvShow(const std::string& strPath);
578  void DeleteSeason(int idSeason, bool bKeepId = false);
579  void DeleteEpisode(int idEpisode, bool bKeepId = false);
580  void DeleteMusicVideo(int idMusicVideo, bool bKeepId = false);
581  void DeleteDetailsForTvShow(int idTvShow);
582  void DeleteStreamDetails(int idFile);
583  void RemoveContentForPath(const std::string& strPath,CGUIDialogProgress *progress = NULL);
584  void UpdateFanart(const CFileItem& item, VideoDbContentType type);
585  void DeleteSet(int idSet);
586  void DeleteTag(int idTag, VideoDbContentType mediaType);
587 
593  bool GetVideoSettings(int idFile, CVideoSettings &settings);
594 
600  bool GetVideoSettings(const CFileItem &item, CVideoSettings &settings);
601 
607  bool GetVideoSettings(const std::string &filePath, CVideoSettings &settings);
608 
613  void SetVideoSettings(const CFileItem &item, const CVideoSettings &settings);
614 
619  void SetVideoSettings(int idFile, const CVideoSettings &settings);
620 
625  void EraseVideoSettings(const CFileItem &item);
626 
630  void EraseAllVideoSettings();
631 
636  void EraseAllVideoSettings(const std::string& path);
637 
642  void EraseAllForPath(const std::string& path);
643 
644  bool GetStackTimes(const std::string &filePath, std::vector<uint64_t> &times);
645  void SetStackTimes(const std::string &filePath, const std::vector<uint64_t> &times);
646 
647  void GetBookMarksForFile(const std::string& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type = CBookmark::STANDARD, bool bAppend=false, long partNumber=0);
648  void AddBookMarkToFile(const std::string& strFilenameAndPath, const CBookmark &bookmark, CBookmark::EType type = CBookmark::STANDARD);
649  bool GetResumeBookMark(const std::string& strFilenameAndPath, CBookmark &bookmark);
650  void DeleteResumeBookMark(const CFileItem& item);
651  void ClearBookMarkOfFile(const std::string& strFilenameAndPath, CBookmark& bookmark, CBookmark::EType type = CBookmark::STANDARD);
652  void ClearBookMarksOfFile(const std::string& strFilenameAndPath, CBookmark::EType type = CBookmark::STANDARD);
653  void ClearBookMarksOfFile(int idFile, CBookmark::EType type = CBookmark::STANDARD);
654  bool GetBookMarkForEpisode(const CVideoInfoTag& tag, CBookmark& bookmark);
655  void AddBookMarkForEpisode(const CVideoInfoTag& tag, const CBookmark& bookmark);
656  void DeleteBookMarkForEpisode(const CVideoInfoTag& tag);
657  bool GetResumePoint(CVideoInfoTag& tag);
658  bool GetStreamDetails(CFileItem& item);
659  bool GetStreamDetails(CVideoInfoTag& tag) const;
660  bool GetDetailsByTypeAndId(CFileItem& item, VideoDbContentType type, int id);
661  CVideoInfoTag GetDetailsByTypeAndId(VideoDbContentType type, int id);
662 
663  // scraper settings
664  void SetScraperForPath(const std::string& filePath, const ADDON::ScraperPtr& info, const VIDEO::SScanSettings& settings);
665  ADDON::ScraperPtr GetScraperForPath(const std::string& strPath);
666  ADDON::ScraperPtr GetScraperForPath(const std::string& strPath, VIDEO::SScanSettings& settings);
667 
676  ADDON::ScraperPtr GetScraperForPath(const std::string& strPath, VIDEO::SScanSettings& settings, bool& foundDirectly);
677 
686  std::string GetContentForPath(const std::string& strPath);
687 
694  bool GetItemsForPath(const std::string &content, const std::string &path, CFileItemList &items);
695 
700  bool ScraperInUse(const std::string &scraperID) const;
701 
702  // scanning hashes and paths scanned
703  bool SetPathHash(const std::string &path, const std::string &hash);
704  bool GetPathHash(const std::string &path, std::string &hash);
705  bool GetPaths(std::set<std::string> &paths);
706  bool GetPathsForTvShow(int idShow, std::set<int>& paths);
707 
713  bool GetPathsLinkedToTvShow(int idShow, std::vector<std::string> &paths);
714 
720  bool GetSubPaths(const std::string& basepath, std::vector< std::pair<int, std::string> >& subpaths);
721 
722  bool GetSourcePath(const std::string &path, std::string &sourcePath);
723  bool GetSourcePath(const std::string &path, std::string &sourcePath, VIDEO::SScanSettings& settings);
724 
725  // for music + musicvideo linkups - if no album and title given it will return the artist id, else the id of the matching video
726  int GetMatchingMusicVideo(const std::string& strArtist, const std::string& strAlbum = "", const std::string& strTitle = "");
727 
728  // searching functions
729  void GetMoviesByActor(const std::string& strActor, CFileItemList& items);
730  void GetTvShowsByActor(const std::string& strActor, CFileItemList& items);
731  void GetEpisodesByActor(const std::string& strActor, CFileItemList& items);
732 
733  void GetMusicVideosByArtist(const std::string& strArtist, CFileItemList& items);
734  void GetMusicVideosByAlbum(const std::string& strAlbum, CFileItemList& items);
735 
736  void GetMovieGenresByName(const std::string& strSearch, CFileItemList& items);
737  void GetTvShowGenresByName(const std::string& strSearch, CFileItemList& items);
738  void GetMusicVideoGenresByName(const std::string& strSearch, CFileItemList& items);
739 
740  void GetMovieCountriesByName(const std::string& strSearch, CFileItemList& items);
741 
742  void GetMusicVideoAlbumsByName(const std::string& strSearch, CFileItemList& items);
743 
744  void GetMovieActorsByName(const std::string& strSearch, CFileItemList& items);
745  void GetTvShowsActorsByName(const std::string& strSearch, CFileItemList& items);
746  void GetMusicVideoArtistsByName(const std::string& strSearch, CFileItemList& items);
747 
748  void GetMovieDirectorsByName(const std::string& strSearch, CFileItemList& items);
749  void GetTvShowsDirectorsByName(const std::string& strSearch, CFileItemList& items);
750  void GetMusicVideoDirectorsByName(const std::string& strSearch, CFileItemList& items);
751 
752  void GetMoviesByName(const std::string& strSearch, CFileItemList& items);
753  void GetTvShowsByName(const std::string& strSearch, CFileItemList& items);
754  void GetEpisodesByName(const std::string& strSearch, CFileItemList& items);
755  void GetMusicVideosByName(const std::string& strSearch, CFileItemList& items);
756 
757  void GetEpisodesByPlot(const std::string& strSearch, CFileItemList& items);
758  void GetMoviesByPlot(const std::string& strSearch, CFileItemList& items);
759 
760  bool LinkMovieToTvshow(int idMovie, int idShow, bool bRemove);
761  bool IsLinkedToTvshow(int idMovie);
762  bool GetLinksToTvShow(int idMovie, std::vector<int>& ids);
763 
764  // general browsing
765  bool GetGenresNav(const std::string& strBaseDir,
766  CFileItemList& items,
767  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
768  const Filter& filter = Filter(),
769  bool countOnly = false);
770  bool GetCountriesNav(const std::string& strBaseDir,
771  CFileItemList& items,
772  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
773  const Filter& filter = Filter(),
774  bool countOnly = false);
775  bool GetStudiosNav(const std::string& strBaseDir,
776  CFileItemList& items,
777  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
778  const Filter& filter = Filter(),
779  bool countOnly = false);
780  bool GetYearsNav(const std::string& strBaseDir,
781  CFileItemList& items,
782  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
783  const Filter& filter = Filter());
784  bool GetActorsNav(const std::string& strBaseDir,
785  CFileItemList& items,
786  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
787  const Filter& filter = Filter(),
788  bool countOnly = false);
789  bool GetDirectorsNav(const std::string& strBaseDir,
790  CFileItemList& items,
791  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
792  const Filter& filter = Filter(),
793  bool countOnly = false);
794  bool GetWritersNav(const std::string& strBaseDir,
795  CFileItemList& items,
796  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
797  const Filter& filter = Filter(),
798  bool countOnly = false);
799  bool GetSetsNav(const std::string& strBaseDir,
800  CFileItemList& items,
801  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
802  const Filter& filter = Filter(),
803  bool ignoreSingleMovieSets = false);
804  bool GetTagsNav(const std::string& strBaseDir,
805  CFileItemList& items,
806  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
807  const Filter& filter = Filter(),
808  bool countOnly = false);
809  bool GetMusicVideoAlbumsNav(const std::string& strBaseDir, CFileItemList& items, int idArtist, const Filter &filter = Filter(), bool countOnly = false);
810 
811  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);
812  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);
813  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);
814  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);
815  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);
816 
817  bool GetRecentlyAddedMoviesNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
818  bool GetRecentlyAddedEpisodesNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
819  bool GetRecentlyAddedMusicVideosNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
820  bool GetInProgressTvShowsNav(const std::string& strBaseDir, CFileItemList& items, unsigned int limit=0, int getDetails = VideoDbDetailsNone);
821 
822  bool HasContent();
823  bool HasContent(VideoDbContentType type);
824  bool HasSets() const;
825 
826  void CleanDatabase(CGUIDialogProgressBarHandle* handle = NULL, const std::set<int>& paths = std::set<int>(), bool showProgress = true);
827 
837  int AddFile(const std::string& url,
838  const std::string& parentPath = "",
839  const CDateTime& dateAdded = CDateTime(),
840  int playcount = 0,
841  const CDateTime& lastPlayed = CDateTime());
842 
848  int AddFile(const CFileItem& item);
849 
856  int AddFile(const CVideoInfoTag& details, const std::string& parentPath = "");
857 
865  int AddPath(const std::string& strPath, const std::string &parentPath = "", const CDateTime& dateAdded = CDateTime());
866 
871  void UpdateFileDateAdded(CVideoInfoTag& details);
872 
873  void ExportToXML(const std::string &path, bool singleFile = true, bool images=false, bool actorThumbs=false, bool overwrite=false);
874  void ExportActorThumbs(const std::string &path, const CVideoInfoTag& tag, bool singleFiles, bool overwrite=false);
875  void ImportFromXML(const std::string &path);
876  void DumpToDummyFiles(const std::string &path);
877  bool ImportArtFromXML(const TiXmlNode *node, std::map<std::string, std::string> &artwork);
878 
879  // smart playlists and main retrieval work in these functions
880  bool GetMoviesByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
881  bool GetSetsByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, bool ignoreSingleMovieSets = false);
882  bool GetTvShowsByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
883  bool GetSeasonsByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, bool appendFullShowPath = true, const SortDescription &sortDescription = SortDescription());
884  bool GetEpisodesByWhere(const std::string& strBaseDir, const Filter &filter, CFileItemList& items, bool appendFullShowPath = true, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
885  bool GetMusicVideosByWhere(const std::string &baseDir, const Filter &filter, CFileItemList& items, bool checkLocks = true, const SortDescription &sortDescription = SortDescription(), int getDetails = VideoDbDetailsNone);
886 
887  // retrieve sorted and limited items
888  bool GetSortedVideos(const MediaType &mediaType, const std::string& strBaseDir, const SortDescription &sortDescription, CFileItemList& items, const Filter &filter = Filter());
889 
890  // retrieve a list of items
891  bool GetItems(const std::string &strBaseDir, CFileItemList &items, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription());
892  bool GetItems(const std::string &strBaseDir, const std::string &mediaType, const std::string &itemType, CFileItemList &items, const Filter &filter = Filter(), const SortDescription &sortDescription = SortDescription());
893  bool GetItems(const std::string& strBaseDir,
894  VideoDbContentType mediaType,
895  const std::string& itemType,
896  CFileItemList& items,
897  const Filter& filter = Filter(),
898  const SortDescription& sortDescription = SortDescription());
899  std::string GetItemById(const std::string &itemType, int id);
900 
901  // partymode
907  unsigned int GetRandomMusicVideoIDs(const std::string& strWhere, std::vector<std::pair<int, int> > &songIDs);
908 
909  static void VideoContentTypeToString(VideoDbContentType type, std::string& out)
910  {
911  switch (type)
912  {
913  case VideoDbContentType::MOVIES:
914  out = MediaTypeMovie;
915  break;
916  case VideoDbContentType::TVSHOWS:
917  out = MediaTypeTvShow;
918  break;
919  case VideoDbContentType::EPISODES:
920  out = MediaTypeEpisode;
921  break;
922  case VideoDbContentType::MUSICVIDEOS:
923  out = MediaTypeMusicVideo;
924  break;
925  default:
926  break;
927  }
928  }
929 
930  void SetArtForItem(int mediaId, const MediaType &mediaType, const std::string &artType, const std::string &url);
931  void SetArtForItem(int mediaId, const MediaType &mediaType, const std::map<std::string, std::string> &art);
932  bool GetArtForItem(int mediaId, const MediaType &mediaType, std::map<std::string, std::string> &art);
933  std::string GetArtForItem(int mediaId, const MediaType &mediaType, const std::string &artType);
934  bool HasArtForItem(int mediaId, const MediaType &mediaType);
935  bool RemoveArtForItem(int mediaId, const MediaType &mediaType, const std::string &artType);
936  bool RemoveArtForItem(int mediaId, const MediaType &mediaType, const std::set<std::string> &artTypes);
937  bool GetTvShowSeasons(int showId, std::map<int, int> &seasons);
938  bool GetTvShowNamedSeasons(int showId, std::map<int, std::string> &seasons);
939 
946  std::string GetTvShowNamedSeasonById(int tvshowId, int seasonId);
947 
948  bool GetTvShowSeasonArt(int mediaId, std::map<int, std::map<std::string, std::string> > &seasonArt);
949  bool GetArtTypes(const MediaType &mediaType, std::vector<std::string> &artTypes);
950 
957  std::vector<std::string> GetAvailableArtTypesForItem(int mediaId, const MediaType& mediaType);
958 
966  std::vector<CScraperUrl::SUrlEntry> GetAvailableArtForItem(
967  int mediaId, const MediaType& mediaType, const std::string& artType);
968 
969  int AddTag(const std::string &tag);
970  void AddTagToItem(int idItem, int idTag, const std::string &type);
971  void RemoveTagFromItem(int idItem, int idTag, const std::string &type);
972  void RemoveTagsFromItem(int idItem, const std::string &type);
973 
974  bool GetFilter(CDbUrl &videoUrl, Filter &filter, SortDescription &sorting) override;
975 
981  int AddSeason(int showID, int season, const std::string& name = "");
982  int AddSet(const std::string& strSet, const std::string& strOverview = "");
983  void ClearMovieSet(int idMovie);
984  void SetMovieSet(int idMovie, int idSet);
985  bool SetVideoUserRating(int dbId, int rating, const MediaType& mediaType);
986  bool GetUseAllExternalAudioForVideo(const std::string& videoPath);
987 
988 protected:
989  int AddNewMovie(CVideoInfoTag& details);
990  int AddNewMusicVideo(CVideoInfoTag& details);
991 
992  int GetMovieId(const std::string& strFilenameAndPath);
993  int GetMusicVideoId(const std::string& strFilenameAndPath);
994 
1000  int GetFileId(const CFileItem &item);
1001  int GetFileId(const CVideoInfoTag& details);
1002 
1007  int GetAndFillFileId(CVideoInfoTag& details);
1008 
1013  int GetFileId(const std::string& url);
1014 
1015  int AddToTable(const std::string& table, const std::string& firstField, const std::string& secondField, const std::string& value);
1016  int UpdateRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating);
1017  int AddRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating);
1018  int UpdateUniqueIDs(int mediaId, const char *mediaType, const CVideoInfoTag& details);
1019  int AddUniqueIDs(int mediaId, const char *mediaType, const CVideoInfoTag& details);
1020  int AddActor(const std::string& strActor, const std::string& thumbURL, const std::string &thumb = "");
1021 
1022  int AddTvShow();
1023 
1031  bool AddPathToTvShow(int idShow, const std::string &path, const std::string &parentPath, const CDateTime& dateAdded = CDateTime());
1032 
1038  int GetMatchingTvShow(const CVideoInfoTag &show);
1039 
1040  // link functions - these two do all the work
1041  void AddLinkToActor(int mediaId, const char *mediaType, int actorId, const std::string &role, int order);
1042  void AddToLinkTable(int mediaId, const std::string& mediaType, const std::string& table, int valueId, const char *foreignKey = NULL);
1043  void RemoveFromLinkTable(int mediaId, const std::string& mediaType, const std::string& table, int valueId, const char *foreignKey = NULL);
1044 
1045  void AddLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1046  void UpdateLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1047  void AddActorLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1048  void UpdateActorLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1049 
1050  void AddCast(int mediaId, const char *mediaType, const std::vector<SActorInfo> &cast);
1051 
1052  CVideoInfoTag GetDetailsForMovie(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1053  CVideoInfoTag GetDetailsForMovie(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1054  CVideoInfoTag GetDetailsForTvShow(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone, CFileItem* item = NULL);
1055  CVideoInfoTag GetDetailsForTvShow(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone, CFileItem* item = NULL);
1056  CVideoInfoTag GetBasicDetailsForEpisode(std::unique_ptr<dbiplus::Dataset> &pDS);
1057  CVideoInfoTag GetBasicDetailsForEpisode(const dbiplus::sql_record* const record);
1058  CVideoInfoTag GetDetailsForEpisode(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1059  CVideoInfoTag GetDetailsForEpisode(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1060  CVideoInfoTag GetDetailsForMusicVideo(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1061  CVideoInfoTag GetDetailsForMusicVideo(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1062  bool GetPeopleNav(const std::string& strBaseDir,
1063  CFileItemList& items,
1064  const char* type,
1065  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
1066  const Filter& filter = Filter(),
1067  bool countOnly = false);
1068  bool GetNavCommon(const std::string& strBaseDir,
1069  CFileItemList& items,
1070  const char* type,
1071  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
1072  const Filter& filter = Filter(),
1073  bool countOnly = false);
1074  void GetCast(int media_id, const std::string &media_type, std::vector<SActorInfo> &cast);
1075  void GetTags(int media_id, const std::string &media_type, std::vector<std::string> &tags);
1076  void GetRatings(int media_id, const std::string &media_type, RatingMap &ratings);
1077  void GetUniqueIDs(int media_id, const std::string &media_type, CVideoInfoTag& details);
1078 
1079  void GetDetailsFromDB(std::unique_ptr<dbiplus::Dataset> &pDS, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
1080  void GetDetailsFromDB(const dbiplus::sql_record* const record, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
1081  std::string GetValueString(const CVideoInfoTag &details, int min, int max, const SDbTableOffsets *offsets) const;
1082 
1083 private:
1084  void CreateTables() override;
1085  void CreateAnalytics() override;
1086  void UpdateTables(int version) override;
1087  void CreateLinkIndex(const char *table);
1088  void CreateForeignLinkIndex(const char *table, const char *foreignkey);
1089 
1093  virtual void CreateViews();
1094 
1100  int GetDbId(const std::string &query);
1101 
1107  int RunQuery(const std::string &sql);
1108 
1109  void AppendIdLinkFilter(const char* field, const char *table, const MediaType& mediaType, const char *view, const char *viewKey, const CUrlOptions::UrlOptions& options, Filter &filter);
1110  void AppendLinkFilter(const char* field, const char *table, const MediaType& mediaType, const char *view, const char *viewKey, const CUrlOptions::UrlOptions& options, Filter &filter);
1111 
1116  bool LookupByFolders(const std::string &path, bool shows = false);
1117 
1123  int GetPlayCount(int iFileId);
1124 
1130  CDateTime GetLastPlayed(int iFileId);
1131 
1132  bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, bool allDetails, CFileItem* item);
1133 
1134  int GetMinSchemaVersion() const override { return 75; }
1135  int GetSchemaVersion() const override;
1136  virtual int GetExportVersion() const { return 1; }
1137  const char* GetBaseDBName() const override { return "MyVideos"; }
1138 
1139  void ConstructPath(std::string& strDest, const std::string& strPath, const std::string& strFileName);
1140  void SplitPath(const std::string& strFileNameAndPath, std::string& strPath, std::string& strFileName);
1141  void InvalidatePathHash(const std::string& strPath);
1142 
1148  std::string GetSafeFile(const std::string &dir, const std::string &name) const;
1149 
1150  std::vector<int> CleanMediaType(const std::string &mediaType, const std::string &cleanableFileIDs,
1151  std::map<int, bool> &pathsDeleteDecisions, std::string &deletedFileIDs, bool silent);
1152 
1153  static void AnnounceRemove(const std::string& content, int id, bool scanning = false);
1154  static void AnnounceUpdate(const std::string& content, int id);
1155 
1156  static CDateTime GetDateAdded(const std::string& filename, CDateTime dateAdded = CDateTime());
1157 };
Definition: VideoInfoScanner.h:28
Definition: VideoDatabase.h:408
Definition: VideoDatabase.h:399
Represents a list of files.
Definition: FileItem.h:721
Definition: Database.h:29
Definition: VideoDatabase.h:395
Definition: Bookmark.h:14
Definition: Database.h:11
Definition: StreamDetails.h:92
Definition: Application.h:74
Definition: TestNfsFile.cpp:22
Definition: VideoDatabase.h:418
Definition: Database.h:26
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Definition: settings.py:1
Definition: GUIDialogExtendedProgressBar.h:16
Definition: GUIDialogProgress.h:16
Definition: DbUrl.h:18
Definition: VideoDatabase.h:199
Definition: SortUtils.h:176
Definition: VideoInfoTag.h:51
Definition: VideoSettings.h:194
Represents a file on a share.
Definition: FileItem.h:102