Skip to content

Commit

Permalink
Add JellyStat as enhanced (#732)
Browse files Browse the repository at this point in the history
* First Version
- Icon is not the right size
- "Something went wrong"
* Rename icon
* Overhaul...
* Remove all debug stuff
* changes for PHPCS
* PHPCS
  • Loading branch information
kekZiger authored May 17, 2024
1 parent dc24a6a commit 6a4c63f
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
86 changes: 86 additions & 0 deletions Jellystat/Jellystat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\SupportedApps\Jellystat;

class Jellystat 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
}

public function test()
{
$attrs = $this->getRequestAttrs();
$test = parent::appTest($this->url('stats/getLibraryCardStats'), $attrs);
echo $test->status;
}

public function livestats()
{
$status = 'inactive';
$attrs = $this->getRequestAttrs();

$res = parent::execute($this->url('stats/getAllUserActivity'), $attrs);

$results = json_decode($res->getBody());

$details = ["visiblestats" => []];

$newstat = new \stdClass();
$newstat->TotalPlays = new \stdClass();
$newstat->TotalPlays->title = 'Total Plays';

$newstat->TotalWatchTime = new \stdClass();
$newstat->TotalWatchTime->title = 'Total Watchtime';

if (isset($results[0])) {
$result = $results[0];
$newstat->TotalPlays->value = $result->TotalPlays;
$newstat->TotalWatchTime->value = $this->secondsToHoursMinutes($result->TotalWatchTime);
}

$details["visiblestats"][] = $newstat;

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

public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url) . $endpoint;
return $api_url;
}

private function getRequestAttrs()
{
$attrs = [
"headers" => [

"accept" => "application/json",
"x-api-token" => $this->config->x_api_token,
],
];

return $attrs;
}

private function secondsToHoursMinutes($seconds)
{

// Calculate the hours
$hours = floor($seconds / 3600);

// Calculate the remaining seconds
// into minutes
$minutes = floor(($seconds % 3600) / 60);

// Return the result as an
// associative array
return $hours . 'h ' . $minutes . 'min';
}
}
10 changes: 10 additions & 0 deletions Jellystat/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appid": "b134790d9a8269a36013773814955539268e224a",
"name": "Jellystat",
"website": "https://github.com/CyferShepard/Jellystat",
"license": "MIT License",
"description": "Jellystat is a free and open source Statistics App for Jellyfin!",
"enhanced": true,
"tile_background": "dark",
"icon": "jellystat.png"
}
14 changes: 14 additions & 0 deletions Jellystat/config.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<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">
<label>API token</label>
{!! 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']) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>
Binary file added Jellystat/jellystat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Jellystat/livestats.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul class="livestats">
@foreach ($visiblestats as $stat)
<li>
<span class="title">{!! $stat->TotalPlays->title !!}</span>
<strong>{!! $stat->TotalPlays->value !!}</strong>
</li>
<li>
<span class="title">{!! $stat->TotalWatchTime->title !!}</span>
<strong>{!! $stat->TotalWatchTime->value !!}</strong>
</li>
@endforeach
</ul>

0 comments on commit 6a4c63f

Please sign in to comment.