Jellyfin basic functions / user_ids processing

next step is to add the auth functions
main
Brett 2023-08-15 14:00:43 -04:00
parent 94036bcd3a
commit b6e4c3dd22
4 changed files with 72 additions and 8 deletions

View File

@ -5,4 +5,20 @@
#ifndef CROWSITE_JELLYFIN_H #ifndef CROWSITE_JELLYFIN_H
#define CROWSITE_JELLYFIN_H #define CROWSITE_JELLYFIN_H
#include <string_view>
namespace cs::jellyfin
{
void setToken(std::string_view token);
void processUserData();
std::string generateAuthHeader();
std::string getUserData();
bool hasUser(std::string_view username);
}
#endif //CROWSITE_JELLYFIN_H #endif //CROWSITE_JELLYFIN_H

View File

@ -17,8 +17,9 @@ namespace cs
auto* name = (const char*) userdata; auto* name = (const char*) userdata;
std::string site{name}; std::string site{name};
blt::scoped_buffer<char> response{size * nmemb}; blt::scoped_buffer<char> response{size * nmemb + 1};
memcpy(response.ptr(), ptr, size * nmemb); memcpy(response.ptr(), ptr, size * nmemb);
response[size * nmemb] = '\0';
if (responses.find(site) != responses.end()){ if (responses.find(site) != responses.end()){
std::string res{response.ptr()}; std::string res{response.ptr()};
@ -66,7 +67,6 @@ namespace cs
void request::get(const std::string& domain, const std::string& data) void request::get(const std::string& domain, const std::string& data)
{ {
BLT_WARN("Domain: %s", domain.c_str());
auto full = domain + data; auto full = domain + data;
curl_easy_setopt(handler, CURLOPT_URL, full.c_str()); curl_easy_setopt(handler, CURLOPT_URL, full.c_str());
curl_easy_setopt(handler, CURLOPT_WRITEDATA, domain.c_str()); curl_easy_setopt(handler, CURLOPT_WRITEDATA, domain.c_str());

View File

@ -2,4 +2,54 @@
// Created by brett on 8/9/23. // Created by brett on 8/9/23.
// //
#include <crowsite/requests/jellyfin.h> #include <crowsite/requests/jellyfin.h>
#include <crowsite/requests/curl.h> #include <crowsite/requests/curl.h>
#include <crow/json.h>
#include <blt/std/hashmap.h>
#include <blt/std/logging.h>
#include <string>
struct
{
std::string token;
HASHMAP<std::string, std::string> user_ids;
} GLOBALS;
void cs::jellyfin::setToken(std::string_view token)
{
GLOBALS.token = token;
}
void cs::jellyfin::processUserData()
{
auto data = getUserData();
auto json = crow::json::load(data);
for (const auto& user : json){
auto username = user["Name"].s();
auto userid = user["Id"].s();
//BLT_TRACE("Processing %s = %s", username.operator std::string().c_str(), userid.operator std::string().c_str());
GLOBALS.user_ids[username] = userid;
}
}
std::string cs::jellyfin::getUserData()
{
#define url "https://media.tpgc.me/Users"
cs::request request;
request.setAuthHeader(generateAuthHeader());
request.get(url);
return cs::request::getResponse(url);
}
std::string cs::jellyfin::generateAuthHeader()
{
return "MediaBrowser Client=Crowsite, Device=YourMom, Token=" + GLOBALS.token;
}
bool cs::jellyfin::hasUser(std::string_view username)
{
return GLOBALS.user_ids.find(std::string(username)) != GLOBALS.user_ids.end();
}

View File

@ -7,6 +7,7 @@
#include <crowsite/utility.h> #include <crowsite/utility.h>
#include <crowsite/site/cache.h> #include <crowsite/site/cache.h>
#include <crowsite/beemovie.h> #include <crowsite/beemovie.h>
#include <crowsite/requests/jellyfin.h>
#include <crowsite/requests/curl.h> #include <crowsite/requests/curl.h>
#include <blt/parse/argparse.h> #include <blt/parse/argparse.h>
@ -48,6 +49,8 @@ int main(int argc, const char** argv)
blt::arg_parse parser; blt::arg_parse parser;
parser.addArgument(blt::arg_builder("token").build()); parser.addArgument(blt::arg_builder("token").build());
auto args = parser.parse_args(argc, argv); auto args = parser.parse_args(argc, argv);
cs::jellyfin::setToken(blt::arg_parse::get<std::string>(args["token"]));
cs::jellyfin::processUserData();
// blt::string::StringBuffer buffer; // blt::string::StringBuffer buffer;
// std::stringstream stream; // std::stringstream stream;
@ -101,12 +104,7 @@ int main(int argc, const char** argv)
// //
// return 0; // return 0;
cs::request get;
get.setAuthHeader("MediaBrowser Client=Crowsite, Device=YourMom, Token=" + blt::arg_parse::get<std::string>(args["token"]));
get.get("https://media.tpgc.me/Users");
const auto& f = cs::request::getResponse("https://media.tpgc.me/Users");
BLT_TRACE(f);
BLT_INFO("Starting site %s.", SITE_NAME); BLT_INFO("Starting site %s.", SITE_NAME);
crow::mustache::set_global_base(SITE_FILES_PATH); crow::mustache::set_global_base(SITE_FILES_PATH);