-
Notifications
You must be signed in to change notification settings - Fork 23
/
python-streamlink.h
125 lines (98 loc) · 3.02 KB
/
python-streamlink.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include <corecrt.h>
#define PY_SSIZE_T_CLEAN
#ifdef _DEBUG
#define STREAMLINK_DEBUG
#endif
#undef _DEBUG // NOLINT(clang-diagnostic-reserved-macro-identifier)
//#ifdef STREAMLINK_DEBUG // requires debugging version of Python
//#define Py_REF_DEBUG
//#endif
#include <Python.h>
#ifdef STREAMLINK_DEBUG
#define _DEBUG
#endif
#include <string>
#include <functional>
#include <map>
namespace streamlink {
extern bool loaded;
extern bool loadingFailed;
extern PyObject* module;
namespace methods
{
extern PyObject* new_session;
}
class ThreadGIL {
PyGILState_STATE state;
public:
ThreadGIL();
~ThreadGIL();
ThreadGIL(ThreadGIL& another) = delete;
ThreadGIL(ThreadGIL&& another) = default;
ThreadGIL& operator=(ThreadGIL& another) = delete;
ThreadGIL& operator=(ThreadGIL&& another) = default;
};
std::string PyStringToString(PyObject* pyStr);
std::string GetExceptionInfo();
void LogFailure();
void Initialize();
class PyObjectHolder
{
public:
PyObject* underlying;
PyObjectHolder() : PyObjectHolder(nullptr, false) {}
PyObjectHolder(PyObject* underlying, bool inc = true);
virtual ~PyObjectHolder();
PyObjectHolder(PyObjectHolder&& another)noexcept;
PyObjectHolder& operator=(PyObjectHolder&& another) noexcept;
};
class not_loaded : public std::exception {};
class call_failure : public std::exception
{
public:
call_failure() = default;
explicit call_failure(char const* message)
: exception(message)
{ }
call_failure(char const* message, int i)
: exception(message, i)
{ }
explicit call_failure(exception const& other)
: exception(other)
{ }
};
class invalid_underlying_object : public std::exception {};
class stream_ended : public std::exception {};
class Stream : public PyObjectHolder
{
public:
Stream(PyObject* u);
Stream(Stream&) = delete;
Stream(Stream&& another) noexcept;
int Read(unsigned char* buf, const int len);
void Close();
};
class StreamInfo : public PyObjectHolder
{
public:
std::string name;
StreamInfo(std::string name, PyObject* u);
StreamInfo(StreamInfo&& another) noexcept;
PyObject* Open();
};
class Session : public PyObjectHolder {
private:
PyObject* set_option;
PyObjectHolder set_optionGuard;
public:
Session();
~Session() override;
std::map<std::string, StreamInfo> GetStreamsFromUrl(std::string const& url);
void SetOption(std::string const& name, PyObject* value);
void SetOptionString(std::string const& name, std::string const& value);
void SetOptionDouble(std::string const& name, double value);
void SetOptionInt(std::string const& name, long long value);
void SetOptionBool(std::string const& name, bool value);
};
}