-
Notifications
You must be signed in to change notification settings - Fork 0
/
Squeezelite.pm
155 lines (120 loc) · 3.46 KB
/
Squeezelite.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl
# $Id$
#
# WEB INTERFACE and Controll application for an headless squeezelite
# installation.
#
# Best used with Squeezelite-R2
# (https://github.com/marcoc1712/squeezelite/releases)
#
# Copyright 2016 Marco Curti, marcoc1712 at gmail dot com.
# Please visit www.marcoc1712.it
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
################################################################################
package Squeezelite;
use strict;
use warnings;
use utf8;
use Utils;
sub new{
my $class = shift;
my $status = shift;
my $self = bless {
_status => $status,
}, $class;
return $self;
}
sub getStatus{
my $self = shift;
return $self->{_status};
}
################################################################################
# tobe overidden
#
sub getUtils{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub getSettings{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub isInstalled{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub isR2Installed{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub getVersion{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub auto {
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub install{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub upgrade{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub uninstall{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
################################################################################
#privates
#
sub _checkVersion{
my $self = shift;
my $squeezelitePath = shift;
my $command = "$squeezelitePath -t";
my ($err, @answ)= $self->getUtils()->executeCommand($command);
if ($err){
$self->getStatus()->record($command,7, $err,(join "/n", @answ));
return;
}
if (scalar(@answ) == 0) {
# TODO check the eerror with a second call.
#To capture a command's STDERR but discard its STDOUT
#$output = `cmd 2>&1 1>/dev/null`;
$self->getStatus()->record($command,7, "unable to run ".$command,(join "/n", @answ));
return undef;
}
for my $row (@answ){
$row=$self->getUtils()->trim($row);
#look for R2 version tag
#if (lc($row) =~ /v1\.8\...\(r2\)/){ #}
if (lc($row) =~ /v\s*\d{1,2}\.\d{1,2}\.\d{1,2}\s*\(r2\)/){
my $version =substr($row, index(lc($row),$&));
$self->getStatus()->record($command,1, $version,(join "/n", @answ));
return substr($row, index(lc($row),$&), length($&));
}
}
$self->getStatus()->record($command,1, 'undef' ,(join "/n", @answ));
return undef;
}
1;