Skip to content

Commit 6a4c63f

Browse files
authored
Add JellyStat as enhanced (#732)
* First Version - Icon is not the right size - "Something went wrong" * Rename icon * Overhaul... * Remove all debug stuff * changes for PHPCS * PHPCS
1 parent dc24a6a commit 6a4c63f

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

Jellystat/Jellystat.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace App\SupportedApps\Jellystat;
4+
5+
class Jellystat extends \App\SupportedApps implements \App\EnhancedApps
6+
{
7+
public $config;
8+
9+
//protected $login_first = true; // Uncomment if api requests need to be authed first
10+
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
11+
12+
public function __construct()
13+
{
14+
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
15+
}
16+
17+
public function test()
18+
{
19+
$attrs = $this->getRequestAttrs();
20+
$test = parent::appTest($this->url('stats/getLibraryCardStats'), $attrs);
21+
echo $test->status;
22+
}
23+
24+
public function livestats()
25+
{
26+
$status = 'inactive';
27+
$attrs = $this->getRequestAttrs();
28+
29+
$res = parent::execute($this->url('stats/getAllUserActivity'), $attrs);
30+
31+
$results = json_decode($res->getBody());
32+
33+
$details = ["visiblestats" => []];
34+
35+
$newstat = new \stdClass();
36+
$newstat->TotalPlays = new \stdClass();
37+
$newstat->TotalPlays->title = 'Total Plays';
38+
39+
$newstat->TotalWatchTime = new \stdClass();
40+
$newstat->TotalWatchTime->title = 'Total Watchtime';
41+
42+
if (isset($results[0])) {
43+
$result = $results[0];
44+
$newstat->TotalPlays->value = $result->TotalPlays;
45+
$newstat->TotalWatchTime->value = $this->secondsToHoursMinutes($result->TotalWatchTime);
46+
}
47+
48+
$details["visiblestats"][] = $newstat;
49+
50+
return parent::getLiveStats($status, $details);
51+
}
52+
53+
public function url($endpoint)
54+
{
55+
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
56+
return $api_url;
57+
}
58+
59+
private function getRequestAttrs()
60+
{
61+
$attrs = [
62+
"headers" => [
63+
64+
"accept" => "application/json",
65+
"x-api-token" => $this->config->x_api_token,
66+
],
67+
];
68+
69+
return $attrs;
70+
}
71+
72+
private function secondsToHoursMinutes($seconds)
73+
{
74+
75+
// Calculate the hours
76+
$hours = floor($seconds / 3600);
77+
78+
// Calculate the remaining seconds
79+
// into minutes
80+
$minutes = floor(($seconds % 3600) / 60);
81+
82+
// Return the result as an
83+
// associative array
84+
return $hours . 'h ' . $minutes . 'min';
85+
}
86+
}

Jellystat/app.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"appid": "b134790d9a8269a36013773814955539268e224a",
3+
"name": "Jellystat",
4+
"website": "https://github.com/CyferShepard/Jellystat",
5+
"license": "MIT License",
6+
"description": "Jellystat is a free and open source Statistics App for Jellyfin!",
7+
"enhanced": true,
8+
"tile_background": "dark",
9+
"icon": "jellystat.png"
10+
}

Jellystat/config.blade.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
2+
<div class="items">
3+
<div class="input">
4+
<label>{{ strtoupper(__('app.url')) }}</label>
5+
{!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!}
6+
</div>
7+
<div class="input">
8+
<label>API token</label>
9+
{!! Form::input('text', 'config[x_api_token]', isset($item) ? $item->getconfig()->x_api_token : null, ['placeholder' => __('Api Token'), 'data-config' => 'x_api_token', 'class' => 'form-control config-item']) !!}
10+
</div>
11+
<div class="input">
12+
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
13+
</div>
14+
</div>

Jellystat/jellystat.png

16.3 KB
Loading

Jellystat/livestats.blade.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ul class="livestats">
2+
@foreach ($visiblestats as $stat)
3+
<li>
4+
<span class="title">{!! $stat->TotalPlays->title !!}</span>
5+
<strong>{!! $stat->TotalPlays->value !!}</strong>
6+
</li>
7+
<li>
8+
<span class="title">{!! $stat->TotalWatchTime->title !!}</span>
9+
<strong>{!! $stat->TotalWatchTime->value !!}</strong>
10+
</li>
11+
@endforeach
12+
</ul>

0 commit comments

Comments
 (0)