forked from robotastic/trunk-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audioplayer.php
204 lines (185 loc) · 7.34 KB
/
audioplayer.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
$FileType = '.wav';
$system = (empty($_GET['system'])) ? NULL : $_GET['system'];
$date = (isset($_GET['date'])) ? new DateTimeImmutable($_GET['date']) : new DateTimeImmutable();
$tg = (empty($_GET['tg'])) ? NULL : $_GET['tg'];
$CONFIG = (function (string $configFilePath = './config.json') {
if (!file_exists($configFilePath))
return false;
return json_decode(file_get_contents($configFilePath));
})();
$TGFile = function (string $tgFilePath): array {
$return = [];
if (!file_exists($tgFilePath))
return $return;
foreach (file($tgFilePath) as $line) {
[$DEC, $HEX, $Mode, $AlphaTag, $Description, $Tag, $Group, $Priority] = str_getcsv($line);
$return[$DEC] = $AlphaTag;
}
return $return;
};
$TGS = [];
foreach ($CONFIG->systems as $system) {
$TGS += $TGFile($system->talkgroupsFile);
}
$MHz = function (float $MHz): string {
switch (TRUE) {
case $MHz >= 136 AND $MHz <= 174:
return 'text-primary'; # VHF
case $MHz >= 380 AND $MHz <= 520:
return 'text-danger'; # UHF
case $MHz >= 764 AND $MHz <= 870:
return 'text-warning'; # 700
case $MHz >= 896 AND $MHz <= 901:
case $MHz >= 935 AND $MHz <= 940:
return 'text-success'; # 800
default:
return 'null';
}
};
$files = [];
try {
foreach (new DirectoryIterator("{$CONFIG->captureDir}/{$date->format('Y/n/j')}/") as $file) {
$EXT = '.' . $file->getExtension();
if ($EXT != $FileType)
continue;
$Basename = $file->getBasename($EXT);
[$TGID, $TIME, $FREQ] = preg_split('/[-_]/', $Basename);
if ($TGID != $tg AND $tg !== NULL)
continue;
if ($file->getSize() < 1024)
continue; # Filtered because they will produce an error when attempting playback.
$files[$file->getMTime()] = [$Basename, round($file->getSize() / 1024), $TGID, $TIME, $FREQ / 1000000];
}
ksort($files);
} catch (UnexpectedValueException $e) {
$error = 'No directory found for that date.';
}
$path = substr(realpath($CONFIG->captureDir), strlen($_SERVER['DOCUMENT_ROOT']));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover">
<title>Trunk Player</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div id="interface">
<form method="get">
<div class="row">
<div class="form-group col-lg-4">
<label class="form-control-label" for="date">Date</label>
<input class="form-control" id="date" name="date" type="date" value="<?=$date->format('Y-m-d')?>" />
</div>
<div class="form-group col-lg-4">
<label class="form-control-label" for="tg">Talk Group</label>
<select class="form-control" id="tg" name="tg">
<option value="">All Calls</option>
<?php foreach ($TGS as $TGID => $TGName): ?>
<option value="<?=$TGID?>"<?=($tg == $TGID) ? ' selected="selected"' : ''?>><?=$TGName?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-lg-4">
<label class="form-control-label">Controls</label>
<button class="btn btn-outline-success btn-block" type="submit">View</button>
</div>
</div>
</form>
<div class="row">
<div class="form-group col-lg-12">
<audio preload="none" controls>
Sorry, your browser does not support HTML5 audio.
</audio>
</div>
<div class="form-group col-lg-12">Click on a row to begin sequential playback, click file size to download</div>
</div>
</div>
<table class="table">
<thead>
<tr>
<td>Time</td>
<td>Talk Group</td>
<td>MHz</td>
<td>Size</td>
</tr>
</thead>
<tbody>
<?php if (isset($error)): ?>
<tr>
<th colspan="4"><?=$error?></th>
</tr>
<?php endif; ?>
<?php foreach ($files as $FileTime => [$FileName, $FileSize, $TGID, $TIME, $FREQ]): ?>
<tr>
<td><?=date("H:i:s", $FileTime)?></td>
<td><?=($TGS[$TGID]) ?? $TGID?></td>
<td class="<?=$MHz($FREQ)?>"><?=sprintf("%3.4f", $FREQ)?></td>
<td><a href="<?="{$path}/{$date->format('Y/n/j')}/{$FileName}{$FileType}"?>"><?=$FileSize?>k</a></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<script>
window.onload = _ => {
var index = null,
sources = document.querySelector('source'),
audio = document.querySelector('audio'),
list = document.querySelector('tbody'),
tr = [...list.getElementsByTagName('tr')];
list.addEventListener('click', e => {
if (tr[index])
tr[index].classList.toggle('bg-secondary');
tr.forEach((thisRow, i) => {
if (e.target.parentElement == thisRow) {
index = i;
tr[index].classList.toggle('bg-secondary');
}
});
audio.src = tr[index].querySelector('a');
audio.load();
audio.play().catch(error => {
console.log(`${error.name}: ${error.message}`);
});
}, false);
audio.addEventListener('ended', _ => {
tr[index++].classList.toggle('bg-secondary');
if (tr[index])
tr[index].click();
}, false);
}
</script>
<style>
html, body {
background: #012;
color: #FFF;
}
#interface, audio {
width: 100%;
}
table {
text-align: center;
}
input, select, textarea {
color: #fff !important;
background-color: #1a1c22 !important;
border-color: #434857 !important;
}
tbody tr {
cursor: pointer;
}
a {
color: #FA0;
}
a:hover {
color: #FC0;
}
a:active {
color: #FF0;
}
</style>
</body>
</html>