aboutsummaryrefslogtreecommitdiff
path: root/plugins/NyaaSi.hpp
blob: 103fea7f293728f30ffca74e8f75ba7ad718b260 (plain)
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
#pragma once

#include "Page.hpp"

namespace QuickMedia {
    void get_nyaa_si_categories(BodyItems &result_items);
    void get_sukebei_categories(BodyItems &result_items);

    class NyaaSiCategoryPage : public Page {
    public:
        NyaaSiCategoryPage(Program *program, bool is_sukebei) : Page(program), is_sukebei(is_sukebei) {}
        const char* get_title() const override { return is_sukebei ? "Select sukebei category" : "Select nyaa.si category"; }
        PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;

        const bool is_sukebei;
    };

    enum class NyaaSiSortType {
        SIZE_DESC,
        UPLOAD_DATE_DESC,
        SEEDERS_DESC,
        LEECHERS_DESC,
        DOWNLOADS_DESC,

        SIZE_ASC,
        UPLOAD_DATE_ASC,
        SEEDERS_ASC,
        LEECHERS_ASC,
        DOWNLOADS_ASC
    };

    class NyaaSiSearchPage : public Page, public TrackablePage {
    public:
        NyaaSiSearchPage(Program *program, std::string category_name, std::string category_id, std::string domain);
        const char* get_title() const override { return title.c_str(); }
        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 SubmitArgs &args, std::vector<Tab> &result_tabs) override;

        TrackResult track(const std::string &str) override;
        bool is_trackable() const override { return true; }

        void set_sort_type(NyaaSiSortType sort_type);

        const std::string category_name;
        const std::string category_id;
        const std::string domain;
    private:
        NyaaSiSortType sort_type = NyaaSiSortType::UPLOAD_DATE_DESC;
        std::string title;
    };

    class NyaaSiSortOrderPage : public Page {
    public:
        NyaaSiSortOrderPage(Program *program, Body *body, NyaaSiSearchPage *search_page) : Page(program), body(body), search_page(search_page) {}
        const char* get_title() const override { return "Sort order"; }
        PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
        bool submit_is_async() const override { return false; }
    private:
        Body *body;
        NyaaSiSearchPage *search_page;
    };

    class NyaaSiTorrentPage : public Page, public TrackablePage {
    public:
        NyaaSiTorrentPage(Program *program, std::string title) : Page(program), TrackablePage(std::move(title), "") {}
        const char* get_title() const override { return content_title.c_str(); }
        PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
        bool submit_is_async() const override { return false; }

        TrackResult track(const std::string &str) override;
        bool is_trackable() const override { return true; }
    };
}