Revert to earlier HLS parsing logic.

This commit is contained in:
Buster Neece 2022-11-06 09:14:29 -06:00
parent 2d49556100
commit 2d168c00bb
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
3 changed files with 15 additions and 91 deletions

View File

@ -52,7 +52,6 @@
"league/flysystem-sftp-v3": "^3.0",
"league/mime-type-detection": "^1.7",
"league/plates": "^3.1",
"loophp/collection": "^6.0",
"lstrojny/fxmlrpc": "dev-master",
"marcw/rss-writer": "^0.4.0",
"matomo/device-detector": "^6",

74
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "97844b6342e82a1160846496db7f6981",
"content-hash": "1cbe0493b1bb2b62ab667d12fec4d738",
"packages": [
{
"name": "aws/aws-crt-php",
@ -3739,78 +3739,6 @@
},
"time": "2020-12-25T05:00:37+00:00"
},
{
"name": "loophp/collection",
"version": "6.0.3",
"source": {
"type": "git",
"url": "https://github.com/loophp/collection.git",
"reference": "7e22909259cd0804bc6e5be2754c7ff0c8ccb840"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/loophp/collection/zipball/7e22909259cd0804bc6e5be2754c7ff0c8ccb840",
"reference": "7e22909259cd0804bc6e5be2754c7ff0c8ccb840",
"shasum": ""
},
"require": {
"php": ">= 7.4"
},
"require-dev": {
"amphp/parallel-functions": "^1",
"doctrine/collections": "^1.6",
"drupol/php-conventions": "^5",
"friends-of-phpspec/phpspec-code-coverage": "^6.1",
"infection/infection": "^0.23.0 || ^0.24.0",
"infection/phpspec-adapter": "^0.1.2",
"phpspec/phpspec": "^7.1",
"phpstan/phpstan-strict-rules": "^1.0",
"psr/cache": "^1.0",
"symfony/cache": "^5"
},
"type": "library",
"autoload": {
"psr-4": {
"loophp\\collection\\": "./src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Pol Dellaiera",
"email": "pol.dellaiera@protonmail.com",
"homepage": "https://not-a-number.io",
"role": "author"
}
],
"description": "A (memory) friendly, easy, lazy and modular collection class.",
"homepage": "https://github.com/loophp/collection",
"keywords": [
"collection",
"generator",
"iterator",
"yield"
],
"support": {
"docs": "https://loophp-collection.rtfd.io",
"issues": "https://github.com/loophp/collection/issues",
"source": "https://github.com/loophp/collection"
},
"funding": [
{
"url": "https://github.com/drupol",
"type": "github"
},
{
"url": "https://www.paypal.me/drupol",
"type": "paypal"
}
],
"time": "2021-12-11T18:10:52+00:00"
},
{
"name": "lstrojny/fxmlrpc",
"version": "dev-master",

View File

@ -7,7 +7,6 @@ namespace App\Nginx;
use App\Entity\Station;
use Doctrine\ORM\EntityManagerInterface;
use JsonException;
use loophp\collection\Collection;
use NowPlaying\Result\Client;
use NowPlaying\Result\Result;
use Psr\Log\LoggerInterface;
@ -46,13 +45,6 @@ final class HlsListeners
return $np;
}
$logs = Collection::fromFile($hlsLogFile);
if (is_file($hlsLogBackup) && filemtime($hlsLogBackup) >= $timestamp) {
$logs = $logs->merge(
Collection::fromFile($hlsLogBackup)
);
}
$streamsByName = [];
$clientsByStream = [];
foreach ($hlsStreams as $hlsStream) {
@ -60,19 +52,24 @@ final class HlsListeners
$clientsByStream[$hlsStream->getName()] = 0;
}
$logs = $logs
->lines()
->reverse()
->map(fn($row) => $this->parseRow($row, $timestamp)) // @phpstan-ignore-line
->filter();
$allClients = [];
$i = 1;
/** @var Client $client */
foreach ($logs as $client) {
$logContents = file($hlsLogFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
if (is_file($hlsLogBackup) && filemtime($hlsLogBackup) >= $timestamp) {
$logContents = array_merge(
$logContents,
file($hlsLogBackup, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []
);
}
$logContents = array_reverse($logContents);
foreach ($logContents as $logRow) {
$client = $this->parseRow($logRow, $timestamp);
if (
isset($clientsByStream[$client->mount])
null !== $client
&& isset($clientsByStream[$client->mount])
&& !isset($allClients[$client->uid])
) {
$clientsByStream[$client->mount]++;