Merge pull request #3819 from arnova/subtitles_for_stacks
[vuplus_xbmc] / xbmc / utils / ScraperParser.h
1 #ifndef SCRAPER_PARSER_H
2 #define SCRAPER_PARSER_H
3
4 /*
5  *      Copyright (C) 2012-2013 Team XBMC
6  *      http://xbmc.org
7  *
8  *  This Program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  This Program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with XBMC; see the file COPYING.  If not, see
20  *  <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include <vector>
25 #include "StdString.h"
26 #include "addons/IAddon.h"
27
28 #define MAX_SCRAPER_BUFFERS 20
29
30 namespace ADDON
31 {
32   class CScraper;
33 }
34
35 class TiXmlElement;
36 class CXBMCTinyXML;
37
38 class CScraperSettings;
39
40 class CScraperParser
41 {
42 public:
43   CScraperParser();
44   CScraperParser(const CScraperParser& parser);
45   ~CScraperParser();
46   CScraperParser& operator= (const CScraperParser& parser);
47   bool Load(const CStdString& strXMLFile);
48   bool IsNoop() { return m_isNoop; };
49
50   void Clear();
51   const CStdString GetFilename() { return m_strFile; }
52   CStdString GetSearchStringEncoding() const
53     { return m_SearchStringEncoding; }
54   const CStdString Parse(const CStdString& strTag,
55                          ADDON::CScraper* scraper);
56
57   void AddDocument(const CXBMCTinyXML* doc);
58
59   CStdString m_param[MAX_SCRAPER_BUFFERS];
60
61 private:
62   bool LoadFromXML();
63   void ReplaceBuffers(CStdString& strDest);
64   void ParseExpression(const CStdString& input, CStdString& dest, TiXmlElement* element, bool bAppend);
65
66   /*! \brief Parse an 'XSLT' declaration from the scraper
67    This allow us to transform an inbound XML document using XSLT
68    to a different type of XML document, ready to be output direct
69    to the album loaders or similar
70    \param input the input document
71    \param dest the output destation for the conversion
72    \param element the current XML element
73    \param bAppend append or clear the buffer
74    */
75   void ParseXSLT(const CStdString& input, CStdString& dest, TiXmlElement* element, bool bAppend);
76   void ParseNext(TiXmlElement* element);
77   void Clean(CStdString& strDirty);
78   void ConvertJSON(CStdString &string);
79   void ClearBuffers();
80   void GetBufferParams(bool* result, const char* attribute, bool defvalue);
81   void InsertToken(CStdString& strOutput, int buf, const char* token);
82
83   CXBMCTinyXML* m_document;
84   TiXmlElement* m_pRootElement;
85
86   const char* m_SearchStringEncoding;
87   bool m_isNoop;
88
89   CStdString m_strFile;
90   ADDON::CScraper* m_scraper;
91 };
92
93 #endif
94
95