Last active
June 18, 2019 22:07
-
-
Save JohnMertz/93e47ebd92608339bd27245ae2e082c5 to your computer and use it in GitHub Desktop.
Start Music On Console Player and Force Active Input via HDMI-CEC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use JSON::XS; | |
# Checking for devices every time takes a few seconds, so store these | |
# settings in a file. Do so in /tmp so that it will be re-checked on reboot | |
my $tmp = '/tmp/cec-devices'; | |
my $json = JSON::XS->new(); | |
my $raw = ''; | |
my $settings; | |
my $address; | |
# If the devices list already exist, use it. | |
if ( -e $tmp ) { | |
open my $config, '<', $tmp; | |
while (<$config>) { | |
chomp; | |
$raw .= $_; | |
} | |
close $config; | |
$settings = $json->decode($raw); | |
# Else generate device list | |
} else { | |
open my $config, '>', $tmp; | |
my $cec = `echo scan | cec-client -s -d 1`; | |
my @lines = split(/\n/,$cec); | |
my $device; | |
foreach (@lines) { | |
if ($_ =~ m/^device /) { | |
$device = $_; | |
my $name = $_; | |
$device =~ s/^.*#//; | |
$device =~ s/:.*$//; | |
$name =~ s/.*:\s*//; | |
$settings->{$device}->{name} = $name; | |
} elsif ($_ =~ m/^\s*$/) { | |
$device = undef; | |
next; | |
} elsif (!defined $device) { | |
next; | |
} else { | |
my $key = $_; | |
my $value = $_; | |
$key =~ s/:.*//; | |
$value =~ s/.*:\s*//; | |
$settings->{$device}->{$key} = $value; | |
} | |
} | |
print $config $json->encode($settings); | |
close $config; | |
} | |
foreach my $device (keys %$settings) { | |
if ($settings->{$device}->{vendor} =~ m/Pulse/) { | |
$address = $settings->{$device}->{address}; | |
$address =~ s/(.)\.(.)\.(.)\.(.)/$1$2:$3$4/; | |
last; | |
} | |
} | |
system("echo \"tx 5f:82:$address\" | cec-client -s -d 1; mocp -p"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment