summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/Scraper.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2015-03-03 16:53:59 +0100
committermanuel <manuel@mausz.at>2015-03-03 16:53:59 +0100
commitffca21f2743a7b367fa212799c6e2fea6190dd5d (patch)
tree0608ea3a29cf644ec9ab204e2b4bb9bfaae1c381 /xbmc/addons/Scraper.h
downloadkodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.tar.gz
kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.tar.bz2
kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.zip
initial commit for kodi master
Diffstat (limited to 'xbmc/addons/Scraper.h')
-rw-r--r--xbmc/addons/Scraper.h178
1 files changed, 178 insertions, 0 deletions
diff --git a/xbmc/addons/Scraper.h b/xbmc/addons/Scraper.h
new file mode 100644
index 0000000..7302972
--- /dev/null
+++ b/xbmc/addons/Scraper.h
@@ -0,0 +1,178 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2013 Team XBMC
4 * http://xbmc.org
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21#include "addons/Addon.h"
22#include "XBDateTime.h"
23#include "utils/ScraperUrl.h"
24#include "utils/ScraperParser.h"
25#include "video/Episode.h"
26
27class CAlbum;
28class CArtist;
29class CVideoInfoTag;
30
31namespace MUSIC_GRABBER
32{
33class CMusicAlbumInfo;
34class CMusicArtistInfo;
35}
36
37typedef enum
38{
39 CONTENT_MOVIES,
40 CONTENT_TVSHOWS,
41 CONTENT_MUSICVIDEOS,
42 CONTENT_ALBUMS,
43 CONTENT_ARTISTS,
44 CONTENT_NONE,
45} CONTENT_TYPE;
46
47namespace XFILE
48{
49 class CCurlFile;
50}
51
52class CScraperUrl;
53
54namespace ADDON
55{
56class CScraper;
57typedef std::shared_ptr<CScraper> ScraperPtr;
58
59std::string TranslateContent(const CONTENT_TYPE &content, bool pretty=false);
60CONTENT_TYPE TranslateContent(const std::string &string);
61TYPE ScraperTypeFromContent(const CONTENT_TYPE &content);
62
63// thrown as exception to signal abort or show error dialog
64class CScraperError
65{
66public:
67 CScraperError() : m_fAborted(true) {}
68 CScraperError(const std::string &sTitle, const std::string &sMessage) :
69 m_fAborted(false), m_sTitle(sTitle), m_sMessage(sMessage) {}
70
71 bool FAborted() const { return m_fAborted; }
72 const std::string &Title() const { return m_sTitle; }
73 const std::string &Message() const { return m_sMessage; }
74
75private:
76 bool m_fAborted;
77 std::string m_sTitle;
78 std::string m_sMessage;
79};
80
81class CScraper : public CAddon
82{
83public:
84 CScraper(const AddonProps &props) : CAddon(props), m_fLoaded(false) {}
85 CScraper(const cp_extension_t *ext);
86 virtual ~CScraper() {}
87 virtual AddonPtr Clone() const;
88
89 /*! \brief Set the scraper settings for a particular path from an XML string
90 Loads the default and user settings (if not already loaded) and, if the given XML string is non-empty,
91 overrides the user settings with the XML.
92 \param content Content type of the path
93 \param xml string of XML with the settings. If non-empty this overrides any saved user settings.
94 \return true if settings are available, false otherwise
95 \sa GetPathSettings
96 */
97 bool SetPathSettings(CONTENT_TYPE content, const std::string& xml);
98
99 /*! \brief Get the scraper settings for a particular path in the form of an XML string
100 Loads the default and user settings (if not already loaded) and returns the user settings in the
101 form or an XML string
102 \return a string containing the XML settings
103 \sa SetPathSettings
104 */
105 std::string GetPathSettings();
106
107 /*! \brief Clear any previously cached results for this scraper
108 Any previously cached files are cleared if they have been cached for longer than the specified
109 cachepersistence.
110 */
111 void ClearCache();
112
113 CONTENT_TYPE Content() const { return m_pathContent; }
114 const std::string& Language() const { return m_language; }
115 bool RequiresSettings() const { return m_requiressettings; }
116 bool Supports(const CONTENT_TYPE &content) const;
117
118 bool IsInUse() const;
119 bool IsNoop();
120
121 // scraper media functions
122 CScraperUrl NfoUrl(const std::string &sNfoContent);
123
124 /*! \brief Resolve an external ID (e.g. MusicBrainz IDs) to a URL using scrapers
125 If we have an ID in hand, e.g. MusicBrainz IDs or TheTVDB Season IDs
126 we can get directly to a URL instead of searching by name and choosing from
127 the search results. The correct scraper type should be used to get the right
128 URL for a given ID, so we can differentiate albums, artists, TV Seasons, etc.
129 \param externalID the external ID - e.g. MusicBrainzArtist/AlbumID
130 \return a populated URL pointing to the details page for the given ID or
131 an empty URL if we couldn't resolve the ID.
132 */
133 CScraperUrl ResolveIDToUrl(const std::string &externalID);
134
135 std::vector<CScraperUrl> FindMovie(XFILE::CCurlFile &fcurl,
136 const std::string &sMovie, bool fFirst);
137 std::vector<MUSIC_GRABBER::CMusicAlbumInfo> FindAlbum(XFILE::CCurlFile &fcurl,
138 const std::string &sAlbum, const std::string &sArtist = "");
139 std::vector<MUSIC_GRABBER::CMusicArtistInfo> FindArtist(
140 XFILE::CCurlFile &fcurl, const std::string &sArtist);
141 VIDEO::EPISODELIST GetEpisodeList(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl);
142
143 bool GetVideoDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
144 bool fMovie/*else episode*/, CVideoInfoTag &video);
145 bool GetAlbumDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
146 CAlbum &album);
147 bool GetArtistDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
148 const std::string &sSearch, CArtist &artist);
149
150private:
151 CScraper(const CScraper &rhs);
152 std::string SearchStringEncoding() const
153 { return m_parser.GetSearchStringEncoding(); }
154
155 bool Load();
156 std::vector<std::string> Run(const std::string& function,
157 const CScraperUrl& url,
158 XFILE::CCurlFile& http,
159 const std::vector<std::string>* extras = NULL);
160 std::vector<std::string> RunNoThrow(const std::string& function,
161 const CScraperUrl& url,
162 XFILE::CCurlFile& http,
163 const std::vector<std::string>* extras = NULL);
164 std::string InternalRun(const std::string& function,
165 const CScraperUrl& url,
166 XFILE::CCurlFile& http,
167 const std::vector<std::string>* extras);
168
169 bool m_fLoaded;
170 std::string m_language;
171 bool m_requiressettings;
172 CDateTimeSpan m_persistence;
173 CONTENT_TYPE m_pathContent;
174 CScraperParser m_parser;
175};
176
177}
178