1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#pragma once
#include "Page.hpp"
#include <functional>
namespace QuickMedia {
struct MediaSearchQuery {
const char *search_template = nullptr;
int page_start = 0;
};
// If |url_contains| is null, then any matching query is added. If |title_field| is "text", then the inner text is used.
// If |url_field| is null, then the current page is used instead.
struct MediaTextQuery {
const char *html_query = nullptr;
const char *title_field = nullptr;
const char *url_field = nullptr;
const char *url_contains = nullptr;
};
struct MediaThumbnailQuery {
const char *html_query = nullptr;
const char *field_name = nullptr;
const char *field_contains = nullptr;
};
struct MediaRelatedItem {
std::string title;
std::string url;
std::string thumbnail_url;
};
using MediaRelatedCustomHandler = std::function<std::vector<MediaRelatedItem>(const std::string &html_source)>;
class MediaGenericSearchPage : public Page {
public:
MediaGenericSearchPage(Program *program, const char *website_url, sf::Vector2i thumbnail_max_size);
const char* get_title() const override { return "Search"; }
bool search_is_filter() override { return false; }
SearchResult search(const std::string &str, BodyItems &result_items) override;
PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
sf::Vector2i get_thumbnail_max_size() override { return thumbnail_max_size; };
PluginResult get_related_media(const std::string &url, BodyItems &result_items);
// Add a %s where the search query should be inserted into |search_template| and add a %p where the page number should be inserted, for example:
// example.com/search?q=%s&page=%p
// This is required.
MediaGenericSearchPage& search_handler(const char *search_template, int page_start);
// This is required.
MediaGenericSearchPage& text_handler(std::vector<MediaTextQuery> queries);
// This is optional.
MediaGenericSearchPage& thumbnail_handler(std::vector<MediaThumbnailQuery> queries);
// This is optional.
MediaGenericSearchPage& related_media_text_handler(std::vector<MediaTextQuery> queries);
// This is optional.
MediaGenericSearchPage& related_media_thumbnail_handler(std::vector<MediaThumbnailQuery> queries);
// This is optional.
MediaGenericSearchPage& related_media_custom_handler(MediaRelatedCustomHandler handler);
private:
std::string website_url;
sf::Vector2i thumbnail_max_size;
MediaSearchQuery search_query;
std::vector<MediaTextQuery> text_queries;
std::vector<MediaThumbnailQuery> thumbnail_queries;
std::vector<MediaTextQuery> related_media_text_queries;
std::vector<MediaThumbnailQuery> related_media_thumbnail_queries;
MediaRelatedCustomHandler related_custom_handler = nullptr;
};
class MediaGenericRelatedPage : public RelatedVideosPage {
public:
MediaGenericRelatedPage(Program *program, MediaGenericSearchPage *search_page) : RelatedVideosPage(program), search_page(search_page) {}
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
private:
MediaGenericSearchPage *search_page;
};
class MediaGenericVideoPage : public VideoPage {
public:
MediaGenericVideoPage(Program *program, MediaGenericSearchPage *search_page, const std::string &url) : VideoPage(program), search_page(search_page), url(url) {}
const char* get_title() const override { return ""; }
BodyItems get_related_media(const std::string &url, std::string &channel_url) override;
std::unique_ptr<Page> create_search_page(Program *program, int &search_delay) override;
std::unique_ptr<RelatedVideosPage> create_related_videos_page(Program *program, const std::string &video_url, const std::string &video_title) override;
std::unique_ptr<Page> create_channels_page(Program*, const std::string&) override {
return nullptr;
}
std::string get_url() override { return url; }
private:
MediaGenericSearchPage *search_page;
std::string url;
};
}
|