feat: add match live service helpers
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service\match;
|
||||
|
||||
use app\common\model\match\MatchEvent;
|
||||
use app\common\model\match\MatchLive;
|
||||
|
||||
class MatchLiveService
|
||||
{
|
||||
public static function syncLegacyLiveUrl(int $matchId): void
|
||||
{
|
||||
$row = MatchLive::where('match_id', $matchId)
|
||||
->order('create_time', 'asc')
|
||||
->order('id', 'asc')
|
||||
->find();
|
||||
|
||||
MatchEvent::where('id', $matchId)->update([
|
||||
'live_url' => $row ? (string) $row->source_url : '',
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getLiveListForApi(int $matchId): array
|
||||
{
|
||||
$rows = MatchLive::where('match_id', $matchId)
|
||||
->order('create_time', 'asc')
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($rows as &$row) {
|
||||
$row['stream_options'] = self::buildStreamOptions($row);
|
||||
$row['default_play_url'] = $row['stream_options'][0]['url'] ?? '';
|
||||
}
|
||||
unset($row);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function buildStreamOptions(array $row): array
|
||||
{
|
||||
$definitions = [
|
||||
['label' => 'M3U8', 'field' => 'play_url_m3u8'],
|
||||
['label' => 'HD M3U8', 'field' => 'play_url_hd_m3u8'],
|
||||
['label' => 'FLV', 'field' => 'play_url_flv'],
|
||||
['label' => 'HD FLV', 'field' => 'play_url_hd_flv'],
|
||||
];
|
||||
|
||||
$options = [];
|
||||
foreach ($definitions as $definition) {
|
||||
$url = trim((string) ($row[$definition['field']] ?? ''));
|
||||
if ($url === '') {
|
||||
continue;
|
||||
}
|
||||
$options[] = [
|
||||
'label' => $definition['label'],
|
||||
'url' => $url,
|
||||
];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user