Skip to content

Commit

Permalink
Add Threadfin Enhanced app (#746)
Browse files Browse the repository at this point in the history
* Add Threadfin Enhanced app

* Fix lint error

* Add SVG icon for Threadfin
  • Loading branch information
albinmedoc authored Jun 27, 2024
1 parent 6b1312b commit 35b82de
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Threadfin/Threadfin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\SupportedApps\Threadfin;

class Threadfin extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;

//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

public function __construct()
{
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
}

private function getStatus()
{
$attrs = [
"headers" => [
"Content-Type" => "application/json"
],
"body" => json_encode([
"cmd" => "status"
])
];

$res = parent::execute($this->url("api/"), $attrs);

switch ($res->getStatusCode()) {
case 200:
return json_decode($res->getBody());
case 400:
throw new \Exception("Bad command");
default:
throw new \Exception("Could not connect to Threadfin");
}
}

public function test()
{
try {
$res = $this->getStatus();
if ($res->status == true) {
echo "Successfully communicated with the API";
} else {
echo "Threadfin is not in a good health";
}
} catch (Exception $err) {
echo $err->getMessage();
}
}

public function livestats()
{
$status = "inactive";
$data = [];

$res = $this->getStatus();

$data["activeChannels"] = $res->{"streams.active"};
$data["totalChannels"] = $res->{"streams.all"};

return parent::getLiveStats($status, $data);
}

public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
return $api_url;
}
}
10 changes: 10 additions & 0 deletions Threadfin/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appid": "98028de0432f62fda3283fc2e833f0d68c2a38d9",
"name": "Threadfin",
"website": "https://github.com/Threadfin/Threadfin",
"license": "MIT license",
"description": "An M3U proxy for Kernel/Plex/Jellyfin/Emby based on xTeVe",
"enhanced": true,
"tile_background": "dark",
"icon": "threadfin.svg"
}
10 changes: 10 additions & 0 deletions Threadfin/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
<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">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
5 changes: 5 additions & 0 deletions Threadfin/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul class="livestats">
<li>
<span class="title">Channels</span>
<strong>{!! $activeChannels !!}<span>/{!! $totalChannels !!}</span></strong>
</li>
61 changes: 61 additions & 0 deletions Threadfin/threadfin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 35b82de

Please sign in to comment.