Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "plex-connect.h"
- #import <Cocoa/Cocoa.h>
- #include "restclient-cpp/restclient.h"
- #include "restclient-cpp/connection.h"
- #include <json/json.h>
- #include <string>
- /*
- $host = "https://plex.tv/users/sign_in.json";
- $username = 'myPlexUser';
- $password = 'myPlexPass';
- $header = array(
- 'Content-Type: application/xml; charset=utf-8',
- 'Content-Length: 0',
- 'X-Plex-Client-Identifier: 8334-8A72-4C28-FDAF-29AB-479E-4069-C3A3',
- 'X-Plex-Product: Test',
- 'X-Plex-Version: v1_06',
- );
- $process = curl_init($host);
- curl_setopt($process, CURLOPT_HTTPHEADER, $header);
- curl_setopt($process, CURLOPT_HEADER, 0);
- curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
- curl_setopt($process, CURLOPT_TIMEOUT, 30);
- curl_setopt($process, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($process, CURLOPT_POST, 1);
- curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($process);
- $curlError = curl_error($process);
- $json = json_decode($data, true);
- */
- CPlexConnect::CPlexConnect()
- : mConnection(nullptr)
- {
- }
- CPlexConnect::~CPlexConnect()
- {
- }
- void CPlexConnect::Open()
- {
- mConnection = new RestClient::Connection("http://192.168.2.202:32400");
- //mConnection->SetTimeout(1);
- mConnection->SetBasicAuth("", "");
- //conn->SetBasicAuth("myPlexUser", "myPlexPass");
- mConnection->SetBasicAuth("", "");
- mConnection->AppendHeader("Accept", "application/json");
- Json::Value root;
- std::string root_url = "";
- if (GetAndParse(root_url, root))
- {
- bool allowChannelAccess = root.get("allowChannelAccess", "").asString() == "1";
- bool allowSync = root.get("allowSync", "").asString() == "1";
- bool backgroundProcessing = root.get("backgroundProcessing", "").asString() == "1";
- bool allowMediaDeletion = root.get("allowMediaDeletion", "").asString() == "1";
- bool transcoderAudio = root.get("transcoderAudio", "").asString() == "1";
- bool transcoderVideo = root.get("transcoderVideo", "").asString() == "1";
- std::string serverClass = root.get("allowMediaDeletion", "").asString();
- std::string version = root.get("version", "").asString();
- //std::string serverClass = root["allowMediaDeletion"].asString();
- //std::string version = root["version"].asString();
- // updatedAt
- // transcoderVideoResolutions
- // transcoderVideoBitrates
- // transcoderVideoQualities
- Json::Value sections_root;
- std::string sections_root_url = "/library/sections";
- if (GetAndParse(sections_root_url, sections_root))
- {
- Json::Value sections = sections_root.get("_children", "");
- for (int i = 0; i < sections.size(); ++i)
- {
- NSLog(@"%s", sections[i]["key"].asString().c_str());
- NSLog(@"%s", sections[i]["title"].asString().c_str());
- Json::Value section;
- std::string section_url = sections_root_url + "/";
- section_url += sections[i]["key"].asString() + "/all";
- if (GetAndParse(section_url, section))
- {
- Json::Value items = section.get("_children", "");
- for (int i = 0; i < items.size(); ++i)
- {
- //NSLog(@"%s", items[i]["key"].asString().c_str());
- NSLog(@"%s", items[i]["title"].asString().c_str());
- }
- }
- }
- }
- }
- }
- bool CPlexConnect::GetAndParse(const std::string path, Json::Value &value)
- {
- bool parsingSuccessful = false;
- RestClient::Response res = mConnection->get(path);
- if (res.code == 200)
- {
- NSLog(@"%s", res.body.c_str());
- Json::Reader reader;
- std::istringstream body(res.body);
- parsingSuccessful = reader.parse(body, value, false);
- }
- return parsingSuccessful;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement