xbmc
ScraperUrl.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 #include <map>
12 #include <string>
13 #include <vector>
14 
15 class TiXmlElement;
16 namespace XFILE
17 {
18 class CCurlFile;
19 }
20 
22 {
23 public:
24  enum class UrlType
25  {
26  General = 1,
27  Season = 2
28  };
29 
30  struct SUrlEntry
31  {
32  explicit SUrlEntry(std::string url = "")
33  : m_url(std::move(url)), m_type(UrlType::General), m_post(false), m_isgz(false), m_season(-1)
34  {
35  }
36 
37  std::string m_spoof;
38  std::string m_url;
39  std::string m_cache;
40  std::string m_aspect;
41  std::string m_preview;
42  UrlType m_type;
43  bool m_post;
44  bool m_isgz;
45  int m_season;
46  };
47 
48  CScraperUrl();
49  explicit CScraperUrl(const std::string& strUrl);
50  explicit CScraperUrl(const TiXmlElement* element);
51  ~CScraperUrl();
52 
53  void Clear();
54 
55  bool HasData() const { return !m_data.empty(); }
56  const std::string& GetData() const { return m_data; }
57  void SetData(std::string data);
58 
59  const std::string& GetTitle() const { return m_title; }
60  void SetTitle(std::string title) { m_title = std::move(title); }
61 
62  const std::string& GetId() const { return m_id; }
63  void SetId(std::string id) { m_id = std::move(id); }
64 
65  double GetRelevance() const { return m_relevance; }
66  void SetRelevance(double relevance) { m_relevance = relevance; }
67 
68  bool HasUrls() const { return !m_urls.empty(); }
69  const std::vector<SUrlEntry>& GetUrls() const { return m_urls; }
70  void SetUrls(std::vector<SUrlEntry> urls) { m_urls = std::move(urls); }
71  void AppendUrl(SUrlEntry url) { m_urls.push_back(std::move(url)); }
72 
73  const SUrlEntry GetFirstUrlByType(const std::string& type = "") const;
74  const SUrlEntry GetSeasonUrl(int season, const std::string& type = "") const;
75  unsigned int GetMaxSeasonUrl() const;
76 
77  std::string GetFirstThumbUrl() const;
78 
85  void GetThumbUrls(std::vector<std::string>& thumbs,
86  const std::string& type = "",
87  int season = -1,
88  bool unique = false) const;
89 
90  bool Parse();
91  bool ParseFromData(const std::string& data); // copies by intention
92  bool ParseAndAppendUrl(const TiXmlElement* element);
93  bool ParseAndAppendUrlsFromEpisodeGuide(const std::string& episodeGuide); // copies by intention
94  void AddParsedUrl(const std::string& url,
95  const std::string& aspect = "",
96  const std::string& preview = "",
97  const std::string& referrer = "",
98  const std::string& cache = "",
99  bool post = false,
100  bool isgz = false,
101  int season = -1);
102 
107  static std::string GetThumbUrl(const CScraperUrl::SUrlEntry& entry);
108 
109  static bool Get(const SUrlEntry& scrURL,
110  std::string& strHTML,
111  XFILE::CCurlFile& http,
112  const std::string& cacheContext);
113 
114  // ATTENTION: this member MUST NOT be used directly except from databases
115  std::string m_data;
116 
117 private:
118  std::string m_title;
119  std::string m_id;
120  double m_relevance;
121  std::vector<SUrlEntry> m_urls;
122  bool m_parsed;
123 };
Definition: Scraper.h:41
Definition: ScraperUrl.h:30
Definition: CurlFile.h:24
Definition: ScraperUrl.h:21
Definition: cache.py:1