ajout heimdall
This commit is contained in:
166
heimdall/config/www/SupportedApps/Transmission/Transmission.php
Executable file
166
heimdall/config/www/SupportedApps/Transmission/Transmission.php
Executable file
@@ -0,0 +1,166 @@
|
||||
<?php namespace App\SupportedApps\Transmission;
|
||||
|
||||
class Transmission extends \App\SupportedApps implements \App\EnhancedApps
|
||||
{
|
||||
public $config;
|
||||
public $attrs = [];
|
||||
public $vars;
|
||||
|
||||
//protected $login_first = true; // Uncomment if api requests need to be authed first
|
||||
protected $method = "POST"; // Uncomment if requests to the API should be set by POST
|
||||
|
||||
function __construct()
|
||||
{
|
||||
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
|
||||
$body["method"] = "torrent-get";
|
||||
$body["arguments"] = [
|
||||
"fields" => ["percentDone", "status", "rateDownload", "rateUpload"],
|
||||
];
|
||||
$this->vars = [
|
||||
"http_errors" => false,
|
||||
"timeout" => 5,
|
||||
"body" => json_encode($body),
|
||||
];
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$test = $this->sendTest();
|
||||
|
||||
echo $test->status;
|
||||
}
|
||||
|
||||
public function livestats()
|
||||
{
|
||||
$status = "inactive";
|
||||
$res = $this->sendRequest();
|
||||
if ($res == null) {
|
||||
//Log::debug('Transmission connection failed');
|
||||
return "";
|
||||
}
|
||||
|
||||
$details = json_decode($res->getBody());
|
||||
if (!isset($details->arguments)) {
|
||||
//Log::debug('Failed to fetch data from Transmission');
|
||||
return "";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
$torrents = $details->arguments->torrents;
|
||||
$seeding_torrents = 0;
|
||||
$leeching_torrents = 0;
|
||||
$rateDownload = $rateUpload = 0;
|
||||
|
||||
foreach ($torrents as $thisTorrent) {
|
||||
$rateDownload += $thisTorrent->rateDownload;
|
||||
$rateUpload += $thisTorrent->rateUpload;
|
||||
if ($thisTorrent->status == 6) {
|
||||
$seeding_torrents += 1;
|
||||
}
|
||||
if($thisTorrent->status == 4) {
|
||||
$leeching_torrents += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($leeching_torrents > 0) {
|
||||
$status = "active";
|
||||
}
|
||||
|
||||
$data["download_rate"] = format_bytes(
|
||||
$rateDownload,
|
||||
false,
|
||||
" <span>",
|
||||
"/s</span>"
|
||||
);
|
||||
$data["upload_rate"] = format_bytes(
|
||||
$rateUpload,
|
||||
false,
|
||||
" <span>",
|
||||
"/s</span>"
|
||||
);
|
||||
$data["seed_count"] = $seeding_torrents;
|
||||
$data["leech_count"] = $leeching_torrents;
|
||||
|
||||
return parent::getLiveStats($status, $data);
|
||||
}
|
||||
|
||||
private function sendTest()
|
||||
{
|
||||
$this->setClientOptions();
|
||||
$test = parent::appTest(
|
||||
$this->url("transmission/rpc"),
|
||||
$this->attrs,
|
||||
$this->vars
|
||||
);
|
||||
if ($test->code === 409) {
|
||||
$this->setClientOptions();
|
||||
$test = parent::appTest(
|
||||
$this->url("transmission/rpc"),
|
||||
$this->attrs,
|
||||
$this->vars
|
||||
);
|
||||
}
|
||||
return $test;
|
||||
}
|
||||
|
||||
private function sendRequest()
|
||||
{
|
||||
$this->setClientOptions();
|
||||
$res = parent::execute(
|
||||
$this->url("transmission/rpc"),
|
||||
$this->attrs,
|
||||
$this->vars
|
||||
);
|
||||
if ($res->getStatusCode() === 409) {
|
||||
$this->setClientOptions();
|
||||
$res = parent::execute(
|
||||
$this->url("transmission/rpc"),
|
||||
$this->attrs,
|
||||
$this->vars
|
||||
);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function setClientOptions()
|
||||
{
|
||||
if ($this->config->username != "" || $this->config->password != "") {
|
||||
$this->attrs = [
|
||||
"auth" => [
|
||||
$this->config->username,
|
||||
$this->config->password,
|
||||
"Basic",
|
||||
],
|
||||
];
|
||||
}
|
||||
$res = parent::execute(
|
||||
$this->url("transmission/rpc"),
|
||||
$this->attrs,
|
||||
$this->vars
|
||||
);
|
||||
|
||||
try {
|
||||
//print_r($res);
|
||||
$xtId = $res->getHeaderLine("X-Transmission-Session-Id");
|
||||
if ($xtId != null) {
|
||||
$this->attrs["headers"] = [
|
||||
"X-Transmission-Session-Id" => $xtId,
|
||||
];
|
||||
} else {
|
||||
//Log::error("Unable to get Transmission session information");
|
||||
//Log::debug("Status Code: ".$res->getStatusCode());
|
||||
}
|
||||
} catch (\GuzzleHttp\Exception\ConnectException $e) {
|
||||
//Log::error("Failed connection to Transmission");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function url($endpoint)
|
||||
{
|
||||
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
|
||||
return $api_url;
|
||||
}
|
||||
}
|
||||
10
heimdall/config/www/SupportedApps/Transmission/app.json
Executable file
10
heimdall/config/www/SupportedApps/Transmission/app.json
Executable file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"appid": "34899a33e3d7e33e1966b921ea250350fc71591a",
|
||||
"name": "Transmission",
|
||||
"website": "https://transmissionbt.com",
|
||||
"license": "GNU General Public License v3.0 only",
|
||||
"description": "Transmission is a BitTorrent client which features a variety of user interfaces on top of a cross-platform back-end.",
|
||||
"enhanced": true,
|
||||
"tile_background": "dark",
|
||||
"icon": "transmission.svg"
|
||||
}
|
||||
19
heimdall/config/www/SupportedApps/Transmission/config.blade.php
Executable file
19
heimdall/config/www/SupportedApps/Transmission/config.blade.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
|
||||
<div class="items">
|
||||
<input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
|
||||
<div class="input">
|
||||
<label>{{ strtoupper(__('app.url')) }}</label>
|
||||
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.username') }}</label>
|
||||
{!! Form::text('config[username]', isset($item) ? $item->getconfig()->username : null, ['placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<label>{{ __('app.apps.password') }}</label>
|
||||
{!! Form::input('password', 'config[password]', '', ['placeholder' => __('app.apps.password'), 'data-config' => 'password', 'class' => 'form-control config-item']) !!}
|
||||
</div>
|
||||
<div class="input">
|
||||
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
4
heimdall/config/www/SupportedApps/Transmission/livestats.blade.php
Executable file
4
heimdall/config/www/SupportedApps/Transmission/livestats.blade.php
Executable file
@@ -0,0 +1,4 @@
|
||||
<ul class="livestats">
|
||||
<li><span class="title">Leech: {{ $leech_count }}</span><strong>{!! $download_rate !!}</strong></li>
|
||||
<li><span class="title">Seed: {{ $seed_count }}</span><strong>{!! $upload_rate !!}</strong></li>
|
||||
</ul>
|
||||
BIN
heimdall/config/www/SupportedApps/Transmission/transmission.png
Executable file
BIN
heimdall/config/www/SupportedApps/Transmission/transmission.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
Reference in New Issue
Block a user