From 9b0c5473222010c5de405713fdbdad258cc268f3 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Thu, 4 May 2023 18:34:46 -0700 Subject: changes to ytdlp wrapper fix video to and from json for lists of formats --- src/YtdlpWrapper.cpp | 14 +++++++++----- src/YtdlpWrapper.hpp | 6 ++---- src/main.cpp | 11 ++++++----- src/video.hpp | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src') 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 YtdlpWrapper::searchVideos(const std::string& searchTerm, int limit) { + pybind11::scoped_interpreter guard{}; std::vector resp; json info = json::parse(pyDictToJsonString( @@ -49,6 +52,7 @@ std::vector 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 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& 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& v); + void from_json(const nlohmann::json& j, std::vector& v); void from_json(const nlohmann::json& j, thumbnail& t); - void from_json(const nlohmann::json& j, const std::vector& v); + void from_json(const nlohmann::json& j, std::vector& v); void from_json(const nlohmann::json& j, video& v); }; #endif \ No newline at end of file -- cgit 1.4.1-2-gfad0 n15' href='#n15'>15 16 1
# Hello World

The classical introductory exercise. Just say "Hello, World!".

["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.

The objectives are simple:

- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.


## Exception messages

Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
a message.

To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
`raise Exception`, you should write:

```python
raise Exception("Meaningful message indicating the source of the error")
```

## Running the tests

To run the tests, run `pytest hello_world_test.py`

Alternatively, you can tell Python to run the pytest module:
`python -m pytest hello_world_test.py`

### Common `pytest` options

- `-v` : enable verbose output
- `-x` : stop running tests on first failure
- `--ff` : run failures from previous test before running other test cases

For other options, see `python -m pytest -h`

## Submitting Exercises

Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/hello-world` directory.

You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`.

For more detailed information about running tests, code style and linting,
please see [Running the Tests](http://exercism.io/tracks/python/tests).

## Source

This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.