Update includes/functions.php
This commit is contained in:
parent
74bae56f05
commit
23abb63bb8
1 changed files with 174 additions and 104 deletions
|
|
@ -32,8 +32,8 @@ function enforce_rate_limits() {
|
||||||
return ['status' => 'success'];
|
return ['status' => 'success'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to send a request to AllDebrid API
|
// Function to send a GET request to AllDebrid API
|
||||||
function alldebrid_api_request($endpoint, $params = []) {
|
function alldebrid_api_get_request($endpoint, $params = []) {
|
||||||
$params['agent'] = 'SquidDebridEU';
|
$params['agent'] = 'SquidDebridEU';
|
||||||
$params['apikey'] = ALLDEBRID_API_KEY;
|
$params['apikey'] = ALLDEBRID_API_KEY;
|
||||||
$url = ALLDEBRID_API_URL . $endpoint . '?' . http_build_query($params);
|
$url = ALLDEBRID_API_URL . $endpoint . '?' . http_build_query($params);
|
||||||
|
|
@ -60,10 +60,80 @@ function alldebrid_api_request($endpoint, $params = []) {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to send a POST request to AllDebrid API
|
||||||
|
function alldebrid_api_post_request($endpoint, $params = []) {
|
||||||
|
$params['agent'] = 'SquidDebridEU';
|
||||||
|
$params['apikey'] = ALLDEBRID_API_KEY;
|
||||||
|
$url = ALLDEBRID_API_URL . $endpoint;
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
return ['status' => 'error', 'error' => 'Failed to connect to AllDebrid API: ' . curl_error($ch)];
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return ['status' => 'error', 'error' => 'Invalid API response: ' . json_last_error_msg()];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to send a POST request to AllDebrid API with correct Content Type for File Uploading
|
||||||
|
function alldebrid_api_upload_file($endpoint, $filePath) {
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
return ['status' => 'error', 'error' => 'File not found.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = new CURLFile($filePath, 'application/x-bittorrent', basename($filePath));
|
||||||
|
$params = [
|
||||||
|
'agent' => 'SquidDebridEU',
|
||||||
|
'apikey' => ALLDEBRID_API_KEY,
|
||||||
|
'files[]' => $file
|
||||||
|
];
|
||||||
|
|
||||||
|
$url = ALLDEBRID_API_URL . $endpoint;
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
return ['status' => 'error', 'error' => 'Failed to connect to AllDebrid API: ' . curl_error($ch)];
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return ['status' => 'error', 'error' => 'Invalid API response: ' . json_last_error_msg()];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Function to copy an torrent/magnet link
|
// Function to copy an torrent/magnet link
|
||||||
function upload_torrent_magnet($link) {
|
function upload_torrent_magnet($link) {
|
||||||
// Use the correct parameter name for magnets (e.g., "magnets[]")
|
// Use the correct parameter name for magnets (e.g., "magnets[]")
|
||||||
$response = alldebrid_api_request('magnet/upload', ['magnets[]' => $link]);
|
$response = alldebrid_api_get_request('magnet/upload', ['magnets[]' => $link]);
|
||||||
if ($response['status'] === 'success') {
|
if ($response['status'] === 'success') {
|
||||||
return $response['data'];
|
return $response['data'];
|
||||||
}
|
}
|
||||||
|
|
@ -71,8 +141,8 @@ function upload_torrent_magnet($link) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to upload a .torrent file
|
// Function to upload a .torrent file
|
||||||
function upload_torrent_file($file) {
|
function upload_torrent_file($filePath) {
|
||||||
$response = alldebrid_api_request('magnet/upload/file', [], $file);
|
$response = alldebrid_api_upload_file('magnet/upload/file', $filePath);
|
||||||
if ($response['status'] === 'success') {
|
if ($response['status'] === 'success') {
|
||||||
return $response['data'];
|
return $response['data'];
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +151,7 @@ function upload_torrent_file($file) {
|
||||||
|
|
||||||
// Function to get torrent/magnet status and file list
|
// Function to get torrent/magnet status and file list
|
||||||
function get_torrent_status($id) {
|
function get_torrent_status($id) {
|
||||||
$response = alldebrid_api_request('magnet/status', ['id' => $id]);
|
$response = alldebrid_api_get_request('magnet/status', ['id' => $id]);
|
||||||
if ($response['status'] === 'success') {
|
if ($response['status'] === 'success') {
|
||||||
return $response['data'];
|
return $response['data'];
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +160,7 @@ function get_torrent_status($id) {
|
||||||
|
|
||||||
// Function to get supported file hosters
|
// Function to get supported file hosters
|
||||||
function get_supported_filehosts() {
|
function get_supported_filehosts() {
|
||||||
$response = alldebrid_api_request("hosts");
|
$response = alldebrid_api_get_request("hosts");
|
||||||
$hosts = $response['data']['hosts'];
|
$hosts = $response['data']['hosts'];
|
||||||
|
|
||||||
// filter out alldebrid and example from the hosts
|
// filter out alldebrid and example from the hosts
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue