about summary refs log tree commit diff stats
path: root/src/YtdlpWrapper.hpp
blob: 39cf4df22b9fe075432fe3170992a287127bae57 (plain) (blame)
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
#ifndef YTDLPWRAPPER_H
#define YTDLPWRAPPER_H
#include <string>
#include <pybind11/embed.h>
#include <nlohmann/json.hpp>

namespace Video {

    struct format {
    
        std::string format;
        std::string url;
        std::string vcodec;
        std::string acodec;
        std::string ext;
        std::optional<float> quality;
        std::optional<std::string> resolution;
        std::optional<int> height;
        std::optional<int> width;
    };

    struct thumbnail {

        std::string url;
        int preference;
        std::string id;
        std::optional<std::string> resolution;
        std::optional<int> height;
        std::optional<int> width;
    };

    struct video {

        std::string id;
        std::string title;
        std::string url;
        std::string channelId;
        std::string channelUrl;
        std::vector<format> formats;
        std::vector<thumbnail> thumbnails;
        std::optional<std::string> uploader;
        std::optional<std::string> uploaderId;
        std::optional<std::string> uploaderUrl;
        std::optional<int> duration;
        std::optional<int> viewcount;
        std::optional<std::string> description;
    };

    void to_json(nlohmann::json& j, const format& f);
    void to_json(nlohmann::json& j, const thumbnail& t);
    void to_json(nlohmann::json& j, const video& v);
    void from_json(const nlohmann::json& j, format& f);
    void from_json(const nlohmann::json& j, thumbnail& t);
    void from_json(const nlohmann::json& j, video& v);
};

class YtdlpWrapper {

    public:
        nlohmann::json getJsonSearch(const std::string& searchTerm, int limit = 1);
        Video::video getVideoByUrl(const std::string& url);
        std::vector<Video::video> searchVideos(const std::string& searchterm, int limit = 1);
    private:
        pybind11::object get_ytdl();
        pybind11::object ytdl = pybind11::none();
        pybind11::scoped_interpreter guard{};
};


#endif