[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / video / VideoInfoScanner.h
blobabfcbd52f40a03447259e87456fc7afaaa24ec8d
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "InfoScanner.h"
12 #include "VideoDatabase.h"
13 #include "addons/Scraper.h"
14 #include "guilib/GUIListItem.h"
16 #include <set>
17 #include <string>
18 #include <vector>
20 class CRegExp;
21 class CFileItem;
22 class CFileItemList;
24 namespace KODI::VIDEO
26 class IVideoInfoTagLoader;
28 typedef struct SScanSettings
30 SScanSettings()
32 parent_name = false;
33 parent_name_root = false;
34 noupdate = false;
35 exclude = false;
36 m_allExtAudio = false;
37 recurse = 1;
39 bool parent_name; /* use the parent dirname as name of lookup */
40 bool parent_name_root; /* use the name of directory where scan started as name for files in that dir */
41 int recurse; /* recurse into sub folders (indicate levels) */
42 bool noupdate; /* exclude from update library function */
43 bool exclude; /* exclude this path from scraping */
44 bool m_allExtAudio; /* treat all audio files in video directory as external tracks */
45 } SScanSettings;
47 class CVideoInfoScanner : public CInfoScanner
49 public:
50 CVideoInfoScanner();
51 ~CVideoInfoScanner() override;
53 /*! \brief Scan a folder using the background scanner
54 \param strDirectory path to scan
55 \param scanAll whether to scan everything not already scanned (regardless of whether the user normally doesn't want a folder scanned.) Defaults to false.
57 void Start(const std::string& strDirectory, bool scanAll = false);
58 void Stop();
60 /*! \brief Add an item to the database.
61 \param pItem item to add to the database.
62 \param content content type of the item.
63 \param videoFolder whether the video is represented by a folder (single movie per folder). Defaults to false.
64 \param useLocal whether to use local information for artwork etc.
65 \param showInfo pointer to CVideoInfoTag details for the show if this is an episode. Defaults to NULL.
66 \param libraryImport Whether this call belongs to a full library import or not. Defaults to false.
67 \return database id of the added item, or -1 on failure.
69 long AddVideo(CFileItem *pItem, const CONTENT_TYPE &content, bool videoFolder = false, bool useLocal = true, const CVideoInfoTag *showInfo = NULL, bool libraryImport = false);
71 /*! \brief Retrieve information for a list of items and add them to the database.
72 \param items list of items to retrieve info for.
73 \param bDirNames whether we should use folder or file names for lookups.
74 \param content type of content to retrieve.
75 \param useLocal should local data (.nfo and art) be used. Defaults to true.
76 \param pURL an optional URL to use to retrieve online info. Defaults to NULL.
77 \param fetchEpisodes whether we are fetching episodes with shows. Defaults to true.
78 \param pDlgProgress progress dialog to update and check for cancellation during processing. Defaults to NULL.
79 \return true if we successfully found information for some items, false otherwise
81 bool RetrieveVideoInfo(CFileItemList& items, bool bDirNames, CONTENT_TYPE content, bool useLocal = true, CScraperUrl *pURL = NULL, bool fetchEpisodes = true, CGUIDialogProgress* pDlgProgress = NULL);
83 static void ApplyThumbToFolder(const std::string &folder, const std::string &imdbThumb);
84 static bool DownloadFailed(CGUIDialogProgress* pDlgProgress);
86 /*! \brief Retrieve any artwork associated with an item
87 \param pItem item to find artwork for.
88 \param content content type of the item.
89 \param bApplyToDir whether we should apply any thumbs to a folder. Defaults to false.
90 \param useLocal whether we should use local thumbs. Defaults to true.
91 \param actorArtPath the path to search for actor thumbs. Defaults to empty.
93 void GetArtwork(CFileItem *pItem, const CONTENT_TYPE &content, bool bApplyToDir=false, bool useLocal=true, const std::string &actorArtPath = "");
95 /*! \brief Get season thumbs for a tvshow.
96 All seasons (regardless of whether the user has episodes) are added to the art map.
97 \param show tvshow info tag
98 \param art artwork map to which season thumbs are added.
99 \param useLocal whether to use local thumbs, defaults to true
101 static void GetSeasonThumbs(const CVideoInfoTag &show, std::map<int, std::map<std::string, std::string> > &art, const std::vector<std::string> &artTypes, bool useLocal = true);
102 static std::string GetImage(const CScraperUrl::SUrlEntry &image, const std::string& itemPath);
104 bool EnumerateEpisodeItem(const CFileItem *item, EPISODELIST& episodeList);
106 static std::string GetMovieSetInfoFolder(const std::string& setTitle);
108 protected:
109 virtual void Process();
110 bool DoScan(const std::string& strDirectory) override;
112 INFO_RET RetrieveInfoForTvShow(CFileItem *pItem, bool bDirNames, ADDON::ScraperPtr &scraper, bool useLocal, CScraperUrl* pURL, bool fetchEpisodes, CGUIDialogProgress* pDlgProgress);
113 INFO_RET RetrieveInfoForMovie(CFileItem *pItem, bool bDirNames, ADDON::ScraperPtr &scraper, bool useLocal, CScraperUrl* pURL, CGUIDialogProgress* pDlgProgress);
114 INFO_RET RetrieveInfoForMusicVideo(CFileItem *pItem, bool bDirNames, ADDON::ScraperPtr &scraper, bool useLocal, CScraperUrl* pURL, CGUIDialogProgress* pDlgProgress);
115 INFO_RET RetrieveInfoForEpisodes(CFileItem *item, long showID, const ADDON::ScraperPtr &scraper, bool useLocal, CGUIDialogProgress *progress = NULL);
117 /*! \brief Update the progress bar with the heading and line and check for cancellation
118 \param progress CGUIDialogProgress bar
119 \param heading string id of heading
120 \param line1 string to set for the first line
121 \return true if the user has cancelled the scanner, false otherwise
123 bool ProgressCancelled(CGUIDialogProgress* progress, int heading, const std::string &line1);
125 /*! \brief Find a url for the given video using the given scraper
126 \param title title of the video to lookup
127 \param year year of the video to lookup
128 \param scraper scraper to use for the lookup
129 \param url [out] returned url from the scraper
130 \param progress CGUIDialogProgress bar
131 \return >0 on success, <0 on failure (cancellation), and 0 on no info found
133 int FindVideo(const std::string &title, int year, const ADDON::ScraperPtr &scraper, CScraperUrl &url, CGUIDialogProgress *progress);
135 /*! \brief Find a url for the given video using the given scraper
136 \param item the video to lookup
137 \param scraper scraper to use for the lookup
138 \param url [out] returned url from the scraper
139 \param progress CGUIDialogProgress bar
140 \return >0 on success, <0 on failure (cancellation), and 0 on no info found
142 int FindVideoUsingTag(CFileItem& item, const ADDON::ScraperPtr &scraper, CScraperUrl &url, CGUIDialogProgress *progress);
144 /*! \brief Retrieve detailed information for an item from an online source, optionally supplemented with local data
145 @todo sort out some better return codes.
146 \param pItem item to retrieve online details for.
147 \param uniqueIDs Unique IDs for additional information for scrapers.
148 \param url URL to use to retrieve online details.
149 \param scraper Scraper that handles parsing the online data.
150 \param nfoFile if set, we override the online data with the locally supplied data. Defaults to NULL.
151 \param pDialog progress dialog to update and check for cancellation during processing. Defaults to NULL.
152 \return true if information is found, false if an error occurred, the lookup was cancelled, or no information was found.
154 bool GetDetails(CFileItem* pItem,
155 const std::unordered_map<std::string, std::string>& uniqueIDs,
156 CScraperUrl& url,
157 const ADDON::ScraperPtr& scraper,
158 VIDEO::IVideoInfoTagLoader* nfoFile = nullptr,
159 CGUIDialogProgress* pDialog = nullptr);
161 /*! \brief Extract episode and season numbers from a processed regexp
162 \param reg Regular expression object with at least 2 matches
163 \param episodeInfo Episode information to fill in.
164 \param defaultSeason Season to use if not found in reg.
165 \return true on success (2 matches), false on failure (fewer than 2 matches)
167 bool GetEpisodeAndSeasonFromRegExp(CRegExp &reg, EPISODE &episodeInfo, int defaultSeason);
169 /*! \brief Extract episode air-date from a processed regexp
170 \param reg Regular expression object with at least 3 matches
171 \param episodeInfo Episode information to fill in.
172 \return true on success (3 matches), false on failure (fewer than 3 matches)
174 bool GetAirDateFromRegExp(CRegExp &reg, EPISODE &episodeInfo);
176 /*! \brief Extract episode title from a processed regexp
177 \param reg Regular expression object with at least 1 match
178 \param episodeInfo Episode information to fill in.
179 \return true on success (1 match), false on failure (no matches)
181 bool GetEpisodeTitleFromRegExp(CRegExp& reg, EPISODE& episodeInfo);
183 /*! \brief Fetch thumbs for actors
184 Updates each actor with their thumb (local or online)
185 \param actors - vector of SActorInfo
186 \param strPath - path on filesystem to look for local thumbs
188 void FetchActorThumbs(std::vector<SActorInfo>& actors, const std::string& strPath);
190 static int GetPathHash(const CFileItemList &items, std::string &hash);
192 /*! \brief Retrieve a "fast" hash of the given directory (if available)
193 Performs a stat() on the directory, and uses modified time to create a "fast"
194 hash of the folder. If no modified time is available, the create time is used,
195 and if neither are available, an empty hash is returned.
196 In case exclude from scan expressions are present, the string array will be appended
197 to the md5 hash to ensure we're doing a re-scan whenever the user modifies those.
198 \param directory folder to hash
199 \param excludes string array of exclude expressions
200 \return the md5 hash of the folder"
202 std::string GetFastHash(const std::string &directory, const std::vector<std::string> &excludes) const;
204 /*! \brief Retrieve a "fast" hash of the given directory recursively (if available)
205 Performs a stat() on the directory, and uses modified time to create a "fast"
206 hash of each folder. If no modified time is available, the create time is used,
207 and if neither are available, an empty hash is returned.
208 In case exclude from scan expressions are present, the string array will be appended
209 to the md5 hash to ensure we're doing a re-scan whenever the user modifies those.
210 \param directory folder to hash (recursively)
211 \param excludes string array of exclude expressions
212 \return the md5 hash of the folder
214 std::string GetRecursiveFastHash(const std::string &directory, const std::vector<std::string> &excludes) const;
216 /*! \brief Decide whether a folder listing could use the "fast" hash
217 Fast hashing can be done whenever the folder contains no scannable subfolders, as the
218 fast hash technique uses modified time to determine when folder content changes, which
219 is generally not propagated up the directory tree.
220 \param items the directory listing
221 \param excludes string array of exclude expressions
222 \return true if this directory listing can be fast hashed, false otherwise
224 bool CanFastHash(const CFileItemList &items, const std::vector<std::string> &excludes) const;
226 /*! \brief Process a series folder, filling in episode details and adding them to the database.
227 @todo Ideally we would return INFO_HAVE_ALREADY if we don't have to update any episodes
228 and we should return INFO_NOT_FOUND only if no information is found for any of
229 the episodes. INFO_ADDED then indicates we've added one or more episodes.
230 \param files the episode files to process.
231 \param scraper scraper to use for finding online info
232 \param showInfo information for the show.
233 \param pDlgProcess progress dialog to update during processing. Defaults to NULL.
234 \return INFO_ERROR on failure, INFO_CANCELLED on cancellation,
235 INFO_NOT_FOUND if an episode isn't found, or INFO_ADDED if all episodes are added.
237 INFO_RET OnProcessSeriesFolder(EPISODELIST& files, const ADDON::ScraperPtr &scraper, bool useLocal, const CVideoInfoTag& showInfo, CGUIDialogProgress* pDlgProgress = NULL);
239 bool EnumerateSeriesFolder(CFileItem* item, EPISODELIST& episodeList);
240 bool ProcessItemByVideoInfoTag(const CFileItem *item, EPISODELIST &episodeList);
242 bool AddVideoExtras(CFileItemList& items, const CONTENT_TYPE& content, const std::string& path);
243 bool ProcessVideoVersion(VideoDbContentType itemType, int dbId);
245 bool m_bStop;
246 bool m_scanAll;
247 bool m_ignoreVideoVersions{false};
248 bool m_ignoreVideoExtras{false};
249 std::string m_strStartDir;
250 CVideoDatabase m_database;
251 std::set<std::string> m_pathsToCount;
252 std::set<int> m_pathsToClean;
254 private:
255 static void AddLocalItemArtwork(CGUIListItem::ArtMap& itemArt,
256 const std::vector<std::string>& wantedArtTypes, const std::string& itemPath,
257 bool addAll, bool exactName);
259 /*! \brief Retrieve the art type for an image from the given size.
260 \param width the width of the image.
261 \param height the height of the image.
262 \return "poster" if the aspect ratio is at most 4:5, "banner" if the aspect ratio
263 is at least 1:4, "thumb" otherwise.
265 static std::string GetArtTypeFromSize(unsigned int width, unsigned int height);
267 } // namespace KODI::VIDEO