xbmc
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, const CScraperUrl &scurl,
135  bool fMovie/*else episode*/, CVideoInfoTag &video);
136  bool GetAlbumDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
137  CAlbum &album);
138  bool GetArtistDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
139  const std::string &sSearch, CArtist &artist);
140  bool GetArtwork(XFILE::CCurlFile &fcurl, CVideoInfoTag &details);
141 
142 private:
143  CScraper(const CScraper &rhs) = delete;
144  CScraper& operator=(const CScraper&) = delete;
145  CScraper(CScraper&&) = delete;
146  CScraper& operator=(CScraper&&) = delete;
147 
148  std::string SearchStringEncoding() const
149  { return m_parser.GetSearchStringEncoding(); }
150 
157  std::string GetPathSettingsAsJSON();
158 
159  bool Load();
160  std::vector<std::string> Run(const std::string& function,
161  const CScraperUrl& url,
162  XFILE::CCurlFile& http,
163  const std::vector<std::string>* extras = nullptr);
164  std::vector<std::string> RunNoThrow(const std::string& function,
165  const CScraperUrl& url,
166  XFILE::CCurlFile& http,
167  const std::vector<std::string>* extras = nullptr);
168  std::string InternalRun(const std::string& function,
169  const CScraperUrl& url,
170  XFILE::CCurlFile& http,
171  const std::vector<std::string>* extras);
172 
173  bool m_fLoaded;
174  bool m_isPython = false;
175  bool m_requiressettings;
176  CDateTimeSpan m_persistence;
177  CONTENT_TYPE m_pathContent;
178  CScraperParser m_parser;
179 };
180 
181 }
182 
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:51
Definition: Artist.h:32
Definition: Addon.h:34
Definition: ScraperUrl.h:21