kodi
NfoFile.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 // NfoFile.h: interface for the CNfoFile class.
12 //
14 
15 #include "InfoScanner.h"
16 #include "addons/Scraper.h"
17 #include "utils/XBMCTinyXML.h"
18 
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 namespace ADDON
24 {
25 enum class AddonType;
26 }
27 
28 class CNfoFile
29 {
30 public:
31  virtual ~CNfoFile() { Close(); }
32 
33  CInfoScanner::INFO_TYPE Create(const std::string&,
34  const ADDON::ScraperPtr&, int episode=-1);
35  template<class T>
36  bool GetDetails(T& details, const char* document=NULL,
37  bool prioritise=false)
38  {
39  CXBMCTinyXML doc;
40  if (document)
41  doc.Parse(document, TIXML_ENCODING_UNKNOWN);
42  else if (m_headPos < m_doc.size())
43  doc.Parse(m_doc.substr(m_headPos), TIXML_ENCODING_UNKNOWN);
44  else
45  return false;
46 
47  return details.Load(doc.RootElement(), true, prioritise);
48  }
49 
50  void Close();
51  void SetScraperInfo(ADDON::ScraperPtr info) { m_info = std::move(info); }
52  ADDON::ScraperPtr GetScraperInfo() { return m_info; }
53  const CScraperUrl &ScraperUrl() const { return m_scurl; }
54 
55  static int Scrape(ADDON::ScraperPtr& scraper, CScraperUrl& url,
56  const std::string& content);
57 
58  static std::vector<ADDON::ScraperPtr> GetScrapers(ADDON::AddonType type,
59  const ADDON::ScraperPtr& selectedScraper);
60 
61 private:
62  std::string m_doc;
63  size_t m_headPos = 0;
64  ADDON::ScraperPtr m_info;
65  ADDON::AddonType m_type{};
66  CScraperUrl m_scurl;
67 
68  int Load(const std::string&);
69 };
Definition: XBMCTinyXML.h:33
Definition: scraper.py:1
Definition: NfoFile.h:28
Definition: Addon.cpp:39
Definition: ScraperUrl.h:21
INFO_TYPE
Definition: InfoScanner.h:37