1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00
xiaochong0302 e711a3ef50 1.Response增加unauthorized响应
2.open_avatar字段增加长度为255
3.清理无用的代码
2024-04-10 19:01:58 +08:00

109 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services;
use App\Repos\Chapter as ChapterRepo;
use App\Services\Vod as VodService;
class ChapterVod extends Service
{
public function getPlayUrls($chapterId)
{
$chapterRepo = new ChapterRepo();
$vod = $chapterRepo->findChapterVod($chapterId);
/**
* 腾讯云点播优先
*/
if ($vod->file_id) {
$playUrls = $this->getCosPlayUrls($chapterId);
} else {
$playUrls = $this->getRemotePlayUrls($chapterId);
}
/**
*过滤播放地址为空的条目
*/
foreach ($playUrls as $key => $value) {
if (empty($value['url'])) unset($playUrls[$key]);
}
return $playUrls;
}
public function getCosPlayUrls($chapterId)
{
$chapterRepo = new ChapterRepo();
$vod = $chapterRepo->findChapterVod($chapterId);
if (empty($vod->file_transcode)) return [];
$vodService = new VodService();
$result = [];
foreach ($vod->file_transcode as $file) {
$file['url'] = $vodService->getPlayUrl($file['url']);
$type = $this->getDefinitionType($file['height']);
$result[$type] = $file;
}
return $result;
}
public function getRemotePlayUrls($chapterId)
{
$chapterRepo = new ChapterRepo();
$vod = $chapterRepo->findChapterVod($chapterId);
$result = [
'hd' => ['url' => ''],
'sd' => ['url' => ''],
'fd' => ['url' => ''],
];
if (!empty($vod->file_remote)) {
$result = $vod->file_remote;
}
return $result;
}
protected function getDefinitionType($height)
{
$default = 'sd';
$vodTemplates = $this->getVodTemplates();
/**
* 腾讯云播放器只支持[od|hd|sd]遇到fd替换为od
*/
foreach ($vodTemplates as $key => $template) {
if ($height >= $template['height']) {
return $key == 'fd' ? $default : $key;
}
}
return $default;
}
protected function getVodTemplates()
{
return [
'hd' => ['height' => 1080, 'rate' => 2500],
'sd' => ['height' => 720, 'rate' => 1800],
'fd' => ['height' => 540, 'rate' => 1000],
];
}
}