kodi
Scraper.h
1 /*
2  * Copyright (C) 2005-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 "XBDateTime.h"
12 #include "addons/Addon.h"
13 #include "utils/ScraperParser.h"
14 #include "utils/ScraperUrl.h"
15 #include "video/Episode.h"
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 class CAlbum;
22 class CArtist;
23 class CVideoInfoTag;
24 
25 namespace MUSIC_GRABBER
26 {
27 class CMusicAlbumInfo;
28 class CMusicArtistInfo;
29 }
30 
31 typedef enum
32 {
33  CONTENT_MOVIES,
34  CONTENT_TVSHOWS,
35  CONTENT_MUSICVIDEOS,
36  CONTENT_ALBUMS,
37  CONTENT_ARTISTS,
38  CONTENT_NONE,
39 } CONTENT_TYPE;
40 
41 namespace XFILE
42 {
43  class CCurlFile;
44 }
45 
46 class CScraperUrl;
47 
48 namespace ADDON
49 {
50 class CScraper;
51 typedef std::shared_ptr<CScraper> ScraperPtr;
52 
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);
56 
57 // thrown as exception to signal abort or show error dialog
59 {
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) {}
64 
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; }
68 
69 private:
70  bool m_fAborted = true;
71  std::string m_sTitle;
72  std::string m_sMessage;
73 };
74 
75 class CScraper : public CAddon
76 {
77 public:
78  explicit CScraper(const AddonInfoPtr& addonInfo, AddonType addonType);
79 
88  bool SetPathSettings(CONTENT_TYPE content, const std::string& xml);
89 
96  std::string GetPathSettings();
97 
102  void ClearCache();
103 
104  CONTENT_TYPE Content() const { return m_pathContent; }
105  bool RequiresSettings() const { return m_requiressettings; }
106  bool Supports(const CONTENT_TYPE &content) const;
107 
108  bool IsInUse() const override;
109  bool IsNoop();
110  bool IsPython() const { return m_isPython; }
111 
112  // scraper media functions
113  CScraperUrl NfoUrl(const std::string &sNfoContent);
114 
124  CScraperUrl ResolveIDToUrl(const std::string &externalID);
125 
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  VIDEO::EPISODELIST GetEpisodeList(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl);
133 
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);
144 
145 private:
146  CScraper(const CScraper &rhs) = delete;
147  CScraper& operator=(const CScraper&) = delete;
148  CScraper(CScraper&&) = delete;
149  CScraper& operator=(CScraper&&) = delete;
150 
151  std::string SearchStringEncoding() const
152  { return m_parser.GetSearchStringEncoding(); }
153 
160  std::string GetPathSettingsAsJSON();
161 
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);
175 
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;
182 };
183 
184 }
185 
Definition: Scraper.h:41
Definition: Scraper.h:75
Definition: Scraper.h:58
Definition: Album.h:26
Definition: XBDateTime.h:21
Definition: ScraperParser.h:26
Definition: CurlFile.h:24
Definition: Addon.cpp:39
Definition: Scraper.h:25
Definition: VideoInfoTag.h:53
Definition: Artist.h:40
Definition: Addon.h:34
Definition: ScraperUrl.h:21