feat: move kodi diashow updater to api.mayer.life
This commit is contained in:
parent
80737e207c
commit
59cdcc0fdb
|
@ -0,0 +1,3 @@
|
|||
# folder diashow
|
||||
|
||||
This folder is mapped within the `php` container to the live `diashow` folder containing the *.jpg images.
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
include('../inc/config.php');
|
||||
// script runtime...
|
||||
$rustart = getrusage();
|
||||
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
$DEBUG = false;
|
||||
|
||||
$verbose = (isset($_GET["d"]) && $_GET["d"] == "1");
|
||||
$verboseMsg = "";
|
||||
|
||||
$glob = "diashow/*.[jJ][pP][gG]";
|
||||
$jsonf = "diashow/images.json";
|
||||
|
||||
$output = [];
|
||||
ini_set('exif.encode_unicode', 'UTF-8');
|
||||
|
||||
/*ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);*/
|
||||
|
||||
$existing = [];
|
||||
if (file_exists($jsonf)) {
|
||||
$existing = json_decode(file_get_contents($jsonf));
|
||||
}
|
||||
|
||||
// if($DEBUG) { var_dump($existing); }
|
||||
|
||||
$hasChanges = false;
|
||||
$i = 0;
|
||||
$noinfo = 0;
|
||||
foreach (glob($glob) as $filename) {
|
||||
//debugEcho(basename($filename));
|
||||
$exif = exif_read_data($filename, 'IFD0', true);
|
||||
|
||||
$title = getExifValue($exif, "ImageDescription");
|
||||
$subject = getExifValue($exif, "Subject");
|
||||
|
||||
$fname = basename($filename);
|
||||
$jsonItem = null;
|
||||
foreach ($existing as $itm) {
|
||||
if ($fname == $itm->image) {
|
||||
$jsonItem = $itm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($jsonItem != null && ($jsonItem->line1 != $title || $jsonItem->line2 != $subject)) {
|
||||
if ($DEBUG) {
|
||||
debugEcho("changed existing item");
|
||||
if ($jsonItem->line1 != $title) {
|
||||
debugEcho("title: $jsonItem->line1 => $title");
|
||||
}
|
||||
if ($jsonItem->line2 != $subject) {
|
||||
debugEcho("subject: $jsonItem->line2 => $subject");
|
||||
}
|
||||
}
|
||||
$hasChanges = true;
|
||||
} else {
|
||||
if ($jsonItem == null && ($title != "" && $subject != "")) {
|
||||
debugEcho("new item\ntitle: $title\nsubject: $subject");
|
||||
$hasChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($title != "" && $subject != "") {
|
||||
//debugEcho("title=$title subject=$subject");
|
||||
$output[] = array('image' => basename($filename), 'line1' => $title, 'line2' => $subject);
|
||||
} else {
|
||||
$noinfo++;
|
||||
if ($title != "" || $subject != "") {
|
||||
$verboseMsg .= "Komisch, ignoriert: " . basename($filename) . "\n";
|
||||
debugEcho("title=$title\nsubject=$subject");
|
||||
} else {
|
||||
$verboseMsg .= "Keine Infos in " . basename($filename) . "\n";
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($hasChanges && !$DEBUG) {
|
||||
file_put_contents($jsonf, json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
//$f = fopen($jsonf, "w") or die("unable to open file!");
|
||||
//fwrite($f, json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
//fclose($f);
|
||||
} else {
|
||||
if ($DEBUG) {
|
||||
$verboseMsg .= "no changes (debug, $hasChanges).\n";
|
||||
} else {
|
||||
$verboseMsg .= "no changes.\n";
|
||||
}
|
||||
}
|
||||
//debugEcho(json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
$verboseMsg .= "$i Dateien, $noinfo ohne Beschreibung\n";
|
||||
|
||||
if (!$verbose && $noinfo > 0) {
|
||||
include('../inc/gotify.php');
|
||||
$gotify = new Gotify();
|
||||
if ($gotify->send($config['gotify-url'],$config['gotify-token'], "kodi diashow", $verboseMsg)) {
|
||||
print "ok.";
|
||||
} else {
|
||||
print "failed to gotify! " . $gotify->getLastStatus();
|
||||
}
|
||||
}
|
||||
|
||||
$ru = getrusage();
|
||||
if ($verbose) {
|
||||
echo $verboseMsg;
|
||||
echo "This process used " . rutime($ru, $rustart, "utime") .
|
||||
" ms for its computations\n";
|
||||
echo "It spent " . rutime($ru, $rustart, "stime") .
|
||||
" ms in system calls\n";
|
||||
} else {
|
||||
echo "ok\r\n";
|
||||
echo rutime($ru, $rustart, "utime") . "ms";
|
||||
}
|
||||
|
||||
function getExifValue(array $arr, string $val): string
|
||||
{
|
||||
if (!isset($arr["IFD0"])) {
|
||||
//debugEcho("IFD0 is missing");
|
||||
return "";
|
||||
} else {
|
||||
if (isset($arr["IFD0"][$val])) {
|
||||
$ret = str_replace("\0", "", $arr["IFD0"][$val]);
|
||||
//debugEcho("orig: $ret");
|
||||
//debugEcho(mb_detect_encoding($ret));
|
||||
if (mb_detect_encoding($ret) == "UTF-8") {
|
||||
//debugEcho("...converting...");
|
||||
$ret = mb_convert_encoding($ret, "ISO-8859-1");
|
||||
}
|
||||
//debugEcho("after: $ret");
|
||||
return utf8_encode($ret);
|
||||
} else {
|
||||
//debugEcho("$val is missing in IFD0");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function debugEcho(string $msg)
|
||||
{
|
||||
global $DEBUG;
|
||||
if ($DEBUG) {
|
||||
echo "$msg\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Script runtime...
|
||||
function rutime(array|false $ru, array|false $rus, string $index)
|
||||
{
|
||||
if($ru === false || $rus === false) {
|
||||
return 0;
|
||||
}
|
||||
return ($ru["ru_$index.tv_sec"] * 1000 + intval($ru["ru_$index.tv_usec"] / 1000))
|
||||
- ($rus["ru_$index.tv_sec"] * 1000 + intval($rus["ru_$index.tv_usec"] / 1000));
|
||||
}
|
Loading…
Reference in New Issue