fix: tolerate missing playlist metadata (#49868)

This commit is contained in:
chen zhihao authored and GitHub committed 2026-09-04 17:12:25 +02:00
1 parent 2f83f28352
commit 9652409093
3 files changed
+16 -4

No files matched your search

+5 -4
View File
@@ -87,7 +87,8 @@ export class Stream extends sdk.Models.Stream {
if (!data.name) throw new Error('"name" property is required') if (!data.name) throw new Error('"name" property is required')
if (!data.url) throw new Error('"url" property is required') if (!data.url) throw new Error('"url" property is required')
const [channelId, feedId] = data.tvg.id.split('@') const tvgId = data.tvg?.id || ''
const [channelId, feedId] = tvgId.split('@')
const { title, label, quality } = parseName(data.name) const { title, label, quality } = parseName(data.name)
const stream = new Stream({ const stream = new Stream({
@@ -96,12 +97,12 @@ export class Stream extends sdk.Models.Stream {
title: title, title: title,
quality: quality || null, quality: quality || null,
url: data.url, url: data.url,
referrer: data.http.referrer || null, referrer: data.http?.referrer || null,
user_agent: data.http['user-agent'] || null, user_agent: data.http?.['user-agent'] || null,
label: label || null label: label || null
}) })
stream.tvgId = data.tvg.id stream.tvgId = tvgId
stream.line = data.line stream.line = data.line
return stream return stream
@@ -0,0 +1,3 @@
#EXTM3U
#EXTINF:-1,Example
https://example.com/live.m3u8
+8
View File
@@ -101,4 +101,12 @@ describe('playlist:validate', () => {
const stdout = execSync(cmd, { encoding: 'utf8' }) const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout) if (process.env.DEBUG === 'true') console.log(cmd, stdout)
}) })
it('accepts a playlist without optional metadata attributes', () => {
const cmd = `${ENV_VAR} npm run playlist:validate -- missing_metadata.m3u`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(stdout).toContain('missing_metadata.m3u')
expect(stdout).toContain('is missing a channel ID')
})
}) })