Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / xbmc / utils / ScraperUrl.h
blob0ecf6419094f8d9cfac7d6d0d04e0c4bbbfb53b7
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include <map>
12 #include <string>
13 #include <vector>
15 class TiXmlElement;
16 namespace XFILE
18 class CCurlFile;
21 class CScraperUrl
23 public:
24 enum class UrlType
26 General = 1,
27 Season = 2
30 struct SUrlEntry
32 explicit SUrlEntry(std::string url = "") : m_url(std::move(url)) {}
34 std::string m_spoof;
35 std::string m_url;
36 std::string m_cache;
37 std::string m_aspect;
38 std::string m_preview;
39 UrlType m_type = UrlType::General;
40 bool m_post = false;
41 bool m_isgz = false;
42 int m_season = -1;
45 CScraperUrl();
46 explicit CScraperUrl(const std::string& strUrl);
47 explicit CScraperUrl(const TiXmlElement* element);
48 ~CScraperUrl();
50 void Clear();
52 bool HasData() const { return !m_data.empty(); }
53 const std::string& GetData() const { return m_data; }
54 void SetData(std::string data);
56 const std::string& GetTitle() const { return m_title; }
57 void SetTitle(std::string title) { m_title = std::move(title); }
59 const std::string& GetId() const { return m_id; }
60 void SetId(std::string id) { m_id = std::move(id); }
62 double GetRelevance() const { return m_relevance; }
63 void SetRelevance(double relevance) { m_relevance = relevance; }
65 bool HasUrls() const { return !m_urls.empty(); }
66 const std::vector<SUrlEntry>& GetUrls() const { return m_urls; }
67 void SetUrls(std::vector<SUrlEntry> urls) { m_urls = std::move(urls); }
68 void AppendUrl(SUrlEntry url) { m_urls.push_back(std::move(url)); }
70 const SUrlEntry GetFirstUrlByType(const std::string& type = "") const;
71 const SUrlEntry GetSeasonUrl(int season, const std::string& type = "") const;
72 unsigned int GetMaxSeasonUrl() const;
74 std::string GetFirstThumbUrl() const;
76 /*! \brief fetch the full URLs (including referrer) of thumbs
77 \param thumbs [out] vector of thumb URLs to fill
78 \param type the type of thumb URLs to fetch, if empty (the default) picks any
79 \param season number of season that we want thumbs for, -1 indicates no season (the default)
80 \param unique avoid adding duplicate URLs when adding to a thumbs vector with existing items
82 void GetThumbUrls(std::vector<std::string>& thumbs,
83 const std::string& type = "",
84 int season = -1,
85 bool unique = false) const;
87 bool Parse();
88 bool ParseFromData(const std::string& data); // copies by intention
89 bool ParseAndAppendUrl(const TiXmlElement* element);
90 bool ParseAndAppendUrlsFromEpisodeGuide(const std::string& episodeGuide); // copies by intention
91 void AddParsedUrl(const std::string& url,
92 const std::string& aspect = "",
93 const std::string& preview = "",
94 const std::string& referrer = "",
95 const std::string& cache = "",
96 bool post = false,
97 bool isgz = false,
98 int season = -1);
100 /*! \brief fetch the full URL (including referrer) of a thumb
101 \param URL entry to use to create the full URL
102 \return the full URL, including referrer
104 static std::string GetThumbUrl(const CScraperUrl::SUrlEntry& entry);
106 static bool Get(const SUrlEntry& scrURL,
107 std::string& strHTML,
108 XFILE::CCurlFile& http,
109 const std::string& cacheContext);
111 // ATTENTION: this member MUST NOT be used directly except from databases
112 std::string m_data;
114 private:
115 std::string m_title;
116 std::string m_id;
117 double m_relevance;
118 std::vector<SUrlEntry> m_urls;
119 bool m_parsed;