mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-08 22:36:37 +08:00
优化播放体验
优化播放体验
This commit is contained in:
@@ -86,6 +86,21 @@ func playableSTRMTarget(ctx context.Context, repo *repository.Container, raw str
|
|||||||
return STRMPlaybackEnabled(ctx, repo)
|
return STRMPlaybackEnabled(ctx, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isStrmMediaRow 判断媒体行是否为 .strm(远程直链)媒体:STRMURL 非空、
|
||||||
|
// container=strm 或路径以 .strm 结尾。strm 媒体只能直连播放,禁止转码。
|
||||||
|
func isStrmMediaRow(m *model.Media) bool {
|
||||||
|
if m == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(m.STRMURL) != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if strings.EqualFold(strings.TrimSpace(m.Container), "strm") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return strings.HasSuffix(strings.ToLower(strings.TrimSpace(m.Path)), ".strm")
|
||||||
|
}
|
||||||
|
|
||||||
func isHTTPPlaybackTarget(raw string) bool {
|
func isHTTPPlaybackTarget(raw string) bool {
|
||||||
u, err := url.Parse(strings.TrimSpace(raw))
|
u, err := url.Parse(strings.TrimSpace(raw))
|
||||||
if err != nil || u == nil || !u.IsAbs() {
|
if err != nil || u == nil || !u.IsAbs() {
|
||||||
|
|||||||
@@ -101,6 +101,12 @@ func (t *TranscoderService) EnsureJob(ctx context.Context, mediaID string) (stri
|
|||||||
if m == nil {
|
if m == nil {
|
||||||
return "", ErrMediaNotFound
|
return "", ErrMediaNotFound
|
||||||
}
|
}
|
||||||
|
// .strm 媒体(STRMURL 或 container=strm / *.strm 路径)的内容是远程
|
||||||
|
// 直链文本,ffmpeg 无法读取,转码必然失败且白白消耗资源。直接拒绝
|
||||||
|
// 转码,迫使播放器走 /api/stream 302 直连播放。
|
||||||
|
if isStrmMediaRow(m) {
|
||||||
|
return "", ErrTranscodeDisabled
|
||||||
|
}
|
||||||
if _, err := os.Stat(m.Path); err != nil {
|
if _, err := os.Stat(m.Path); err != nil {
|
||||||
return "", ErrMediaNotFound
|
return "", ErrMediaNotFound
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ export function pickPlayerMode(media: Media): PlayerMode {
|
|||||||
|
|
||||||
export function needsTranscodeForBrowser(media: Media): boolean {
|
export function needsTranscodeForBrowser(media: Media): boolean {
|
||||||
const container = (media.container ?? '').toLowerCase()
|
const container = (media.container ?? '').toLowerCase()
|
||||||
|
// .strm 媒体内容是远程直链(服务端 302 到播放 CDN 或反向代理),
|
||||||
|
// 浏览器直接播放该远程流即可,转码无意义且必然失败(ffmpeg 无法读取
|
||||||
|
// 文本 strm),恒走 direct play。
|
||||||
|
if (container.includes('strm') || String(media.strm_url ?? '').trim() !== '') return false
|
||||||
const videoCodec = (media.video_codec ?? '').toLowerCase()
|
const videoCodec = (media.video_codec ?? '').toLowerCase()
|
||||||
const audioCodec = (media.audio_codec ?? '').toLowerCase()
|
const audioCodec = (media.audio_codec ?? '').toLowerCase()
|
||||||
const containerOK = directContainers.some((item) => container.includes(item))
|
const containerOK = directContainers.some((item) => container.includes(item))
|
||||||
|
|||||||
Reference in New Issue
Block a user