3 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
21 #include "addons/Addon.h"
22 #include "XBDateTime.h"
23 #include "utils/ScraperUrl.h"
24 #include "utils/ScraperParser.h"
25 #include "video/Episode.h"
31 namespace MUSIC_GRABBER
33 class CMusicAlbumInfo;
34 class CMusicArtistInfo;
57 typedef boost::shared_ptr<CScraper> ScraperPtr;
59 CStdString TranslateContent(const CONTENT_TYPE &content, bool pretty=false);
60 CONTENT_TYPE TranslateContent(const CStdString &string);
61 TYPE ScraperTypeFromContent(const CONTENT_TYPE &content);
63 // thrown as exception to signal abort or show error dialog
67 CScraperError() : m_fAborted(true) {}
68 CScraperError(const CStdString &sTitle, const CStdString &sMessage) :
69 m_fAborted(false), m_sTitle(sTitle), m_sMessage(sMessage) {}
71 bool FAborted() const { return m_fAborted; }
72 const CStdString &Title() const { return m_sTitle; }
73 const CStdString &Message() const { return m_sMessage; }
78 CStdString m_sMessage;
81 class CScraper : public CAddon
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;
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
97 bool SetPathSettings(CONTENT_TYPE content, const CStdString& xml);
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
105 CStdString GetPathSettings();
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
113 CONTENT_TYPE Content() const { return m_pathContent; }
114 const CStdString& Language() const { return m_language; }
115 bool RequiresSettings() const { return m_requiressettings; }
116 bool Supports(const CONTENT_TYPE &content) const;
118 bool IsInUse() const;
121 // scraper media functions
122 CScraperUrl NfoUrl(const CStdString &sNfoContent);
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.
133 CScraperUrl ResolveIDToUrl(const CStdString &externalID);
135 std::vector<CScraperUrl> FindMovie(XFILE::CCurlFile &fcurl,
136 const CStdString &sMovie, bool fFirst);
137 std::vector<MUSIC_GRABBER::CMusicAlbumInfo> FindAlbum(XFILE::CCurlFile &fcurl,
138 const CStdString &sAlbum, const CStdString &sArtist = "");
139 std::vector<MUSIC_GRABBER::CMusicArtistInfo> FindArtist(
140 XFILE::CCurlFile &fcurl, const CStdString &sArtist);
141 VIDEO::EPISODELIST GetEpisodeList(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl);
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,
147 bool GetArtistDetails(XFILE::CCurlFile &fcurl, const CScraperUrl &scurl,
148 const CStdString &sSearch, CArtist &artist);
151 CScraper(const CScraper &rhs);
152 CStdString SearchStringEncoding() const
153 { return m_parser.GetSearchStringEncoding(); }
156 std::vector<CStdString> Run(const CStdString& function,
157 const CScraperUrl& url,
158 XFILE::CCurlFile& http,
159 const std::vector<CStdString>* extras = NULL);
160 std::vector<CStdString> RunNoThrow(const CStdString& function,
161 const CScraperUrl& url,
162 XFILE::CCurlFile& http,
163 const std::vector<CStdString>* extras = NULL);
164 CStdString InternalRun(const CStdString& function,
165 const CScraperUrl& url,
166 XFILE::CCurlFile& http,
167 const std::vector<CStdString>* extras);
170 CStdString m_language;
171 bool m_requiressettings;
172 CDateTimeSpan m_persistence;
173 CONTENT_TYPE m_pathContent;
174 CScraperParser m_parser;