summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/ScraperUrl.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/utils/ScraperUrl.h')
-rw-r--r--xbmc/utils/ScraperUrl.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/xbmc/utils/ScraperUrl.h b/xbmc/utils/ScraperUrl.h
new file mode 100644
index 0000000..f6c13ba
--- /dev/null
+++ b/xbmc/utils/ScraperUrl.h
@@ -0,0 +1,122 @@
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
15class TiXmlElement;
16namespace XFILE
17{
18class CCurlFile;
19}
20
21class CScraperUrl
22{
23public:
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 UrlType m_type;
42 bool m_post;
43 bool m_isgz;
44 int m_season;
45 };
46
47 CScraperUrl();
48 explicit CScraperUrl(std::string strUrl);
49 explicit CScraperUrl(const TiXmlElement* element);
50 ~CScraperUrl();
51
52 void Clear();
53
54 bool HasData() const { return !m_data.empty(); }
55 const std::string& GetData() const { return m_data; }
56 void SetData(std::string data);
57
58 const std::string& GetTitle() const { return m_title; }
59 void SetTitle(std::string title) { m_title = std::move(title); }
60
61 const std::string& GetId() const { return m_id; }
62 void SetId(std::string id) { m_id = std::move(id); }
63
64 double GetRelevance() const { return m_relevance; }
65 void SetRelevance(double relevance) { m_relevance = relevance; }
66
67 bool HasUrls() const { return !m_urls.empty(); }
68 const std::vector<SUrlEntry>& GetUrls() const { return m_urls; }
69 void SetUrls(std::vector<SUrlEntry> urls) { m_urls = std::move(urls); }
70 void AppendUrl(SUrlEntry url) { m_urls.push_back(std::move(url)); }
71
72 const SUrlEntry GetFirstUrlByType(const std::string& type = "") const;
73 const SUrlEntry GetSeasonUrl(int season, const std::string& type = "") const;
74 unsigned int GetMaxSeasonUrl() const;
75
76 std::string GetFirstThumbUrl() const;
77
78 /*! \brief fetch the full URLs (including referrer) of thumbs
79 \param thumbs [out] vector of thumb URLs to fill
80 \param type the type of thumb URLs to fetch, if empty (the default) picks any
81 \param season number of season that we want thumbs for, -1 indicates no season (the default)
82 \param unique avoid adding duplicate URLs when adding to a thumbs vector with existing items
83 */
84 void GetThumbUrls(std::vector<std::string>& thumbs,
85 const std::string& type = "",
86 int season = -1,
87 bool unique = false) const;
88
89 bool Parse();
90 bool ParseFromData(std::string data); // copies by intention
91 bool ParseAndAppendUrl(const TiXmlElement* element);
92 bool ParseAndAppendUrlsFromEpisodeGuide(std::string episodeGuide); // copies by intention
93 void AddParsedUrl(std::string url,
94 std::string aspect = "",
95 std::string preview = "",
96 std::string referrer = "",
97 std::string cache = "",
98 bool post = false,
99 bool isgz = false,
100 int season = -1);
101
102 /*! \brief fetch the full URL (including referrer) of a thumb
103 \param URL entry to use to create the full URL
104 \return the full URL, including referrer
105 */
106 static std::string GetThumbUrl(const CScraperUrl::SUrlEntry& entry);
107
108 static bool Get(const SUrlEntry& scrURL,
109 std::string& strHTML,
110 XFILE::CCurlFile& http,
111 const std::string& cacheContext);
112
113 // ATTENTION: this member MUST NOT be used directly except from databases
114 std::string m_data;
115
116private:
117 std::string m_title;
118 std::string m_id;
119 double m_relevance;
120 std::vector<SUrlEntry> m_urls;
121 bool m_parsed;
122};