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 
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
146 
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
156 
157 enum class VideoDbContentType
158 {
159  UNKNOWN = -1,
160  MOVIES = 1,
161  TVSHOWS = 2,
162  MUSICVIDEOS = 3,
163  EPISODES = 4,
164  MOVIE_SETS = 5,
165  MUSICALBUMS = 6
166 };
167 
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)
169 {
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;
197 
198 const struct SDbTableOffsets
199 {
200  int type;
201  size_t offset;
202 } DbMovieOffsets[] =
203 {
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) }
228 };
229 
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)
231 {
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;
252 
253 const struct SDbTableOffsets DbTvShowOffsets[] =
254 {
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)}
272 };
273 
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)
276 {
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;
295 
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)
297 {
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;
322 
323 const struct SDbTableOffsets DbEpisodeOffsets[] =
324 {
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) }
346 };
347 
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)
349 {
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;
369 
370 const struct SDbTableOffsets DbMusicVideoOffsets[] =
371 {
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)}
388 };
389 
390 #define COMPARE_PERCENTAGE 0.90f // 90%
391 #define COMPARE_PERCENTAGE_MIN 0.50f // 50%
392 
393 class CVideoDatabase : public CDatabase
394 {
395 public:
396 
397  class CActor // used for actor retrieval for non-master users
398  {
399  public:
400  std::string name;
401  std::string thumb;
402  int playcount;
403  int appearances;
404  };
405 
406  class CSeason // used for season retrieval for non-master users
407  {
408  public:
409  std::string path;
410  std::vector<std::string> genre;
411  int numEpisodes;
412  int numWatched;
413  int id;
414  };
415 
416  class CSetInfo
417  {
418  public:
419  std::string name;
420  VECMOVIES movies;
421  DatabaseResults results;
422  };
423 
424  CVideoDatabase(void);
425  ~CVideoDatabase(void) override;
426 
427  bool Open() override;
428  bool CommitTransaction() override;
429 
430  int AddNewEpisode(int idShow, CVideoInfoTag& details);
431 
432  // editing functions
442  CDateTime SetPlayCount(const CFileItem& item, int count, const CDateTime& date = CDateTime());
443 
450  CDateTime IncrementPlayCount(const CFileItem& item);
451 
457  int GetPlayCount(const CFileItem &item);
458 
464  int GetPlayCount(const std::string& strFilenameAndPath);
465 
471  CDateTime GetLastPlayed(const std::string& strFilenameAndPath);
472 
479  CDateTime UpdateLastPlayed(const CFileItem& item);
480 
487  bool GetPlayCounts(const std::string &path, CFileItemList &items);
488 
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);
495 
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);
500 
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);
512 
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);
523 
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);
528 
529  void GetEpisodesByFile(const std::string& strFilenameAndPath, std::vector<CVideoInfoTag>& episodes);
530 
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);
533 
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);
538 
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);
561 
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);
569 
570  int UpdateDetailsForMovie(int idMovie, CVideoInfoTag& details, const std::map<std::string, std::string> &artwork, const std::set<std::string> &updatedDetails);
571 
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);
584 
590  bool GetVideoSettings(int idFile, CVideoSettings &settings);
591 
597  bool GetVideoSettings(const CFileItem &item, CVideoSettings &settings);
598 
604  bool GetVideoSettings(const std::string &filePath, CVideoSettings &settings);
605 
610  void SetVideoSettings(const CFileItem &item, const CVideoSettings &settings);
611 
616  void SetVideoSettings(int idFile, const CVideoSettings &settings);
617 
622  void EraseVideoSettings(const CFileItem &item);
623 
627  void EraseAllVideoSettings();
628 
633  void EraseAllVideoSettings(const std::string& path);
634 
639  void EraseAllForPath(const std::string& path);
640 
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);
643 
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);
659 
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);
664 
673  ADDON::ScraperPtr GetScraperForPath(const std::string& strPath, VIDEO::SScanSettings& settings, bool& foundDirectly);
674 
683  std::string GetContentForPath(const std::string& strPath);
684 
691  bool GetItemsForPath(const std::string &content, const std::string &path, CFileItemList &items);
692 
697  bool ScraperInUse(const std::string &scraperID) const;
698 
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);
704 
710  bool GetPathsLinkedToTvShow(int idShow, std::vector<std::string> &paths);
711 
717  bool GetSubPaths(const std::string& basepath, std::vector< std::pair<int, std::string> >& subpaths);
718 
719  bool GetSourcePath(const std::string &path, std::string &sourcePath);
720  bool GetSourcePath(const std::string &path, std::string &sourcePath, VIDEO::SScanSettings& settings);
721 
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 = "");
724 
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);
729 
730  void GetMusicVideosByArtist(const std::string& strArtist, CFileItemList& items);
731  void GetMusicVideosByAlbum(const std::string& strAlbum, CFileItemList& items);
732 
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);
736 
737  void GetMovieCountriesByName(const std::string& strSearch, CFileItemList& items);
738 
739  void GetMusicVideoAlbumsByName(const std::string& strSearch, CFileItemList& items);
740 
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);
744 
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);
748 
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);
753 
754  void GetEpisodesByPlot(const std::string& strSearch, CFileItemList& items);
755  void GetMoviesByPlot(const std::string& strSearch, CFileItemList& items);
756 
757  bool LinkMovieToTvshow(int idMovie, int idShow, bool bRemove);
758  bool IsLinkedToTvshow(int idMovie);
759  bool GetLinksToTvShow(int idMovie, std::vector<int>& ids);
760 
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);
807 
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);
813 
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);
818 
819  bool HasContent();
820  bool HasContent(VideoDbContentType type);
821  bool HasSets() const;
822 
823  void CleanDatabase(CGUIDialogProgressBarHandle* handle = NULL, const std::set<int>& paths = std::set<int>(), bool showProgress = true);
824 
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());
839 
845  int AddFile(const CFileItem& item);
846 
853  int AddFile(const CVideoInfoTag& details, const std::string& parentPath = "");
854 
862  int AddPath(const std::string& strPath, const std::string &parentPath = "", const CDateTime& dateAdded = CDateTime());
863 
868  void UpdateFileDateAdded(CVideoInfoTag& details);
869 
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);
875 
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);
883 
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());
886 
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);
897 
898  // partymode
904  unsigned int GetRandomMusicVideoIDs(const std::string& strWhere, std::vector<std::pair<int, int> > &songIDs);
905 
906  static void VideoContentTypeToString(VideoDbContentType type, std::string& out)
907  {
908  switch (type)
909  {
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;
924  }
925  }
926 
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 
943  std::string GetTvShowNamedSeasonById(int tvshowId, int seasonId);
944 
945  bool GetTvShowSeasonArt(int mediaId, std::map<int, std::map<std::string, std::string> > &seasonArt);
946  bool GetArtTypes(const MediaType &mediaType, std::vector<std::string> &artTypes);
947 
954  std::vector<std::string> GetAvailableArtTypesForItem(int mediaId, const MediaType& mediaType);
955 
963  std::vector<CScraperUrl::SUrlEntry> GetAvailableArtForItem(
964  int mediaId, const MediaType& mediaType, const std::string& artType);
965 
966  int AddTag(const std::string &tag);
967  void AddTagToItem(int idItem, int idTag, const std::string &type);
968  void RemoveTagFromItem(int idItem, int idTag, const std::string &type);
969  void RemoveTagsFromItem(int idItem, const std::string &type);
970 
971  bool GetFilter(CDbUrl &videoUrl, Filter &filter, SortDescription &sorting) override;
972 
978  int AddSeason(int showID, int season, const std::string& name = "");
979  int AddSet(const std::string& strSet, const std::string& strOverview = "");
980  void ClearMovieSet(int idMovie);
981  void SetMovieSet(int idMovie, int idSet);
982  bool SetVideoUserRating(int dbId, int rating, const MediaType& mediaType);
983  bool GetUseAllExternalAudioForVideo(const std::string& videoPath);
984 
985 protected:
986  int AddNewMovie(CVideoInfoTag& details);
987  int AddNewMusicVideo(CVideoInfoTag& details);
988 
989  int GetMovieId(const std::string& strFilenameAndPath);
990  int GetMusicVideoId(const std::string& strFilenameAndPath);
991 
997  int GetFileId(const CFileItem &item);
998  int GetFileId(const CVideoInfoTag& details);
999 
1004  int GetAndFillFileId(CVideoInfoTag& details);
1005 
1010  int GetFileId(const std::string& url);
1011 
1012  int AddToTable(const std::string& table, const std::string& firstField, const std::string& secondField, const std::string& value);
1013  int UpdateRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating);
1014  int AddRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating);
1015  int UpdateUniqueIDs(int mediaId, const char *mediaType, const CVideoInfoTag& details);
1016  int AddUniqueIDs(int mediaId, const char *mediaType, const CVideoInfoTag& details);
1017  int AddActor(const std::string& strActor, const std::string& thumbURL, const std::string &thumb = "");
1018 
1019  int AddTvShow();
1020 
1028  bool AddPathToTvShow(int idShow, const std::string &path, const std::string &parentPath, const CDateTime& dateAdded = CDateTime());
1029 
1035  int GetMatchingTvShow(const CVideoInfoTag &show);
1036 
1037  // link functions - these two do all the work
1038  void AddLinkToActor(int mediaId, const char *mediaType, int actorId, const std::string &role, int order);
1039  void AddToLinkTable(int mediaId, const std::string& mediaType, const std::string& table, int valueId, const char *foreignKey = NULL);
1040  void RemoveFromLinkTable(int mediaId, const std::string& mediaType, const std::string& table, int valueId, const char *foreignKey = NULL);
1041 
1042  void AddLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1043  void UpdateLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1044  void AddActorLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1045  void UpdateActorLinksToItem(int mediaId, const std::string& mediaType, const std::string& field, const std::vector<std::string>& values);
1046 
1047  void AddCast(int mediaId, const char *mediaType, const std::vector<SActorInfo> &cast);
1048 
1049  CVideoInfoTag GetDetailsForMovie(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1050  CVideoInfoTag GetDetailsForMovie(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1051  CVideoInfoTag GetDetailsForTvShow(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone, CFileItem* item = NULL);
1052  CVideoInfoTag GetDetailsForTvShow(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone, CFileItem* item = NULL);
1053  CVideoInfoTag GetBasicDetailsForEpisode(std::unique_ptr<dbiplus::Dataset> &pDS);
1054  CVideoInfoTag GetBasicDetailsForEpisode(const dbiplus::sql_record* const record);
1055  CVideoInfoTag GetDetailsForEpisode(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1056  CVideoInfoTag GetDetailsForEpisode(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1057  CVideoInfoTag GetDetailsForMusicVideo(std::unique_ptr<dbiplus::Dataset> &pDS, int getDetails = VideoDbDetailsNone);
1058  CVideoInfoTag GetDetailsForMusicVideo(const dbiplus::sql_record* const record, int getDetails = VideoDbDetailsNone);
1059  bool GetPeopleNav(const std::string& strBaseDir,
1060  CFileItemList& items,
1061  const char* type,
1062  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
1063  const Filter& filter = Filter(),
1064  bool countOnly = false);
1065  bool GetNavCommon(const std::string& strBaseDir,
1066  CFileItemList& items,
1067  const char* type,
1068  VideoDbContentType idContent = VideoDbContentType::UNKNOWN,
1069  const Filter& filter = Filter(),
1070  bool countOnly = false);
1071  void GetCast(int media_id, const std::string &media_type, std::vector<SActorInfo> &cast);
1072  void GetTags(int media_id, const std::string &media_type, std::vector<std::string> &tags);
1073  void GetRatings(int media_id, const std::string &media_type, RatingMap &ratings);
1074  void GetUniqueIDs(int media_id, const std::string &media_type, CVideoInfoTag& details);
1075 
1076  void GetDetailsFromDB(std::unique_ptr<dbiplus::Dataset> &pDS, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
1077  void GetDetailsFromDB(const dbiplus::sql_record* const record, int min, int max, const SDbTableOffsets *offsets, CVideoInfoTag &details, int idxOffset = 2);
1078  std::string GetValueString(const CVideoInfoTag &details, int min, int max, const SDbTableOffsets *offsets) const;
1079 
1080 private:
1081  void CreateTables() override;
1082  void CreateAnalytics() override;
1083  void UpdateTables(int version) override;
1084  void CreateLinkIndex(const char *table);
1085  void CreateForeignLinkIndex(const char *table, const char *foreignkey);
1086 
1090  virtual void CreateViews();
1091 
1097  int GetDbId(const std::string &query);
1098 
1104  int RunQuery(const std::string &sql);
1105 
1106  void AppendIdLinkFilter(const char* field, const char *table, const MediaType& mediaType, const char *view, const char *viewKey, const CUrlOptions::UrlOptions& options, Filter &filter);
1107  void AppendLinkFilter(const char* field, const char *table, const MediaType& mediaType, const char *view, const char *viewKey, const CUrlOptions::UrlOptions& options, Filter &filter);
1108 
1113  bool LookupByFolders(const std::string &path, bool shows = false);
1114 
1120  int GetPlayCount(int iFileId);
1121 
1127  CDateTime GetLastPlayed(int iFileId);
1128 
1129  bool GetSeasonInfo(int idSeason, CVideoInfoTag& details, bool allDetails, CFileItem* item);
1130 
1131  int GetMinSchemaVersion() const override { return 75; }
1132  int GetSchemaVersion() const override;
1133  virtual int GetExportVersion() const { return 1; }
1134  const char* GetBaseDBName() const override { return "MyVideos"; }
1135 
1136  void ConstructPath(std::string& strDest, const std::string& strPath, const std::string& strFileName);
1137  void SplitPath(const std::string& strFileNameAndPath, std::string& strPath, std::string& strFileName);
1138  void InvalidatePathHash(const std::string& strPath);
1139 
1145  std::string GetSafeFile(const std::string &dir, const std::string &name) const;
1146 
1147  std::vector<int> CleanMediaType(const std::string &mediaType, const std::string &cleanableFileIDs,
1148  std::map<int, bool> &pathsDeleteDecisions, std::string &deletedFileIDs, bool silent);
1149 
1150  static void AnnounceRemove(const std::string& content, int id, bool scanning = false);
1151  static void AnnounceUpdate(const std::string& content, int id);
1152 
1153  static CDateTime GetDateAdded(const std::string& filename, CDateTime dateAdded = CDateTime());
1154 };
Definition: VideoInfoScanner.h:28
Definition: VideoDatabase.h:406
Definition: VideoDatabase.h:397
Represents a list of files.
Definition: FileItem.h:713
Definition: Database.h:29
Definition: VideoDatabase.h:393
Definition: Bookmark.h:14
Definition: Database.h:11
Definition: StreamDetails.h:92
Definition: Application.h:74
Definition: TestNfsFile.cpp:22
Definition: VideoDatabase.h:416
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:198
Definition: SortUtils.h:176
Definition: VideoInfoTag.h:51
Definition: VideoSettings.h:194
Represents a file on a share.
Definition: FileItem.h:102