FHEM Forum

FHEM - Anwendungen => Multimedia => Thema gestartet von: topa_LE am 20 November 2020, 09:26:31

Titel: TVHeadend UTF-8 JSON Problem - API Schnittstelle manuell auslesen
Beitrag von: topa_LE am 20 November 2020, 09:26:31
Hallo,

bin gerade dabei die verfügbare API von TVHeadend zu nutzen. Da das bestehende Modul nicht mehr weiterentwickelt wird, wollte ich manuell per httpmod Modul die API's auslesen. Das bekannte JSON/UTF-8 Problem habe ich schon erkannt.

Über extractAllJSON attr bleibt es hängen, da in dem Wert Umlaute vorkommen. Auch einzelt wenn ich mit (reading10JSON reading10Name) die Werte einzeln auslesen möchte.

Das Modul z.B. nutzt:

use HttpUtils;
use utf8;
eval "use JSON;1" or my $JSON = "JSON";


Kann man nun in 99_myUtils eine Funktion einbauen, damit der Fehler:

error while parsing JSON data: malformed UTF-8 character in JSON string, at character offset 63 (before "\x{fffd}t","hostname...") at lib/FHEM/HTTPMOD/Utils.pm line 644

nicht kommt. Er steigt genau beim "state: Läuft" aus. Selbst wenn ich den Wert gar nicht definiert habe in FHEM.

Log:

{"entries":[{"id":1125,"start":1605856294,"errors":0,"state":"Läuft","hostname":"192.168.178.20","username":"admin","client":"VLC/3.0.11 LibVLC/3.0.11","title":"HTTP","channel":"ZDF HD","service":"Montage Technology M88DS3103 #0 : DVB-S #0/topaLE HD Free/11362H/ZDF HD","pids":[6100,6110,6120,6121,6122,6123,6130,6131],"profile":"pass","in":1942040,"out":1942040,"total_in":55021020,"total_out":55021020}],"totalCount":1}
2020.11.20 08:12:03 4: TV_Headend_Server_Abo_Stream_94: BodyDecode found charset header and set decoding to UTF-8 (bodyDecode was set to auto)
2020.11.20 08:12:03 4: TV_Headend_Server_Abo_Stream_94: BodyDecode is decoding the response body as UTF-8
2020.11.20 08:12:03 3: TV_Headend_Server_Abo_Stream_94: error while parsing JSON data: malformed UTF-8 character in JSON string, at character offset 63 (before "\x{fffd}t","hostname...") at lib/FHEM/HTTPMOD/Utils.pm line 644



List:

Internals:
BUSY       0
CFGFN     
DEF        http://user:passwort@192.168.178.94:9981/api/status/subscriptions
FUUID      5fb6d442-f33f-252b-73cc-4b15c68bb8aba436
Interval   60
MainURL    http://user:passwort@192.168.178.94:9981/api/status/subscriptions
ModuleVersion 4.0.12 - 24.10.2020
NAME       TV_Headend_Server_Abo_Stream_94
NOTIFYDEV  global
NR         53539
NTFY_ORDER 50-TV_Headend_Server_Abo_Stream_94
STATE      ???
   TYPE       HTTPMOD
   value     
   HttpUtils:
     NAME       
     addr       http://192.168.178.94:9981
     auth       1
     buf       
     code       200
     compress   1
     conn       
     data       
     displayurl http://user:passwort@192.168.178.94:9981/api/status/subscriptions
     header     
     host       192.168.178.94
     httpheader HTTP/1.0 200 OK
Server: tvheadend
Cache-Control: no-cache
Connection: Close
Content-Type: text/x-json; charset=UTF-8
Content-Length: 29
     httpversion 1.0
     hu_blocking 0
     hu_filecount 1
     hu_port    9981
     hu_portSfx :9981
     ignoreredirects 1
     loglevel   4
     path       /api/status/subscriptions
     protocol   http
     pwd        passwort
     redirects  0
     timeout    2
     url        http://user:passwort@192.168.178.94:9981/api/status/subscriptions
     user       user
     sslargs:
   QUEUE:
   READINGS:
   REQUEST:
     context    reading
     data       
     header     
     ignoreredirects 0
     num        0
     retryCount 0
     type       update
     url        http://user:passwort@192.168.178.94:9981/api/status/subscriptions
Attributes:
   DbLogExclude .*
   alias      TVHeadend Server - Abo Stream ( 94 )
   disable    1
   enableControlSet 1
   enableCookies 1
   getDecode  UTF-8
   group      TV Streaming Server
   icon       it_television
   reading10JSON entries_01_id
   reading10Name id_channel
   reading11JSON entries_01_hostname
   reading11Name hostadresse
   readingEncode UTF-8
   room       10-Arbeitszimmer
   userattr   getDecode reading10JSON reading10Name reading11JSON reading11Name reading12JSON reading12Name reading13JSON reading13Name reading14JSON reading14Name reading15JSON reading15Name reading16JSON reading16Name reading17JSON reading17Name reading18JSON reading18Name reading19JSON reading19Name readingEncode



Danke für den Denkanstoss.
Titel: Antw:TVHeadend UTF-8 JSON Problem - API Schnittstelle manuell auslesen
Beitrag von: topa_LE am 21 November 2020, 19:08:49
Keiner hier einen Lösungsansatz?

Nun gut, dann tüte ich das als unerledigt ein. Scheinbar doch nicht ganz so wichtig hier zu helfen.

Besten Dank trotzdem.
Titel: Antw:TVHeadend UTF-8 JSON Problem - API Schnittstelle manuell auslesen
Beitrag von: herrmannj am 21 November 2020, 19:33:18
Wenn es um JSON geht kannst du vmtl besser JsonMod verwenden.