[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / addons / Scraper.h
blobd09a4e082c157ea6fec14b974893e9dc3393f4bc
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 "XBDateTime.h"
12 #include "addons/Addon.h"
13 #include "utils/ScraperParser.h"
14 #include "utils/ScraperUrl.h"
15 #include "video/Episode.h"
17 #include <memory>
18 #include <string>
19 #include <vector>
21 class CAlbum;
22 class CArtist;
23 class CVideoInfoTag;
25 namespace MUSIC_GRABBER
27 class CMusicAlbumInfo;
28 class CMusicArtistInfo;
31 typedef enum
33 CONTENT_MOVIES,
34 CONTENT_TVSHOWS,
35 CONTENT_MUSICVIDEOS,
36 CONTENT_ALBUMS,
37 CONTENT_ARTISTS,
38 CONTENT_NONE,
39 } CONTENT_TYPE;
41 namespace XFILE
43 class CCurlFile;
46 class CScraperUrl;
48 namespace ADDON
50 class CScraper;
51 typedef std::shared_ptr<CScraper> ScraperPtr;
53 std::string TranslateContent(const CONTENT_TYPE &content, bool pretty=false);
54 CONTENT_TYPE TranslateContent(const std::string &string);
55 AddonType ScraperTypeFromContent(const CONTENT_TYPE& content);
57 // thrown as exception to signal abort or show error dialog
58 class CScraperError
60 public:
61 CScraperError() = default;
62 CScraperError(const std::string &sTitle, const std::string &sMessage) :
63 m_fAborted(false), m_sTitle(sTitle), m_sMessage(sMessage) {}
65 bool FAborted() const { return m_fAborted; }
66 const std::string &Title() const { return m_sTitle; }
67 const std::string &Message() const { return m_sMessage; }
69 private:
70 bool m_fAborted = true;
71 std::string m_sTitle;
72 std::string m_sMessage;
75 class CScraper : public CAddon
77 public:
78 explicit CScraper(const AddonInfoPtr& addonInfo, AddonType addonType);
80 /*! \brief Set the scraper settings for a particular path from an XML string
81 Loads the default and user settings (if not already loaded) and, if the given XML string is non-empty,
82 overrides the user settings with the XML.
83 \param content Content type of the path
84 \param xml string of XML with the settings. If non-empty this overrides any saved user settings.
85 \return true if settings are available, false otherwise
86 \sa GetPathSettings
88 bool SetPathSettings(CONTENT_TYPE content, const std::string& xml);
90 /*! \brief Get the scraper settings for a particular path in the form of an XML string
91 Loads the default and user settings (if not already loaded) and returns the user settings in the
92 form or an XML string
93 \return a string containing the XML settings
94 \sa SetPathSettings
96 std::string GetPathSettings();
98 /*! \brief Clear any previously cached results for this scraper
99 Any previously cached files are cleared if they have been cached for longer than the specified
100 cachepersistence.
102 void ClearCache();
104 CONTENT_TYPE Content() const { return m_pathContent; }
105 bool RequiresSettings() const { return m_requiressettings; }
106 bool Supports(const CONTENT_TYPE &content) const;
108 bool IsInUse() const override;
109 bool IsNoop();
110 bool IsPython() const { return m_isPython; }
112 // scraper media functions
113 CScraperUrl NfoUrl(const std::string &sNfoContent);
115 /*! \brief Resolve an external ID (e.g. MusicBrainz IDs) to a URL using scrapers
116 If we have an ID in hand, e.g. MusicBrainz IDs or TheTVDB Season IDs
117 we can get directly to a URL instead of searching by name and choosing from
118 the search results. The correct scraper type should be used to get the right
119 URL for a given ID, so we can differentiate albums, artists, TV Seasons, etc.
120 \param externalID the external ID - e.g. MusicBrainzArtist/AlbumID
121 \return a populated URL pointing to the details page for the given ID or
122 an empty URL if we couldn't resolve the ID.
124 CScraperUrl ResolveIDToUrl(const std::string &externalID);
126 std::vector<CScraperUrl> FindMovie(XFILE::CCurlFile &fcurl,
127 const std::string &movieTitle, int movieYear, bool fFirst);
128 std::vector<MUSIC_GRABBER::CMusicAlbumInfo> FindAlbum(XFILE::CCurlFile &fcurl,
129 const std::string &sAlbum, const std::string &sArtist = "");
130 std::vector<MUSIC_GRABBER::CMusicArtistInfo> FindArtist(
131 XFILE::CCurlFile &fcurl, const std::string &sArtist);
132 KODI::VIDEO::EPISODELIST GetEpisodeList(XFILE::CCurlFile& fcurl, const CScraperUrl& scurl);
134 bool GetVideoDetails(XFILE::CCurlFile& fcurl,
135 const std::unordered_map<std::string, std::string>& uniqueIDs,
136 const CScraperUrl& scurl,
137 bool fMovie /*else episode*/,
138 CVideoInfoTag& video);
139 bool GetAlbumDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
140 CAlbum &album);
141 bool GetArtistDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
142 const std::string &sSearch, CArtist &artist);
143 bool GetArtwork(XFILE::CCurlFile &fcurl, CVideoInfoTag &details);
145 private:
146 CScraper(const CScraper &rhs) = delete;
147 CScraper& operator=(const CScraper&) = delete;
148 CScraper(CScraper&&) = delete;
149 CScraper& operator=(CScraper&&) = delete;
151 std::string SearchStringEncoding() const
152 { return m_parser.GetSearchStringEncoding(); }
154 /*! \brief Get the scraper settings for a particular path in the form of a JSON string
155 Loads the default and user settings (if not already loaded) and returns the user settings in the
156 form of an JSON string. It is used in Python scrapers.
157 \return a string containing the JSON settings
158 \sa SetPathSettings
160 std::string GetPathSettingsAsJSON();
162 bool Load();
163 std::vector<std::string> Run(const std::string& function,
164 const CScraperUrl& url,
165 XFILE::CCurlFile& http,
166 const std::vector<std::string>* extras = nullptr);
167 std::vector<std::string> RunNoThrow(const std::string& function,
168 const CScraperUrl& url,
169 XFILE::CCurlFile& http,
170 const std::vector<std::string>* extras = nullptr);
171 std::string InternalRun(const std::string& function,
172 const CScraperUrl& url,
173 XFILE::CCurlFile& http,
174 const std::vector<std::string>* extras);
176 bool m_fLoaded = false;
177 bool m_isPython = false;
178 bool m_requiressettings = false;
179 CDateTimeSpan m_persistence;
180 CONTENT_TYPE m_pathContent = CONTENT_NONE;
181 CScraperParser m_parser;