diff options
-rw-r--r-- | src/YtdlpWrapper.cpp | 26 | ||||
-rw-r--r-- | src/main.cpp | 22 |
2 files changed, 24 insertions, 24 deletions
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp index a1e417f..424c6a4 100644 --- a/src/YtdlpWrapper.cpp +++ b/src/YtdlpWrapper.cpp @@ -41,7 +41,7 @@ void Video::to_json(json& j, const video& v) { j = json{{"id", v.id}, {"title", v.title}, - {"url", v.url}, + {"webpage_url", v.url}, {"channel_id", v.channelId}, {"channel_url", v.channelUrl}}; @@ -75,10 +75,10 @@ void Video::from_json(const json& j, format& f) { j.at("acodec").get_to(f.acodec); j.at("ext").get_to(f.ext); - if (j.contains("quality")) { f.quality = j.at("quality"); } - if (j.contains("resolution")) { f.resolution = j.at("resolution"); } - if (j.contains("width")) { f.width = j.at("width"); } - if (j.contains("height")) { f.height = j.at("height"); } + if (j.contains("quality") && j.at("quality").is_string()) { f.quality = j.at("quality"); } + if (j.contains("resolution") && j.at("resolution").is_string()) { f.resolution = j.at("resolution"); } + if (j.contains("width") && j.at("width").is_number()) { f.width = j.at("width"); } + if (j.contains("height") && j.at("height").is_number()) { f.height = j.at("height"); } } void Video::from_json(const json& j, thumbnail& t) { @@ -87,18 +87,18 @@ void Video::from_json(const json& j, thumbnail& t) { j.at("preference").get_to(t.preference); j.at("id").get_to(t.id); - if (j.contains("resolution")) { t.resolution = j.at("resolution"); } - if (j.contains("width")) { t.width = j.at("width"); } - if (j.contains("height")) { t.height = j.at("height"); } + if (j.contains("resolution") && j.at("resolution").is_string()) { t.resolution = j.at("resolution"); } + if (j.contains("width") && j.at("width").is_number()) { t.width = j.at("width"); } + if (j.contains("height") && j.at("height").is_number()) { t.height = j.at("height"); } } void Video::from_json(const json& j, video& v) { j.at("id").get_to(v.id); j.at("title").get_to(v.title); - j.at("url").get_to(v.url); - j.at("channelId").get_to(v.channelId); - j.at("channelUrl").get_to(v.channelUrl); + j.at("webpage_url").get_to(v.url); + j.at("channel_id").get_to(v.channelId); + j.at("channel_url").get_to(v.channelUrl); if (j.contains("uploader")) { v.uploader = j.at("uploader"); } if (j.contains("uploader_id")) { v.uploaderId = j.at("uploader_id"); } @@ -110,14 +110,14 @@ void Video::from_json(const json& j, video& v) { for (json f: j.at("formats")) { format form; - from_json(j, form); + from_json(f, form); v.formats.push_back(form); } for (json t: j.at("thumbnails")) { thumbnail thumb; - from_json(j, thumb); + from_json(t, thumb); v.thumbnails.push_back(thumb); } } diff --git a/src/main.cpp b/src/main.cpp index 059657c..69309c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ // #include <exception> // #include <vector> #include <fstream> +#include <filesystem> #include "tui.hpp" #include "invapi.hpp" @@ -17,21 +18,20 @@ // namespace py = pybind11; using namespace std; using json = nlohmann::json; +namespace fs = std::filesystem; void validateStructConversions() { + fs::path here("raycharles.json"); + cout << fs::absolute(here) << endl; - std::ifstream inputFile{"./raycharles.json"}; - auto size = inputFile.tellg(); - cout << size << endl; - std::string str(size, '\0'); // construct string to stream size - inputFile.seekg(0); - if(inputFile.read(&str[0], size)) - std::cout << str << '\n'; + ifstream ifs; + ifs.open(fs::absolute(here).c_str(), ifstream::in); - // json info = json::parse(inputFile); - // Video::video v = info["entries"].get<Video::video>(); - // json j = v; - // cout << j << endl; + json info = json::parse(ifs); + + Video::video v = info["entries"][0].get<Video::video>(); + json j = v; + cout << j << endl; } int main(int argc, char **argv) { |