about summary refs log tree commit diff stats
path: root/src/YtdlpWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/YtdlpWrapper.cpp')
-rw-r--r--src/YtdlpWrapper.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp
index 5a18ab2..cabe473 100644
--- a/src/YtdlpWrapper.cpp
+++ b/src/YtdlpWrapper.cpp
@@ -12,16 +12,18 @@ std::string pyDictToJsonString(const py::dict& dict) {
 }
 
 py::object YtdlpWrapper::get_ytdl() {
-    
-    if (ytdl.is_none()) {
-        ytdl = py::module::import("yt_dlp");
-    }
 
-    return ytdl;
+    // pybind11::object ytdl = pybind11::none();     
+    // if (ytdl.is_none()) {
+    //     ytdl = py::module::import("yt_dlp");
+    // }
+
+    return py::module::import("yt_dlp");
 }
 
 json YtdlpWrapper::getJsonSearch(const std::string& searchTerm, int limit) {
 
+    pybind11::scoped_interpreter guard{};
     py::dict info = get_ytdl()
         .attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true)))
         .attr("extract_info")("ytsearch"+std::to_string(limit)+":"+searchTerm, "download"_a=py::bool_(false));
@@ -30,6 +32,7 @@ json YtdlpWrapper::getJsonSearch(const std::string& searchTerm, int limit) {
 
 std::vector<Video::video> YtdlpWrapper::searchVideos(const std::string& searchTerm, int limit) {
 
+    pybind11::scoped_interpreter guard{};
     std::vector<Video::video> resp;
 
     json info = json::parse(pyDictToJsonString(
@@ -49,6 +52,7 @@ std::vector<Video::video> YtdlpWrapper::searchVideos(const std::string& searchTe
 
 Video::video YtdlpWrapper::getVideoByUrl(const std::string& url) {
 
+    pybind11::scoped_interpreter guard{};
     json info = json::parse(pyDictToJsonString(
         get_ytdl().attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true), "noplaylist"_a=py::bool_(true)))
         .attr("extract_info")(url, "download"_a=py::bool_(false))
href='/akkartik/mu/blame/apps/texture.mu?h=hlt&id=e170b35d8b37901903318851803e3cab5e09cde0'>^
82d1fe7c ^


74f1512f ^

e170b35d ^
d7d384a7 ^

82d1fe7c ^

74f1512f ^

e170b35d ^





c8e41a47 ^
e170b35d ^
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