diff --git a/Jellystat/Jellystat.php b/Jellystat/Jellystat.php new file mode 100644 index 0000000000..a63d825b24 --- /dev/null +++ b/Jellystat/Jellystat.php @@ -0,0 +1,86 @@ +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'; + } +} diff --git a/Jellystat/app.json b/Jellystat/app.json new file mode 100644 index 0000000000..fa614b67e7 --- /dev/null +++ b/Jellystat/app.json @@ -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" +} diff --git a/Jellystat/config.blade.php b/Jellystat/config.blade.php new file mode 100644 index 0000000000..3007a2d6e0 --- /dev/null +++ b/Jellystat/config.blade.php @@ -0,0 +1,14 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! 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']) !!} +
+
+ +
+
diff --git a/Jellystat/jellystat.png b/Jellystat/jellystat.png new file mode 100644 index 0000000000..38a65f38cb Binary files /dev/null and b/Jellystat/jellystat.png differ diff --git a/Jellystat/livestats.blade.php b/Jellystat/livestats.blade.php new file mode 100644 index 0000000000..4a28f8babb --- /dev/null +++ b/Jellystat/livestats.blade.php @@ -0,0 +1,12 @@ +