aboutsummaryrefslogtreecommitdiff
path: root/src/Json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Json.cpp')
-rw-r--r--src/Json.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Json.cpp b/src/Json.cpp
new file mode 100644
index 0000000..86703b2
--- /dev/null
+++ b/src/Json.cpp
@@ -0,0 +1,21 @@
+#include "../include/Json.hpp"
+
+namespace QuickMedia {
+ static rapidjson::Value nullValue(rapidjson::kNullType);
+ const rapidjson::Value& GetMember(const rapidjson::Value &obj, const char *key) {
+ auto it = obj.FindMember(key);
+ if(it != obj.MemberEnd())
+ return it->value;
+ return nullValue;
+ }
+
+ DownloadResult download_json(rapidjson::Document &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_tor, bool use_browser_useragent, std::string *err_msg) {
+ if(download_to_json(url, result, std::move(additional_args), use_tor, use_browser_useragent, err_msg == nullptr) != DownloadResult::OK) {
+ // Cant get error since we parse directly to json. TODO: Make this work somehow?
+ if(err_msg)
+ *err_msg = "Failed to download/parse json";
+ return DownloadResult::NET_ERR;
+ }
+ return DownloadResult::OK;
+ }
+} \ No newline at end of file