forked from robotastic/trunk-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudioplayer.php
187 lines (167 loc) · 7.41 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
<?php
$FileType = '.m4a';
$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;
};
foreach ($CONFIG->systems as $system) {
$SHORTNAME = "{$system->shortName}";
$TGS[$SHORTNAME] = [];
$TGS[$SHORTNAME] += $TGFile($system->talkgroupsFile);
}
$files = [];
try {
foreach ($CONFIG->systems as $system) {
$SHORTNAME = "{$system->shortName}";
foreach (new DirectoryIterator("{$CONFIG->captureDir}/$SHORTNAME/{$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[$TIME . $FREQ] = [$Basename, round($file->getSize() / 1024), $TGID, $TIME, $FREQ / 1000000, $SHORTNAME];
}
}
ksort($files);
} catch (UnexpectedValueException $e) {
$error = 'No directory found for that date.';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="format-detection" content="telephone=no">
<title>Trunk Player</title>
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.0/flatly/bootstrap.min.css" rel="stylesheet" integrity="sha384-mhpbKVUOPCSocLzx2ElRISIORFRwr1ZbO9bAlowgM5kO7hnpRBe+brVj8NNPUiFs" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.0/flatly/bootstrap.min.css" rel="stylesheet" integrity="sha384-mhpbKVUOPCSocLzx2ElRISIORFRwr1ZbO9bAlowgM5kO7hnpRBe+brVj8NNPUiFs" crossorigin="anonymous" media="(prefers-color-scheme: light)">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.0/darkly/bootstrap.min.css" rel="stylesheet" integrity="sha384-Bo21yfmmZuXwcN/9vKrA5jPUMhr7znVBBeLxT9MA4r2BchhusfJ6+n8TLGUcRAtL" crossorigin="anonymous" media="(prefers-color-scheme: dark)">
<style>
#interface, audio {
width: 100%;
}
table {
text-align: center;
}
</style>
</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 ($CONFIG->systems as $system) {
$SHORTNAME = "{$system->shortName}";
foreach ($TGS[$SHORTNAME] 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-primary btn-block" type="submit">Filter</button>
</div>
</div>
</form>
<div class="row">
<div class="form-group col-lg-12"><button class="btn btn-primary btn-block" onclick="window.scrollTo(0,document.body.scrollHeight);">Jump to bottom</button>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, $SHORTNAME]): ?>
<tr>
<td><?=date("H:i:s", $TIME)?></td>
<td><?=($TGS[$SHORTNAME][$TGID]) ?? $TGID?></td>
<td><?=sprintf("%3.4f", $FREQ)?></td>
<td><a href="<?="{$CONFIG->captureDir}/{$SHORTNAME}/{$date->format('Y/n/j')}/{$FileName}{$FileType}"?>"><?=$FileSize?>k</a></td>
</tr>
<?php endforeach; ?>
</table>
<br />
<br />
<br />
<br />
<nav class="navbar fixed-bottom navbar-expand-sm navbar-dark bg-primary">
<audio preload="none" controls>
Sorry, your browser does not support HTML5 audio.
</audio>
</nav>
</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('table-active');
tr.forEach((thisRow, i) => {
if (e.target.parentElement == thisRow) {
index = i;
tr[index].classList.toggle('table-active');
}
});
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('table-active');
if (tr[index])
tr[index].click();
}, false);
}
</script>
</body>
</html>