Fix keymap.
[vuplus_xbmc] / xbmc / addons / Scraper.h
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
27 class CAlbum;
28 class CArtist;
29 class CVideoInfoTag;
30
31 namespace MUSIC_GRABBER
32 {
33 class CMusicAlbumInfo;
34 class CMusicArtistInfo;
35 }
36
37 typedef enum
38 {
39   CONTENT_MOVIES,
40   CONTENT_TVSHOWS,
41   CONTENT_MUSICVIDEOS,
42   CONTENT_ALBUMS,
43   CONTENT_ARTISTS,
44   CONTENT_NONE,
45 } CONTENT_TYPE;
46
47 namespace XFILE
48 {
49   class CCurlFile;
50 }
51
52 class CScraperUrl;
53
54 namespace ADDON
55 {
56 class CScraper;
57 typedef boost::shared_ptr<CScraper> ScraperPtr;
58
59 CStdString TranslateContent(const CONTENT_TYPE &content, bool pretty=false);
60 CONTENT_TYPE TranslateContent(const CStdString &string);
61 TYPE ScraperTypeFromContent(const CONTENT_TYPE &content);
62
63 // thrown as exception to signal abort or show error dialog
64 class CScraperError
65 {
66 public:
67   CScraperError() : m_fAborted(true) {}
68   CScraperError(const CStdString &sTitle, const CStdString &sMessage) :
69     m_fAborted(false), m_sTitle(sTitle), m_sMessage(sMessage) {}
70
71   bool FAborted() const { return m_fAborted; }
72   const CStdString &Title() const { return m_sTitle; }
73   const CStdString &Message() const { return m_sMessage; }
74
75 private:
76   bool m_fAborted;
77   CStdString m_sTitle;
78   CStdString m_sMessage;
79 };
80
81 class CScraper : public CAddon
82 {
83 public:
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 CStdString& 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   CStdString 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 CStdString& 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 CStdString &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 CStdString &externalID);
134
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);
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 CStdString &sSearch, CArtist &artist);
149
150 private:
151   CScraper(const CScraper &rhs);
152   CStdString SearchStringEncoding() const
153     { return m_parser.GetSearchStringEncoding(); }
154
155   bool Load();
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);
168
169   bool m_fLoaded;
170   CStdString m_language;
171   bool m_requiressettings;
172   CDateTimeSpan m_persistence;
173   CONTENT_TYPE m_pathContent;
174   CScraperParser m_parser;
175 };
176
177 }
178