From 818491132234de6a0c49f4f74f8a68ea25f19031 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 25 Mar 2026 12:00:40 +0100 Subject: [PATCH] . --- .idea/workspace.xml | 14 +-- config/music.php | 42 +------ scripts/cron/cron.php | 234 ++++++++++++++++++------------------- scripts/lib/squeezebox.php | 15 +-- 4 files changed, 123 insertions(+), 182 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 299110e..a83b2bd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,15 +6,9 @@ + - - - - - - - - + diff --git a/config/music.php b/config/music.php index 27c1de2..3a7f1af 100644 --- a/config/music.php +++ b/config/music.php @@ -3,9 +3,6 @@ $allmusics = array(); squeezeFavorites(connectRedis()->igbget('squeezebox_favorites'), $shortcuts); profile('Got Music favorites', __FILE__, __LINE__); -$podcasts = connectRedis()->igbget('squeezebox_podcasts'); -//podcastDir($podcasts, 'Podcasts', 'podcasts', $shortcuts); -//profile('Got podcasts', __FILE__, __LINE__); function squeezeFavorites($favorites, &$shortcuts) { @@ -61,39 +58,6 @@ function squeezeSubitems($s, $key, $label, &$shortcuts) $shortcuts[$key] = array_merge([['type' => 'back', 'label' => $label]], $t); } -function podcastDir($podcasts, $label, $key, &$shortcuts) -{ - global $allmusics; - - $k = 'sub-' . $key; - $t = []; - - $hasDir = false; - if (!is_array($podcasts)) { - return; - } - foreach ($podcasts as $subitem) { - if ($subitem['hasitems']) { - if (count($subitem['subitems']) == 0) { - - } elseif (count($subitem['subitems']) == 1) { - $t[] = audioElement($subitem['subitems'][0], 'podcasts'); - } else { - $subname = isset($subitem['name']) && $subitem['name'] ? $subitem['name'] : $subitem['title']; - $subkey = $key . '-' . str_replace('.', '_', $subitem['id']); - $t[] = ['type' => 'sub', 'label' => $subname, 'sub' => $subkey]; - podcastDir($subitem['subitems'], $subname, $subkey, $shortcuts); - $hasDir = true; - } - } else { - $t[] = audioElement($subitem, 'podcasts'); - } - } - - $shortcuts[$k] = array_merge([['type' => 'back', 'label' => $label]], $t); - -} - function audioElement($subitem, $app = 'favorites') { global $allmusics; @@ -113,8 +77,4 @@ $shortcuts['music'] = [ ['type' => 'sub', 'label' => 'Radios', 'sub' => 'radio'], ['type' => 'sub', 'label' => 'Musique', 'sub' => 'playlists'], ['type' => 'sub', 'label' => 'Ambiance', 'sub' => 'ambiance'], -]; - -if ($podcasts !== false) { - $shortcuts['music'][] = ['type' => 'sub', 'label' => 'Podcasts', 'sub' => 'podcasts']; -} \ No newline at end of file +]; \ No newline at end of file diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 493e98f..9accfcf 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -2,163 +2,163 @@ require_once __DIR__ . "/../import.php"; -function cronOneLoop($cronmin) { - set_time_limit(0); +function cronOneLoop($cronmin) +{ + set_time_limit(0); - echo '------------------------------------' . "\n"; - _logSection('One Loop // ' . $cronmin); - cronHeartbeat($cronmin, false); - cronRooms($cronmin); - cronWeather($cronmin); + echo '------------------------------------' . "\n"; + _logSection('One Loop // ' . $cronmin); + cronHeartbeat($cronmin, false); + cronRooms($cronmin); + cronWeather($cronmin); if ($cronmin % 10 == 0) { cronSqueezeFavorites($cronmin); } - if ($cronmin % 15 == 0) { - cronPodcasts($cronmin); - } - if ($cronmin % 5 == 0) { - cronGuest($cronmin); - cronShield($cronmin); - } + if ($cronmin % 5 == 0) { + cronGuest($cronmin); + cronShield($cronmin); + } - if ($cronmin % 20 == 0) { - cronSqueezeCheckPlayers($cronmin); - } + if ($cronmin % 20 == 0) { + cronSqueezeCheckPlayers($cronmin); + } - if ($cronmin % 2 == 0) { - cronPing($cronmin); - } + if ($cronmin % 2 == 0) { + cronPing($cronmin); + } - cronHarmony($cronmin); - cronInterface($cronmin); + cronHarmony($cronmin); + cronInterface($cronmin); - cronEcoMode($cronmin); - cronHeartbeat($cronmin, true); - _logSection('End Loop (min:' . $cronmin . ')'); + cronEcoMode($cronmin); + cronHeartbeat($cronmin, true); + _logSection('End Loop (min:' . $cronmin . ')'); } -function cronShield($cronmin) { - _logSection('Shield'); - `/usr/local/bin/adb-connect`; +function cronShield($cronmin) +{ + _logSection('Shield'); + `/usr/local/bin/adb-connect`; } -function cronGuest($cronmin) { +function cronGuest($cronmin) +{ - _logSection('Guest'); - setState('guest', hasGuest() ? '1' : '0'); + _logSection('Guest'); + setState('guest', hasGuest() ? '1' : '0'); } -function cronEcoMode($cronmin) { - _logSection('Ecomode'); +function cronEcoMode($cronmin) +{ + _logSection('Ecomode'); setState('cron_heartbeat', time()); - ecoMode(null, $cronmin % 15 === 0); + ecoMode(null, $cronmin % 15 === 0); } -function _logSection($t) { - echo '------' . $t . ' :: ' . date('Y-m-d H:i:s') . "\n"; +function _logSection($t) +{ + echo '------' . $t . ' :: ' . date('Y-m-d H:i:s') . "\n"; } -function cronRooms($cronmin) { - _logSection('Rooms'); +function cronRooms($cronmin) +{ + _logSection('Rooms'); - _logSection('Bureau'); - updateBureauAuto(); + _logSection('Bureau'); + updateBureauAuto(); - _logSection('Chambre'); - updateChambreAuto(); + _logSection('Chambre'); + updateChambreAuto(); - _logSection('Cour'); - updateCourAuto(); + _logSection('Cour'); + updateCourAuto(); - _logSection('Salon'); - updateSalonAuto(); + _logSection('Salon'); + updateSalonAuto(); - _logSection('Cuisine'); - updateCuisine(); - _logSection('Planetarium'); - checkPlanetarium(); - if ($cronmin % 2) { - _logSection('WC VMC'); - checkWCVMC(); - } -} - -function cronPing($cronmin) { - _logSection('Pings'); - global $devices; - setState('vincenthere', ping('192.168.13.20', 5) ? '1' : '0'); - setState('hasnetwork', ping('1.1.1.1', 3, 443) ? '1' : '0'); - foreach ($devices as $name => $device) { - if (!isset($device['host'])) { - continue; - } - $result = ping($device['host'], 3, 22) ? '1' : '0'; - setState('device_' . $name . '_awake', $result); - echo 'device_' . $name . '_awake : ' . getState('device_' . $name . '_awake') . "\n"; - if ($result) { - sshCommand('pwd', $device['host'], false, false); - sshCommand('pwd', $device['host'], false, true); - } - } + _logSection('Cuisine'); + updateCuisine(); + _logSection('Planetarium'); + checkPlanetarium(); + if ($cronmin % 2) { + _logSection('WC VMC'); + checkWCVMC(); + } } -function cronSqueezeFavorites($cronmin) { - _logSection('Squeeze Favorites'); - $favorites = getSqueezeFavorites(); - if ($favorites !== false && count($favorites) > 0) { - connectRedis()->igbset('squeezebox_favorites', $favorites); - } +function cronPing($cronmin) +{ + _logSection('Pings'); + global $devices; + setState('vincenthere', ping('192.168.13.20', 5) ? '1' : '0'); + setState('hasnetwork', ping('1.1.1.1', 3, 443) ? '1' : '0'); + foreach ($devices as $name => $device) { + if (!isset($device['host'])) { + continue; + } + $result = ping($device['host'], 3, 22) ? '1' : '0'; + setState('device_' . $name . '_awake', $result); + echo 'device_' . $name . '_awake : ' . getState('device_' . $name . '_awake') . "\n"; + if ($result) { + sshCommand('pwd', $device['host'], false, false); + sshCommand('pwd', $device['host'], false, true); + } + } } -function cronSqueezeCheckPlayers($cronmin) { - _logSection('Check squeezebox players'); +function cronSqueezeFavorites($cronmin) +{ + _logSection('Squeeze Favorites'); + $favorites = getSqueezeFavorites(); + if ($favorites !== false && count($favorites) > 0) { + connectRedis()->igbset('squeezebox_favorites', $favorites); + } } -function cronWeather($cronmin) { - _logSection('Weather'); - getWeather(); +function cronSqueezeCheckPlayers($cronmin) +{ + _logSection('Check squeezebox players'); } -function cronPodcasts($cronmin) { - checkSpottyLogin(); - return; - _logSection('Podcasts'); - $podcasts = getSqueezeFavorites(0, 'podcasts'); - if ($podcasts !== false && count($podcasts) > 0) { - connectRedis()->igbset('squeezebox_podcasts', $podcasts); - } +function cronWeather($cronmin) +{ + _logSection('Weather'); + getWeather(); } -function cronInterface($cronmin) { - _logSection('Interface'); - if ((getState('ecomode') == '0' && $cronmin % 3 == 0) || $cronmin % 10 == 0) { - $devices = ['salon', 'bureau', 'entree', 'cuisine', 'litvincent', 'litjerome', 'sdb', 'chambre', 'bureausun', 'wc']; - foreach ($devices as $device) { - file_get_contents('https://' . $device . '.home.tortuga.enhydra.fr/'); - } - } +function cronInterface($cronmin) +{ + _logSection('Interface'); + if ((getState('ecomode') == '0' && $cronmin % 3 == 0) || $cronmin % 10 == 0) { + $devices = ['salon', 'bureau', 'entree', 'cuisine', 'litvincent', 'litjerome', 'sdb', 'chambre', 'bureausun', 'wc']; + foreach ($devices as $device) { + file_get_contents('https://' . $device . '.home.tortuga.enhydra.fr/'); + } + } } -function cronHarmony($cronmin) { - _logSection('Harmony'); - $currentActivity = getCurrentHarmonyActivity(); - if ($currentActivity == HARMONY_MUSIQUE) { - setPlaying('squeezebox', 'bureau'); - } else if ($currentActivity == HARMONY_OFF) { - setPlaying('mycanal', 'bureau'); - } +function cronHarmony($cronmin) +{ + _logSection('Harmony'); + $currentActivity = getCurrentHarmonyActivity(); + if ($currentActivity == HARMONY_MUSIQUE) { + setPlaying('squeezebox', 'bureau'); + } else if ($currentActivity == HARMONY_OFF) { + setPlaying('mycanal', 'bureau'); + } } -function cronHeartbeat($cronmin, $devices = false) { - _logSection('Heartbeat'); - setState('cron_heartbeat', time()); - squeezeRequest(null); - hueCommand(null); +function cronHeartbeat($cronmin, $devices = false) +{ + _logSection('Heartbeat'); + setState('cron_heartbeat', time()); + squeezeRequest(null); + hueCommand(null); - if (!$devices || $cronmin % 5 != 0) { - return; - } - restartDeadDevices(); + if (!$devices || $cronmin % 5 != 0) { + return; + } + restartDeadDevices(); } \ No newline at end of file diff --git a/scripts/lib/squeezebox.php b/scripts/lib/squeezebox.php index 246a80a..c00c648 100644 --- a/scripts/lib/squeezebox.php +++ b/scripts/lib/squeezebox.php @@ -261,7 +261,6 @@ function isMacAddress($mac) } - function getSqueezeFavorites($root = 0, $app = 'favorites', $level = 0) { global $squeezeboxPlayers; @@ -282,24 +281,12 @@ function getSqueezeFavorites($root = 0, $app = 'favorites', $level = 0) if (is_array($loop)) { - if ($app == 'podcasts' && $level != 0 && count(explode('.', $loop[0]['id'])) <= 2) { - return getSqueezeFavorites(0, $app, 0); - } - - if ($level > 0 && $app == 'podcasts') { - $loop = array_slice($loop, 0, 50); - } - foreach ($loop as $item) { - - if ($app == 'podcasts' && isset($item['isaudio']) && $item['isaudio']) { - $item['hasitems'] = 0; - } if (isset($item['hasitems']) && $item['hasitems'] == 1 && (!isset($item['type']) || $item['type'] !== 'playlist')) { $subitems = getSqueezeFavorites($item['id'], $app, $level + 1); - if ($app == 'favorites' || $app == 'podcasts') { + if ($app == 'favorites') { while (isset($subitems[0]) && ((isset($item['name']) && isset($subitems[0]['name']) && $item['name'] == $subitems[0]['name']) || (isset($item['title']) && isset($subitems[0]['title']) && $item['title'] == $subitems[0]['title']))) { return $subitems; } -- 2.39.5