Преглед на файлове

Merge 53a10944a9d03f58f70521f126f5ae31f0b6ef76 into 196a843148d8a072b03b64e600db2a01a617c7d2

mrquatsch преди 7 години
родител
ревизия
544da4b0fd
променени са 5 файла, в които са добавени 189 реда и са изтрити 2 реда
  1. 1 0
      app/Item.php
  2. 67 2
      app/SupportedApps/Plexpy.php
  3. 89 0
      app/SupportedApps/Runeaudio.php
  4. 11 0
      resources/views/supportedapps/plexpy.blade.app
  5. 21 0
      resources/views/supportedapps/runeaudio.blade.php

+ 1 - 0
app/Item.php

@@ -51,6 +51,7 @@ class Item extends Model
             'Portainer' => \App\SupportedApps\Portainer::class,
             'Proxmox' => \App\SupportedApps\Proxmox::class,
             'Radarr' => \App\SupportedApps\Radarr::class,
+            'Runeaudio' => \App\SupportedApps\Runeaudio::class,
             'Sabnzbd' => \App\SupportedApps\Sabnzbd::class,
             'Sonarr' => \App\SupportedApps\Sonarr::class,
             'Traefik' => \App\SupportedApps\Traefik::class,

+ 67 - 2
app/SupportedApps/Plexpy.php

@@ -1,6 +1,12 @@
 <?php namespace App\SupportedApps;
 
-class Plexpy implements Contracts\Applications {
+use GuzzleHttp\Exception\GuzzleException;
+use GuzzleHttp\Client;
+
+class Plexpy implements Contracts\Applications, Contracts\Livestats {
+
+    public $config;
+
     public function defaultColour()
     {
         return '#2d2208';
@@ -9,4 +15,63 @@ class Plexpy implements Contracts\Applications {
     {
         return 'supportedapps/plexpy.png';
     }
-}
+    public function configDetails()
+    {
+        return 'plexpy';
+    }
+    public function testConfig()
+    {
+        $res = $this->buildRequest('arnold');
+        switch($res->getStatusCode()) {
+            case 200:
+                $data = json_decode($res->getBody());
+                if(isset($data->error) && !empty($data->error)) {
+                    echo 'Failed: '.$data->error;
+                } else {
+                    echo 'Successfully connected to the API';
+                }
+                break;
+            case 401:
+                echo 'Failed: Invalid credentials';
+                break;
+            case 404:
+                echo 'Failed: Please make sure your URL is correct and that there is a trailing slash';
+                break;
+            default:
+                echo 'Something went wrong... Code: '.$res->getStatusCode();
+                break;
+        }
+    }
+    public function executeConfig()
+    {
+        $output = '';
+        $res = $this->buildRequest('get_activity');
+        $data = json_decode($res->getBody());
+        $stream_count = $data->response->data->stream_count;
+
+        $output = '
+        <ul class="livestats">
+            <li><span class="title">Stream Count</span><strong>'.$stream_count.'</strong></li>
+        </ul>
+        ';
+
+        return $output;
+    }
+    public function buildRequest($endpoint)
+    {
+        $config = $this->config;
+        $url = $config->url;
+        $apikey = $config->apikey;
+
+        $url = rtrim($url, '/');
+
+        $api_url = $url.'/api/v2?apikey='.$apikey.'&cmd='.$endpoint;
+        //die( $api_url.' --- ');
+
+        $client = new Client(['http_errors' => false]);
+        $res = $client->request('GET', $api_url);
+        return $res;
+
+    }
+   
+}

+ 89 - 0
app/SupportedApps/Runeaudio.php

@@ -0,0 +1,89 @@
+<?php namespace App\SupportedApps;
+
+use GuzzleHttp\Exception\GuzzleException;
+use GuzzleHttp\Client;
+
+class Runeaudio implements Contracts\Applications, Contracts\Livestats {
+    public function defaultColour()
+    {
+        return '#05A';
+    }
+    public function icon()
+    {
+        return 'supportedapps/runeaudio.png';
+    }
+
+    public function configDetails()
+    {
+        return 'runeaudio';
+    }
+
+    public function testConfig()
+    {
+        $res = $this->buildRequest('status');
+        switch($res->getStatusCode()) {
+            case 200:
+                echo 'Successfully connected to the API';
+                break;
+            case 401:
+                echo 'Failed: Invalid credentials';
+                break;
+            case 404:
+                echo 'Failed: Please make sure your URL is correct and that there is a trailing slash';
+                break;
+            default:
+                echo 'Something went wrong... Code: '.$res->getStatusCode();
+                break;
+        }
+    }
+
+    public function executeConfig()
+    {
+        $output = '';
+        $artist = '';
+        $song_title = '';
+        $res = $this->buildRequest('currentsong');
+        $array = explode("\n", $res->getBody());
+        foreach($array as $item) {
+            $item_array = explode(": ", $item);
+            if ($item_array[0] == 'Artist') {
+                $artist = $item_array[1];
+                if (strlen($artist) > 15) {
+                    $artist = substr($artist,0,12).'...';
+                }
+            } elseif ($item_array[0] == 'Title') {
+                $song_title = $item_array[1];
+                if (strlen($song_title) > 15) {
+                    $song_title = substr($song_title,0,12).'...';
+                }
+            }
+        }
+
+        $output = '
+        <ul class="livestats">
+            <li><span class="title">Artist</span><strong>'.$artist.'</strong></li>
+            <li><span class="title">Song</span><strong>'.$song_title.'</strong></li>
+        </ul>
+        ';
+
+        return $output;
+    }
+
+    public function buildRequest($endpoint)
+    {
+        $config = $this->config;
+        $url = $config->url;
+
+        $url = rtrim($url, '/');
+
+        $api_url = $url.'/command/?cmd='.$endpoint;
+        //die( $api_url.' --- ');
+
+        $client = new Client(['http_errors' => false]);
+        $res = $client->request('GET', $api_url);
+        return $res;
+
+    }
+
+
+}

+ 11 - 0
resources/views/supportedapps/plexpy.blade.app

@@ -0,0 +1,11 @@
+<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }})</h2>
+<div class="items">
+    <input type="hidden" data-config="type" class="config-item" name="config[type]" value="\App\SupportedApps\Plexpy" />
+    <div class="input">
+        <label>{{ __('app.apps.apikey') }}</label>
+        {!! Form::text('config[apikey]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item')) !!}
+    </div>
+    <div class="input">
+        <button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
+    </div>
+</div>

+ 21 - 0
resources/views/supportedapps/runeaudio.blade.php

@@ -0,0 +1,21 @@
+<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }})</h2>
+<div class="items">
+    <input type="hidden" data-config="type" class="config-item" name="config[type]" value="\App\SupportedApps\Runeaudio" />
+    <input type="hidden" data-config="dataonly" class="config-item" name="config[dataonly]" value="1" />
+    <div class="input">
+        <label>{{ __('app.apps.enable') }}</label>
+        {!! Form::hidden('config[enabled]', '0') !!}
+        <label class="switch">
+            <?php
+            $checked = false;
+            if(isset($item->config->enabled) && (bool)$item->config->enabled === true) $checked = true;
+            $set_checked = ($checked) ? ' checked="checked"' : '';
+            ?>
+            <input type="checkbox" name="config[enabled]" value="1"<?php echo $set_checked;?> />
+            <span class="slider round"></span>
+        </label>
+    </div>
+    <div class="input">
+        <button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
+    </div>
+</div>