From 61506594b718c70d246f3051c5202b2225c60a22 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 25 Mar 2026 11:57:13 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 17 +- scripts/cron/cron.php | 50 ---- scripts/lib/lib.php | 10 - scripts/lib/mediarasp.php | 508 ------------------------------------ scripts/lib/remoteinfos.php | 34 +-- scripts/lib/shield.php | 13 +- scripts/shield.php | 2 - scripts/syno.php | 6 - scripts/tmdb.php | 13 - scripts/transcode.php | 4 - 10 files changed, 15 insertions(+), 642 deletions(-) delete mode 100644 scripts/lib/mediarasp.php delete mode 100644 scripts/syno.php delete mode 100644 scripts/tmdb.php delete mode 100644 scripts/transcode.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3d3a144..299110e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,8 +6,15 @@ - - + + + + + + + + + @@ -1755,7 +1762,7 @@ file://$PROJECT_DIR$/scripts/cron/cron.php - 207 + 162 diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 92f1315..493e98f 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -16,8 +16,6 @@ function cronOneLoop($cronmin) { } if ($cronmin % 15 == 0) { cronPodcasts($cronmin); - cronMediaLibrary($cronmin); - cronTmdb($cronmin); } if ($cronmin % 5 == 0) { @@ -26,7 +24,6 @@ function cronOneLoop($cronmin) { } if ($cronmin % 20 == 0) { - cronBackyard($cronmin); cronSqueezeCheckPlayers($cronmin); } @@ -38,19 +35,10 @@ function cronOneLoop($cronmin) { cronInterface($cronmin); cronEcoMode($cronmin); - if ($cronmin % 15 == 0) { - cronKodi($cronmin); - } cronHeartbeat($cronmin, true); _logSection('End Loop (min:' . $cronmin . ')'); } - -function cronBackyard($cronmin) -{ - _logSection('Backyard'); -} - function cronShield($cronmin) { _logSection('Shield'); `/usr/local/bin/adb-connect`; @@ -97,38 +85,6 @@ function cronRooms($cronmin) { } } -function cronMediaLibrary($cronmin) { - global $directories; - _logSection('Media Library'); - - $media = array(); - $shareroot = '/volume1/Share'; - - - foreach ($directories as $name => $directory) { - $dir = $shareroot . '/Videos/' . $directory['dir']; - if ($directory['context'] == 'tvshow' || $name == 'Films') { - continue; - } - $media[$directory['id']] = array('name' => $name, 'items' => getMediaContents($dir, $directory['context'])); - } - - connectRedis()->igbset('medialibrary', $media); - - _getTVShows(true); - _getMovies(true); - _getMediaRecentAdded(true); -} - - -function cronTmdb($cronmin) { - _logSection('TMDB'); - _getTVShows(true, false); - _getMovies(true, false); - _getMediaRecentAdded(true); - parseMoviesLibrary(); -} - function cronPing($cronmin) { _logSection('Pings'); global $devices; @@ -165,7 +121,6 @@ function cronWeather($cronmin) { getWeather(); } - function cronPodcasts($cronmin) { checkSpottyLogin(); return; @@ -206,9 +161,4 @@ function cronHeartbeat($cronmin, $devices = false) { return; } restartDeadDevices(); -} - -function cronKodi($cronmin) { - _logSection('Kodi'); - kodiSyncPlayedStatus(); } \ No newline at end of file diff --git a/scripts/lib/lib.php b/scripts/lib/lib.php index 9145f64..1982403 100644 --- a/scripts/lib/lib.php +++ b/scripts/lib/lib.php @@ -411,16 +411,6 @@ function getJsonRPCClientInstance($url) return $rpcclient; } -function getSynologyInstance() -{ - global $syno; - if (!isset($syno)) { - $syno = new Synology_Api('192.168.13.3', 5002, 'https', 1); - $syno->connect('Vincent', 'xxxx'); - } - return $syno; -} - function hasNetwork() { return true; diff --git a/scripts/lib/mediarasp.php b/scripts/lib/mediarasp.php deleted file mode 100644 index 3a07112..0000000 --- a/scripts/lib/mediarasp.php +++ /dev/null @@ -1,508 +0,0 @@ - ['button', 'jump_fwd'], 'fast-forward' => ['button', 'jump_fwd'], 'fast-rewind' => ['button', 'jump_rew'], 'rewind' => ['button', 'jump_rew'], 'play' => ['pause'], 'pause' => ['pause'], 'stop' => 'stop']; - if (isset($map[$cmd])) { - squeezeRequest($map[$cmd], $player); - } -} - -function remoteCmdSalonTV($cmd) -{ - $map = ['play' => 'play', - 'pause' => 'play', - 'channel-up' => 'prgm_inc', - 'channel-down' => 'prgm_dec', - 'channelup' => 'prgm_inc', - 'channeldown' => 'prgm_dec', - 'up' => 'up', - 'left' => 'left', - 'right' => 'right', - 'down' => 'down', - 'ok' => 'ok', - 'prev-channel' => 'red', - 'tv' => 'home', - 'media' => 'red', - //'mute'=>'', - 'direction-left' => 'left', - 'direction-right' => 'right', - 'direction-up' => 'up', - 'direction-down' => 'down', - 'select' => 'ok', - //'volume-down'=>'' , - //'volume-up'=>'', - 'blue' => 'blue', - 'yellow' => 'yellow', - 'red' => 'red', - 'green' => 'green', - 'guide' => 'media', - 'epg' => 'epg', - 'info' => 'yellow', - 'menu' => 'home', - 'exit' => 'red', - 'esc' => 'red', - 'stop' => 'stop', - 'forward' => 'fwd', - 'fast-forward' => 'fwd', - 'record' => 'rec', - 'fast-rewind' => 'bwd', - 'rewind' => 'bwd', - 'next' => 'next', - 'prev' => 'prev', - 'numeric_0' => '0', - 'numeric_1' => '1', - 'numeric_2' => '2', - 'numeric_3' => '3', - 'numeric_4' => '4', - 'numeric_5' => '5', - 'numeric_6' => '6', - 'numeric_7' => '7', - 'numeric_8' => '8', - 'numeric_9' => '9', - ]; - - if (isset($map[$cmd])) { - freeboxKey([$map[$cmd]]); - return true; - } - return false; -} - -function remoteCmdMedia($cmd, $device = null, $playing = null) -{ - if (null === $device) { - $device = config('DEVICE'); - } - - profile('remote cmd ' . $cmd . ' on ' . $device); - - $map = ['play' => 'pl_pause', - 'pause' => 'pl_pause', - 'stop' => 'pl_stop', - 'exit' => 'pl_stop', - 'title' => 'm', - 'rewind' => 'rewind', - 'forward' => 'forward', - 'fast-rewind' => 'fast-rewind', - 'fast-forward' => 'fast-forward', - 'info' => 'z', - 'direction-left' => 'down', - 'direction-right' => 'up', - 'subtitles-toggle' => 'subtitles-toggle', - 'subtitles-stream-next' => 'subtitles-stream-next', - 'subtitles-stream-prev' => 'subtitles-stream-prev', - 'subtitles-increase-delay' => 'subtitles-increase-delay', - 'subtitles-increase-delay-long' => 'subtitles-increase-delay-long', - 'subtitles-decrease-delay' => 'subtitles-decrease-delay', - 'subtitles-decrease-delay-long' => 'subtitles-decrease-delay-long', - 'audio-track-next' => 'audio-track-next', - ]; - - - if ($device == 'bureau') { - $map['volume-up'] = '+'; - $map['volume-down'] = '-'; - $map['mute'] = '-'; - } - - if (!isset($map[$cmd])) { - return false; - } - - $key = $map[$cmd]; - - - if (null === $playing || $playing == 'mediarasp') { - if ($key == 'subtitles-toggle') { - sendHotKey('shift+v'); - } else if ($key == 'subtitles-stream-next') { - sendHotKey('v'); - } else if ($key == 'subtitles-stream-prev') { - sendHotKey('alt+v'); - } else if ($key == 'subtitles-increase-delay') { - sendHotKey('h', 5); - } else if ($key == 'subtitles-decrease-delay') { - sendHotKey('g', 5); - } else if ($key == 'subtitles-increase-delay-long') { - sendHotKey('h', 40); - } else if ($key == 'subtitles-decrease-delay-long') { - sendHotKey('g', 40); - } else if ($key == 'audio-track-next') { - sendHotKey('b'); - } else if ($key == 'rewind' || $key == 'fast-rewind' || $key == 'forward' || $key == 'fast-forward') { - if ($key == 'rewind' || $key == 'forward') { - $amount = 15; - } else if ($key == 'fast-rewind' || $key == 'fast-forward') { - $amount = 300; - } - if ($key == 'rewind' || $key == 'fast-rewind') { - $way = '-'; - } else if ($key == 'forward' || $key == 'fast-forward') { - $way = '+'; - } - $res = VLCCmd(['command' => 'seek', 'val' => $way . $amount . 's'], $device); - } else { - $params = ['command' => $key]; - $res = VLCCmd($params, $device); - } - echo $res; - } - - return true; -} - -function sendHotKey($key, $times = 1, $device = null) -{ - $keys = str_repeat(' key ' . $key, $times); - return sshCommand('DISPLAY=:0 xdotool getactivewindow' . $keys, $device, true, false); -} - -function moveVLC($fullscreen = true, $device = null) -{ - if ($fullscreen) { - $e = '0,0,800,480'; - } else { - $e = '163,128,414,224'; - } - return sshCommand('DISPLAY=:0 wmctrl -r "VLC" -e 0,' . $e . ';DISPLAY=:0 wmctrl -i -r "VLC" -b add,above;DISPLAY=:0 /usr/local/bin/removeallborders', $device, true, false); -} - -function remoteCmdSalonMusique($cmd) -{ - switch ($cmd) { - case 'PLAY': - case 'PAUSE': - - break; - } - return false; -} - -function mediaRaspPlayMovie($movie, $device = null) -{ - setPlaying('mediarasp:' . $movie, $device); - - profile('mediaRaspPlayMovie ' . $movie, __FILE__, __LINE__); - - $m = explode('.', $movie); - $ext = array_pop($m); - $x264 = false; - if ($m[count($m) - 1] == 'x264') { - array_pop($m); - $x264 = true; - } - $base = implode('.', $m); - - addSeen($movie); - $res = VLCPlay($movie, $device); - - setPlaying('mediarasp:' . $movie, $device); - return $res; -} - -function addSeen($movie) -{ - $redis = connectRedis(); - - try { - $seen = $redis->igbget('mediaseen'); - } catch (Exception $e) { - $seen = []; - } - - if (!is_array($seen)) { - $seen = []; - } - - $cacheFile = ROOT . '/cache/seen.json'; - if (!count($seen)) { - $seen = json_decode(file_get_contents($cacheFile), true); - } - - $seen[str_replace('/nas/', '/volume1/Share/', $movie)] = true; - $redis->igbset('mediaseen', $seen); - - file_put_contents($cacheFile, json_encode($seen)); -} - -function mediaRaspCommons($device) -{ - global $squeezeboxPlayers; - if ($device == 'salon') { - stopSqueezebox('Salon'); - } else if ($device == 'bureau') { - if (getState('bureauPlaying', '0') === '0') { - execScene('bureau/media/play'); - } - stopSqueezebox($squeezeboxPlayers['Bureau']); - if (!isAlive('bureau')) { - sleep(60); - } - } else if ($device == 'sdb') { - execScene('sdb/ampli/on'); - } -} - -function mediaRaspPlayStream($url, $device = null) -{ - setPlaying('mediarasp:' . $url, $device); - mediaRaspCommons($device); - $res = VLCPlay($url, $device); - setPlaying('mediarasp:' . $url, $device); - mediaRaspCommons($device); - return $res; -} - -function mediaRaspPlayCast($castURL, $device = null) -{ - if (null === $device) { - $device = config('DEVICE'); - } - if ($device === 'bureau') { - $height = 720; - } else if ($device === 'salon') { - $height = 1080; - } else { - $height = 640; - } - - setPlaying('mediarasp:cast:' . $castURL); - mediaRaspCommons($device); - $dest = downloadYoutubeDL($castURL, $height, true, 'mkv'); - getYoutubeDLMeta($castURL); - $res = VLCPlay($dest, $device); - setPlaying('mediarasp:cast:' . $castURL); - return $res; -} - -function getYoutubeDLCastURL($url, $height = 1080) -{ - $h = ''; - if ($height != 0) { - $h = '[height<=' . $height . ']'; - } - $cmd = "/usr/local/bin/youtube-dl -f 'best$h' --get-url '$url'"; - $res = `$cmd`; - echo $res; - return trim($res); -} - -function getYoutubeDLPath($url, $h = 0, $ext = 'mkv') -{ - $hash = $url; - if ($h != 0) { - $hash .= '--' . $h . '++'; - } - $hash = sha1($hash); - return "/nas/Videos/YoutubeDL/" . $hash . '.' . $ext; -} - -function downloadYoutubeDL($url, $height = 1080, $cast = true, $ext = 'mkv') -{ - $dest = getYoutubeDLPath($url, $height, $ext); - $wip = $dest . '.wip'; - if (!file_exists($dest)) { - if (!file_exists($wip)) { - $convert = 'https://' . $_SERVER['HTTP_HOST'] . '/scripts/youtubedl-download.php'; - try { - httpRequest($convert, 'get', ['url' => $url, 'h' => $height, 'ext' => $ext], null, $cast ? 1 : 0); - } catch (Exception $e) { - - } - if (!$cast) { - return $dest; - } - } - if ($cast) { - return getYoutubeDLCastURL($url, $height); - } - } else { - return $dest; - } -} - -function getYoutubeDLMeta($url, $isHash = false) -{ - if (!$isHash) { - $hash = sha1($url); - } else { - $hash = $url; - } - $meta = connectRedis()->igbget('youtubedl.' . $hash); - - if ($meta === false && !$isHash) { - $locale = 'en_US.UTF8'; - setlocale(LC_ALL, $locale); - putenv('LC_ALL=' . $locale); - $res = `LC_ALL=$locale;/usr/local/bin/youtube-dl --no-warnings -e --get-thumbnail --get-duration $url`; - $lines = explode("\n", $res, 3); - - // Duration - $d = explode(':', trim($lines[2])); - $d = array_reverse($d); - $duration = 0; - $m = 1; - foreach ($d as $item) { - $duration += $item * $m; - $m *= 60; - } - - $meta = ['title' => trim($lines[0]), 'thumbnail' => trim($lines[1]), 'duration' => $duration]; - connectRedis()->igbset('youtubedl.' . $hash, $meta); - } - return $meta; -} - -function cleanUpSubtitle($srtcontent) -{ - // Convert to UTF-8 - $srtenc = mb_detect_encoding($srtcontent, 'UTF-8, ISO-8859-1'); - if ($srtenc !== 'UTF-8') { - $srtcontent = mb_convert_encoding($srtcontent, 'UTF-8', $srtenc); - - } - // Remove tags - $srtcontent = preg_replace('/\{\\\\[^}]+\}/m', '', $srtcontent); - - // Fix oe - $srtcontent = str_replace('œ', 'oe', $srtcontent); - - - return $srtcontent; -} - -/** - * @return \GuzzleHttp\Client - */ -function getMediaRaspClient() -{ - global $mediaraspclient; - - if ($mediaraspclient == null) { - $mediaraspclient = getHttpClient(); - } - return $mediaraspclient; -} - -function getDevice($device = null) -{ - global $devices; - if (is_array($device) && isset($device['host'])) { - return $device; - } - if (null === $device) { - $device = config('DEVICE'); - } - return $devices[$device]; -} - -function VLCCmd($params, $device = null, $timeout = 5) -{ - $d = getDevice($device); - if (isset($params['query'])) { - $query = $params['query']; - unset($params['query']); - } else { - $query = 'requests/status.xml'; - } - $url = 'http://' . $d['host'] . ':8754/' . $query; - $client = getMediaRaspClient(); - try { - $response = $client->get($url, ['query' => $params, 'timeout' => $timeout, 'auth' => ['', 'atacama']]); - return $response->getBody(); - } catch (Exception $e) { - echo $d['host'] . print_r($params) . ':' . $e->getMessage(); - return false; - } -} - -function VLCPlay($fileorstream, $device = null, $timeout = 5) -{ - $device = getDevice($device); - if (config('VIDEOPLAYER') === 'shield') { - return shieldKodi($fileorstream); - } else { - VLCCmd(['command' => 'pl_empty'], $device, $timeout); - if (file_exists($fileorstream)) { - $fileorstream = 'file://' . $fileorstream; - } - echo $fileorstream; - if ($device === 'bureau') { - sshCommand('/usr/local/bin/soundtohdmi', $device, true, true); - } - return VLCCmd(['command' => 'in_play', 'input' => $fileorstream], $device, $timeout); - } -} - diff --git a/scripts/lib/remoteinfos.php b/scripts/lib/remoteinfos.php index e090612..a50a57b 100644 --- a/scripts/lib/remoteinfos.php +++ b/scripts/lib/remoteinfos.php @@ -6,7 +6,7 @@ function remoteInfos() $p = $e[0]; if (config('TVPLAYER') === 'shield') { - $visualApps = ['arte', 'francetv', 'mycanal', 'youtube', 'dailymotion', 'vimeo', 'kodi', 'vlc']; + $visualApps = ['arte', 'francetv', 'mycanal', 'youtube', 'dailymotion', 'vimeo']; if (in_array(shieldGetCurrentApp(), $visualApps)) { if ($p === 'squeezebox') { setPlaying('shield'); @@ -18,36 +18,7 @@ function remoteInfos() $res = squeezeboxRemoteInfos(); } else { if (config('TVPLAYER') === 'shield') { - if (shieldGetCurrentApp() === 'kodi') { - $res = ['type' => 'shieldmedia', 'can_seek' => true]; - while (true) { - try { - $req = httpRequest('http://' . getDevice()['shield'] . ':8754/jsonrpc?Base=1', 'post', '[{"jsonrpc":"2.0","method":"Player.GetProperties","params":[1,["playlistid","speed","position","totaltime","time","percentage","shuffled","repeat","canrepeat","canshuffle","canseek","partymode"]],"id":1},{"jsonrpc":"2.0","method":"Player.GetItem","params":[1,["title","thumbnail","file","artist","genre","year","rating","album","track","duration","playcount","dateadded","episode","artistid","albumid","tvshowid","fanart"]],"id":2}]', ['kodi', 'atacama'], 10, true, ['X-Requested-With' => 'XMLHttpRequest', 'Content-type' => 'application/json']); - break; - } catch (Exception $e) { - - } - sleep(2); - } - $p = json_decode($req->getBody(), true); - $res['duration'] = ''; - $res['time'] = ''; - $res['title'] = ''; - $res['artwork'] = ''; - $res['status'] = json_encode($p); - if (isset($p[0]['result'])) { - $r = $p[0]['result']; - $res['can_seek'] = $r['canseek']; - $res['duration'] = 3600 * $r['totaltime']['hours'] + 60 * $r['totaltime']['minutes'] + $r['totaltime']['seconds']; - $res['time'] = 3600 * $r['time']['hours'] + 60 * $r['time']['minutes'] + $r['time']['seconds']; - } - if (isset($p[1]['result']['item']['file'])) { - $res = array_merge($res, getTitleAndArtwork($p[1]['result']['item']['file'])); - } - } else { $res = ['type' => 'shield', 'can_seek' => false]; - } - } else { if (($p === 'netflix' || $p === 'tv' || $p==='amazonprime') && config('TVPLAYER') === 'shield') { $res = ['type' => 'shield', 'can_seek' => false]; @@ -84,9 +55,6 @@ function remoteInfos() function remoteProgress($progress) { if (config('TVPLAYER') === 'shield') { - if (shieldGetCurrentApp() === 'kodi') { - $p = json_decode(httpRequest('http://' . getDevice()['shield'] . ':8754/jsonrpc', 'post', '[{"jsonrpc":"2.0","method":"Player.Seek","params":[1,' . (round($progress * 100)) . '],"id":3}]', ['kodi', 'atacama'], 10, true, ['X-Requested-With' => 'XMLHttpRequest', 'Content-type' => 'application/json'])->getBody(), true); - } return; } diff --git a/scripts/lib/shield.php b/scripts/lib/shield.php index f713491..f92ccbb 100644 --- a/scripts/lib/shield.php +++ b/scripts/lib/shield.php @@ -250,14 +250,6 @@ function shieldMyCanal($channel = false, $type = 'live', $device = null) return shieldCommand('shell am start', '-a android.intent.action.VIEW -f 0x10808000 -d ' . $url . ' com.canal.android.canal/com.canal.mycanal.legacy.DeepLinkActivity', $device); } -function shieldKodi($file, $device = null) -{ - $url = shieldNormalizeURL($file); - profile('shield kodi ' . $file . '//' . $url, __FILE__, __LINE__); - shieldRunActivity($device); - shieldHome($device); - shieldCommand('shell am start', '-a android.intent.action.VIEW -d \'"' . $url . '"\' -n org.xbmc.kodi/.Splash', $device); -} function shielOqee($channel, $device = null) { @@ -309,8 +301,7 @@ function shieldGetAppId($id = null) function shieldGetApps() { - return ['kodi' => 'org.xbmc.kodi', - 'vlc' => 'org.videolan.vlc', + return [ 'netflix' => 'com.netflix.ninja', 'mycanal' => 'com.canal.android.canal', 'arte' => 'tv.arte.plus7', @@ -335,7 +326,7 @@ function shieldGetApps() function shieldPlayingVideo($device = null) { - $videoApps = ['kodi', 'vlc', 'mycanal', 'amazonprime', 'netflix', 'arte', 'francetv', 'gamecast', 'twitch', 'youtube', 'dailymotion', 'vimeo', 'steamlink', 'plex']; + $videoApps = ['mycanal', 'amazonprime', 'netflix', 'arte', 'francetv', 'gamecast', 'twitch', 'youtube', 'dailymotion', 'vimeo', 'steamlink', 'plex']; return in_array(shieldGetCurrentApp($device), $videoApps); } diff --git a/scripts/shield.php b/scripts/shield.php index 651aa59..b2609f9 100644 --- a/scripts/shield.php +++ b/scripts/shield.php @@ -20,8 +20,6 @@ if (isset($_GET['key'])) { shieldFindIntents($_GET['intents'], $device); } else if (isset($_GET['vlc'])) { shieldVLC($_GET['vlc'], $device); -} else if (isset($_GET['kodi'])) { - shieldKodi($_GET['kodi'], $device); } else if (isset($_GET['mycanal'])) { $e = explode(':', $_GET['mycanal']); echo shieldMyCanal($e[1], $e[0], $device); diff --git a/scripts/syno.php b/scripts/syno.php deleted file mode 100644 index bb80f29..0000000 --- a/scripts/syno.php +++ /dev/null @@ -1,6 +0,0 @@ -getAvailableApi()); -exit; \ No newline at end of file diff --git a/scripts/tmdb.php b/scripts/tmdb.php deleted file mode 100644 index 24e8dcc..0000000 --- a/scripts/tmdb.php +++ /dev/null @@ -1,13 +0,0 @@ -del(['shortcuts.' . getCurrentConfig()]); -ob_end_clean(); -header('Location: /#/section/home'); \ No newline at end of file diff --git a/scripts/transcode.php b/scripts/transcode.php deleted file mode 100644 index 1f958ed..0000000 --- a/scripts/transcode.php +++ /dev/null @@ -1,4 +0,0 @@ -