mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
70_KODI: added channel name resolution and openchannel command
git-svn-id: https://svn.fhem.de/fhem/trunk@20146 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a0ee4d5326
commit
8889804b9a
@ -1,5 +1,8 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 70_KODI: Added fetching of channel names and command openchannel to
|
||||||
|
open channel by names. Channel IDs will be converted
|
||||||
|
automatically.
|
||||||
- feature: 93_DbRep: SQL Wildcard (%) usage possible as placeholder in a
|
- feature: 93_DbRep: SQL Wildcard (%) usage possible as placeholder in a
|
||||||
reading- or device-list. Forum: #101756,
|
reading- or device-list. Forum: #101756,
|
||||||
internal code changes of SQL statement generation
|
internal code changes of SQL statement generation
|
||||||
|
@ -109,6 +109,7 @@ sub KODI_Initialize($$)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
$hash->{DefFn} = "KODI_Define";
|
$hash->{DefFn} = "KODI_Define";
|
||||||
$hash->{SetFn} = "KODI_Set";
|
$hash->{SetFn} = "KODI_Set";
|
||||||
|
$hash->{GetFn} = "KODI_Get";
|
||||||
$hash->{ReadFn} = "KODI_Read";
|
$hash->{ReadFn} = "KODI_Read";
|
||||||
$hash->{ReadyFn} = "KODI_Ready";
|
$hash->{ReadyFn} = "KODI_Ready";
|
||||||
$hash->{UndefFn} = "KODI_Undefine";
|
$hash->{UndefFn} = "KODI_Undefine";
|
||||||
@ -242,6 +243,7 @@ sub KODI_OnConnect($)
|
|||||||
$hash->{LAST_RECV} = time();
|
$hash->{LAST_RECV} = time();
|
||||||
|
|
||||||
KODI_Update($hash);
|
KODI_Update($hash);
|
||||||
|
KODI_PvrUpdateChannels($hash);
|
||||||
|
|
||||||
KODI_QueueIntervalUpdate($hash);
|
KODI_QueueIntervalUpdate($hash);
|
||||||
|
|
||||||
@ -644,6 +646,30 @@ sub KODI_PlayerOnPlay($$)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub KODI_Get($@) {
|
||||||
|
my ( $hash, $name, $cmd, @args ) = @_;
|
||||||
|
|
||||||
|
return 'Module disabled!' if AttrVal($hash->{NAME}, 'disable', 0);
|
||||||
|
|
||||||
|
if ($cmd eq "update_channels") {
|
||||||
|
KODI_PvrUpdateChannels($hash);
|
||||||
|
}
|
||||||
|
elsif ($cmd eq "channelid") {
|
||||||
|
if ( !defined( $args[0] ) ) {
|
||||||
|
my $msg = "$hash->{NAME} channelid requires channel name parameter";
|
||||||
|
Log3( $hash, 3, $msg );
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $channel = join(" ", @args);
|
||||||
|
return KODI_PvrGetChannelId($hash, $channel);
|
||||||
|
} else {
|
||||||
|
return "Unknown command '$cmd', choose one of update_channels:noArg channelid";
|
||||||
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
sub KODI_ProcessNotification($$)
|
sub KODI_ProcessNotification($$)
|
||||||
{
|
{
|
||||||
my ($hash,$obj) = @_;
|
my ($hash,$obj) = @_;
|
||||||
@ -778,27 +804,50 @@ sub KODI_ProcessResponse($$)
|
|||||||
KODI_Call($hash,$cmd,1);
|
KODI_Call($hash,$cmd,1);
|
||||||
}
|
}
|
||||||
delete $hash->{PendingPlayerCMDs}{$id};
|
delete $hash->{PendingPlayerCMDs}{$id};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# this is for handling other responses like responses to Application.GetProperties etc.
|
# this is for handling other responses like responses to Application.GetProperties etc.
|
||||||
my $result = $obj->{result};
|
my $result = $obj->{result};
|
||||||
if($result && ref $result eq "HASH") {
|
if($result && ref $result eq "HASH") {
|
||||||
Log3($name, 4, "$name: KODI_ProcessResponse: updating readings");
|
if(exists($obj->{result}->{channelgroups})) {
|
||||||
readingsBeginUpdate($hash);
|
Log3($name, 4, "$name: KODI_ProcessResponse: received channelgroups information");
|
||||||
foreach my $key (keys %$result) {
|
readingsBeginUpdate($hash);
|
||||||
if ($key eq 'item') {
|
foreach my $cg (@{$obj->{result}->{channelgroups}}) {
|
||||||
my $item = $obj->{result}->{item};
|
my $cgid = $cg->{channelgroupid};
|
||||||
foreach my $ikey (keys %$item) {
|
readingsBulkUpdate($hash, "channelgroup_${cgid}_type", $cg->{channeltype});
|
||||||
my $value = $item->{$ikey};
|
readingsBulkUpdate($hash, "channelgroup_${cgid}_label", $cg->{label});
|
||||||
KODI_CreateReading($hash,$ikey,$value);
|
|
||||||
|
KODI_PvrGetChannels($hash, $cgid);
|
||||||
|
}
|
||||||
|
readingsEndUpdate($hash, 1);
|
||||||
|
}
|
||||||
|
elsif(exists($obj->{result}->{channels})) {
|
||||||
|
Log3($name, 4, "$name: KODI_ProcessResponse: received channels information");
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
foreach my $c (@{$obj->{result}->{channels}}) {
|
||||||
|
my $cid = $c->{channelid};
|
||||||
|
readingsBulkUpdate($hash, "channel_${cid}", $c->{label});
|
||||||
|
}
|
||||||
|
readingsEndUpdate($hash, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log3($name, 4, "$name: KODI_ProcessResponse: updating readings");
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
foreach my $key (keys %$result) {
|
||||||
|
if ($key eq 'item') {
|
||||||
|
my $item = $obj->{result}->{item};
|
||||||
|
foreach my $ikey (keys %$item) {
|
||||||
|
my $value = $item->{$ikey};
|
||||||
|
KODI_CreateReading($hash,$ikey,$value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $value = $result->{$key};
|
||||||
|
KODI_CreateReading($hash,$key,$value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
readingsEndUpdate($hash, 1);
|
||||||
my $value = $result->{$key};
|
|
||||||
KODI_CreateReading($hash,$key,$value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
readingsEndUpdate($hash, 1);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3($name, 5, "$name: KODI_ProcessResponse: ignoring response: $result");
|
Log3($name, 5, "$name: KODI_ProcessResponse: ignoring response: $result");
|
||||||
@ -977,6 +1026,17 @@ sub KODI_Set($@)
|
|||||||
elsif($cmd eq 'openepisodeid') {
|
elsif($cmd eq 'openepisodeid') {
|
||||||
return KODI_Set_Open($hash, 'episode', @args);
|
return KODI_Set_Open($hash, 'episode', @args);
|
||||||
}
|
}
|
||||||
|
elsif($cmd eq 'openchannel') {
|
||||||
|
my $channel = join(' ', @args);
|
||||||
|
my $cid = KODI_PvrGetChannelId($hash, $channel);
|
||||||
|
if ($cid == -1) {
|
||||||
|
my $msg = "Could not find channel $channel";
|
||||||
|
Log3($name, 4, "$name: KODI_Set: $msg");
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
@args = ($cid);
|
||||||
|
return KODI_Set_Open($hash, 'channel', @args);
|
||||||
|
}
|
||||||
elsif($cmd eq 'openchannelid') {
|
elsif($cmd eq 'openchannelid') {
|
||||||
return KODI_Set_Open($hash, 'channel', @args);
|
return KODI_Set_Open($hash, 'channel', @args);
|
||||||
}
|
}
|
||||||
@ -1121,7 +1181,7 @@ sub KODI_Set($@)
|
|||||||
my $res = "Unknown argument " . $cmd . ", choose one of " .
|
my $res = "Unknown argument " . $cmd . ", choose one of " .
|
||||||
"off play:all,audio,video,picture playpause:all,audio,video,picture pause:all,audio,video,picture " .
|
"off play:all,audio,video,picture playpause:all,audio,video,picture pause:all,audio,video,picture " .
|
||||||
"prev:all,audio,video,picture next:all,audio,video,picture goto stop:all,audio,video,picture " .
|
"prev:all,audio,video,picture next:all,audio,video,picture goto stop:all,audio,video,picture " .
|
||||||
"open opendir openmovieid openepisodeid openchannelid addon shuffle:toggle,on,off repeat:one,all,off volumeUp:noArg volumeDown:noArg " .
|
"open opendir openmovieid openepisodeid openchannel openchannelid addon shuffle:toggle,on,off repeat:one,all,off volumeUp:noArg volumeDown:noArg " .
|
||||||
"seek back:noArg contextmenu:noArg down:noArg home:noArg info:noArg left:noArg " .
|
"seek back:noArg contextmenu:noArg down:noArg home:noArg info:noArg left:noArg " .
|
||||||
"right:noArg select:noArg send exec:left,right," .
|
"right:noArg select:noArg send exec:left,right," .
|
||||||
"up,down,pageup,pagedown,select,highlight,parentdir,parentfolder,back," .
|
"up,down,pageup,pagedown,select,highlight,parentdir,parentfolder,back," .
|
||||||
@ -1416,6 +1476,59 @@ sub KODI_PlayerCommand($$$)
|
|||||||
return KODI_Call($hash,$req,1);
|
return KODI_Call($hash,$req,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub KODI_PvrUpdateChannels($)
|
||||||
|
{
|
||||||
|
my ($hash) = @_;
|
||||||
|
fhem("deletereading $hash->{NAME} channel_.*", 1);
|
||||||
|
fhem("deletereading $hash->{NAME} channelgroup_.*", 1);
|
||||||
|
|
||||||
|
KODI_PvrGetChannelGroups($hash, "tv");
|
||||||
|
KODI_PvrGetChannelGroups($hash, "radio");
|
||||||
|
}
|
||||||
|
|
||||||
|
sub KODI_PvrGetChannelGroups($$)
|
||||||
|
{
|
||||||
|
my ($hash,$type) = @_;
|
||||||
|
|
||||||
|
my $id = KODI_CreateId($hash);
|
||||||
|
my $req = {
|
||||||
|
'method' => 'PVR.GetChannelGroups',
|
||||||
|
'params' => { 'channeltype' => $type },
|
||||||
|
'id' => $id
|
||||||
|
};
|
||||||
|
return KODI_Call($hash,$req,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub KODI_PvrGetChannels($$)
|
||||||
|
{
|
||||||
|
my ($hash,$channelGroupId) = @_;
|
||||||
|
|
||||||
|
my $id = KODI_CreateId($hash);
|
||||||
|
my $req = {
|
||||||
|
'method' => 'PVR.GetChannels',
|
||||||
|
'params' => { 'channelgroupid' => $channelGroupId + 0 },
|
||||||
|
'id' => $id
|
||||||
|
};
|
||||||
|
return KODI_Call($hash,$req,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub KODI_PvrGetChannelId($$) {
|
||||||
|
my ($hash, $channelname) = @_;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $cid=1;
|
||||||
|
|
||||||
|
Log3($name, 4, "$name: KODI_PvrGetChannelId: $channelname");
|
||||||
|
|
||||||
|
my $readings = $defs{$name}{READINGS};
|
||||||
|
foreach my $rname (sort keys %{$readings}) {
|
||||||
|
next if (rindex($rname, "channel_", 0) < 0);
|
||||||
|
my $curname = ReadingsVal($name, $rname, undef);
|
||||||
|
return (split /_/, $rname)[1] if ($curname eq $channelname);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#returns 'toggle' if the argument is undef
|
#returns 'toggle' if the argument is undef
|
||||||
#returns JSON::true if the argument is true and not equals "off" otherwise it returns JSON::false
|
#returns JSON::true if the argument is true and not equals "off" otherwise it returns JSON::false
|
||||||
sub KODI_Toggle($)
|
sub KODI_Toggle($)
|
||||||
@ -1684,7 +1797,14 @@ sub KODI_HTTP_Request($$@)
|
|||||||
is a issue of Kodi. The fix of this bug is included in future version of Kodi (> 12.2).
|
is a issue of Kodi. The fix of this bug is included in future version of Kodi (> 12.2).
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
<a name="KODIget"></a>
|
||||||
|
<b>Get</b>
|
||||||
|
<ul>
|
||||||
|
<li><b>update_channels</b> - fetches all channel groups and all channels from Kodi. The readings "channel_..." and "channelgroup_..." will be filled. Channels will also be automatically updated when the connection is established.</li>
|
||||||
|
<li><b>channelid [<channel_name>]</b> - resolves a channel name and returns its ID. Returns -1 for unknown channels.</li>
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
<a name="KODIset"></a>
|
<a name="KODIset"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
<ul>
|
<ul>
|
||||||
@ -1707,6 +1827,7 @@ sub KODI_HTTP_Request($$@)
|
|||||||
<li><b>opendir <path></b> - Plays the content of the directory</li>
|
<li><b>opendir <path></b> - Plays the content of the directory</li>
|
||||||
<li><b>openmovieid <path></b> - Plays a movie by id</li>
|
<li><b>openmovieid <path></b> - Plays a movie by id</li>
|
||||||
<li><b>openepisodeid <path></b> - Plays an episode by id</li>
|
<li><b>openepisodeid <path></b> - Plays an episode by id</li>
|
||||||
|
<li><b>openchannel <path></b> - Switches to channel by name.</li>
|
||||||
<li><b>openchannelid <path></b> - Switches to channel by id</li>
|
<li><b>openchannelid <path></b> - Switches to channel by id</li>
|
||||||
<li><b>addon <addonid> <parametername> <parametervalue></b> - Executes addon with one Parameter, for example set kodi addon script.json-cec command activate</li>
|
<li><b>addon <addonid> <parametername> <parametervalue></b> - Executes addon with one Parameter, for example set kodi addon script.json-cec command activate</li>
|
||||||
<li><b>seek <hh:mm:ss></b> - seek to the specified time</li>
|
<li><b>seek <hh:mm:ss></b> - seek to the specified time</li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user