about summary refs log tree commit diff stats
path: root/src/invapi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/invapi.cpp')
-rw-r--r--src/invapi.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/invapi.cpp b/src/invapi.cpp
index 59e91bf..f53c06b 100644
--- a/src/invapi.cpp
+++ b/src/invapi.cpp
@@ -22,7 +22,7 @@ vector<string> InvidiousApi::getInstances() {
 
     vector<string> result;
     cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, 
-        cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api"}},
+        cpr::Parameters{{"sort_by", "health"}},
         cpr::Timeout{5000});
 
     if (r.status_code > 299) {
@@ -44,7 +44,7 @@ vector<string> InvidiousApi::getInstances() {
 void InvidiousApi::saveInstancesToDb(SqliteInterface& sqldb) {
 
     cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, 
-        cpr::Parameters{{"sort_by", "health"}, {"fields", "uri,api,health,location"}}, 
+        cpr::Parameters{{"sort_by", "health"}}, 
         cpr::Timeout{5000});
 
     if (r.status_code > 299) {
@@ -55,9 +55,17 @@ void InvidiousApi::saveInstancesToDb(SqliteInterface& sqldb) {
 
     json j = json::parse(r.text);
     for ( json i: j ) {
-        if ( i.at(1).at("api") != json::value_t::null && i.at(1).at("api")) {
-
-            sqldb.saveInstance(i[1]["uri"], i[1]["health"], i[1]["location"]);
+        if ( i.at(1).at("api") != json::value_t::null && i.at(1).at("api") 
+            && i.at(1).at("monitor") != json::value_t::null
+            && i.at(1).at("monitor").at("30dRatio") != json::value_t::null
+            && i.at(1).at("monitor").at("30dRatio").at("ratio") != json::value_t::null
+            && i.at(1).at("uri") != json::value_t::null
+            && i.at(1).at("region") != json::value_t::null) {
+
+                string uri = i[1]["uri"];
+                string health = i[1]["monitor"]["30dRatio"]["ratio"];
+                string region = i[1]["region"];
+                sqldb.saveInstance(uri.c_str(), stof(health), region.c_str());
         }
     }    
 }