diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-05-04 18:34:46 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-05-04 18:34:46 -0700 |
commit | 9b0c5473222010c5de405713fdbdad258cc268f3 (patch) | |
tree | 7dceb2a0c45f04a6a24aba4a65b297b78ce7703f | |
parent | a58e7083712a14f3e644b8d3badf4254191199fa (diff) | |
download | ytcpp-9b0c5473222010c5de405713fdbdad258cc268f3.tar.gz |
changes to ytdlp wrapper
fix video to and from json for lists of formats
-rw-r--r-- | src/YtdlpWrapper.cpp | 14 | ||||
-rw-r--r-- | src/YtdlpWrapper.hpp | 6 | ||||
-rw-r--r-- | src/main.cpp | 11 | ||||
-rw-r--r-- | src/video.hpp | 4 |
4 files changed, 19 insertions, 16 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)) diff --git a/src/YtdlpWrapper.hpp b/src/YtdlpWrapper.hpp index 81857c9..9ee2410 100644 --- a/src/YtdlpWrapper.hpp +++ b/src/YtdlpWrapper.hpp @@ -13,10 +13,8 @@ class YtdlpWrapper { 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{}; -}; + pybind11::object get_ytdl(); +}; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 100d2b5..6f3ce18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,7 +65,7 @@ int main(int argc, char **argv) { parseSysArgs(argc, argv); - // validateStructConversions(); + validateStructConversions(); // YtdlpWrapper yt; // Video::video vid = yt.getVideoByUrl("https://youtu.be/jy5x7bDYd4o?list=OLAK5uy_kSLxuOA_vBO8SsXaI6PjJbqvsIBnBReGM"); @@ -89,9 +89,10 @@ int main(int argc, char **argv) { // } // cout << endl; - // string searchTerm; - // int searchingFor{-1}; + string searchTerm; + int searchingFor{-1}; - // Tui ux; - // ux.renderSearchBar(searchTerm, searchingFor); + Tui ux; + ux.renderSearchBar(searchTerm, searchingFor); + cout << searchTerm << searchingFor << endl; } \ No newline at end of file diff --git a/src/video.hpp b/src/video.hpp index 577606a..fd57d0b 100644 --- a/src/video.hpp +++ b/src/video.hpp @@ -53,9 +53,9 @@ namespace Video { void to_json(nlohmann::json& j, const std::vector<thumbnail>& v); 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, const std::vector<format>& v); + void from_json(const nlohmann::json& j, std::vector<format>& v); void from_json(const nlohmann::json& j, thumbnail& t); - void from_json(const nlohmann::json& j, const std::vector<thumbnail>& v); + void from_json(const nlohmann::json& j, std::vector<thumbnail>& v); void from_json(const nlohmann::json& j, video& v); }; #endif \ No newline at end of file |