diff --git a/fhem/FHEM/70_XBMC.pm b/fhem/FHEM/70_XBMC.pm index 178721442..2cddd1ac3 100644 --- a/fhem/FHEM/70_XBMC.pm +++ b/fhem/FHEM/70_XBMC.pm @@ -340,6 +340,11 @@ sub XBMC_ResetMediaReadings($) readingsBulkUpdate($hash, "currentTrack", "" ); readingsEndUpdate($hash, 1); + + # delete streamdetails readings + # NOTE: we actually delete the readings (unlike the other readings) + # because they are stream count dependent + fhem("deletereading $hash->{NAME} sd_.*"); } sub XBMC_ResetPlayerReadings($) @@ -424,7 +429,7 @@ sub XBMC_PlayerOnPlay($$) "params" => { "movieid" => $obj->{params}->{data}->{item}->{id}, #http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6#Video.Fields.Movie - "properties" => ["title","file","year","originaltitle"] + "properties" => ["title","file","year","originaltitle","streamdetails"] }, "id" => $id }; @@ -579,7 +584,7 @@ sub XBMC_ProcessResponse($$) return undef; } -sub XBMC_is3DFile($$) { +sub XBMC_Is3DFile($$) { my ($hash, $filename) = @_; return ($filename =~ /([-. _]3d[-. _]|.*3dbd.*)/i); @@ -622,18 +627,31 @@ sub XBMC_CreateReading($$$) { elsif($key eq 'file') { $key = 'currentMedia'; - my $is3D = XBMC_is3DFile($hash, $value); - XBMC_CreateReading($hash, "3dfile", $is3D ? "on" : "off"); + readingsBulkUpdate($hash,'3dfile', XBMC_Is3DFile($hash, $value) ? "on" : "off"); } elsif($key =~ /(album|artist|track|title)/) { $key = 'current' . ucfirst($key); } + elsif($key eq 'streamdetails') { + foreach my $mediakey (keys %{$value}) { + my $arrRef = $value->{$mediakey}; + for (my $i = 0; $i <= $#$arrRef; $i++) { + my $propRef = $arrRef->[$i]; + foreach my $propkey (keys %{$propRef}) { + readingsBulkUpdate($hash, "sd_" . $mediakey . $i . $propkey, $propRef->{$propkey}); + } + } + } + + # we dont want to create a "streamdetails" reading + $key = undef; + } if(ref($value) eq 'ARRAY') { if(int(@$value)) { $value = join(',',@$value); } } - readingsBulkUpdate($hash,$key,$value); + readingsBulkUpdate($hash,$key,$value) if defined $key; } #Parses a given string and returns ($msg,$tail). If the string contains a complete message @@ -1487,6 +1505,7 @@ sub XBMC_HTTP_Request($$@)