From f3ef256bdfe4be794691b6c2fc39dd4dd22aff16 Mon Sep 17 00:00:00 2001 From: chen zhihao <2490284538@qq.com> Date: Fri, 4 Sep 2026 15:28:26 +0800 Subject: [PATCH] Restrict parsed stream quality suffixes (#49869) * fix: restrict parsed stream quality suffixes * test: reuse playlist export fixture for quality suffix --- scripts/models/stream.ts | 2 +- .../playlist_export/.api/streams.json | 28 +++++++++++++------ .../input/playlist_export/unsorted.m3u | 8 ++++-- tests/commands/playlist/export.test.ts | 1 + 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/scripts/models/stream.ts b/scripts/models/stream.ts index 9bc3fbff4a..a2fa172ee9 100644 --- a/scripts/models/stream.ts +++ b/scripts/models/stream.ts @@ -78,7 +78,7 @@ export class Stream extends sdk.Models.Stream { let title = name const [, label] = title.match(/ \[(.*)\]$/) || [null, ''] title = title.replace(new RegExp(` \\[${escapeRegExp(label)}\\]$`), '') - const [, quality] = title.match(/ \(([0-9]+[p|i])\)$/) || [null, ''] + const [, quality] = title.match(/ \(([0-9]+[pi])\)$/) || [null, ''] title = title.replace(new RegExp(` \\(${quality}\\)$`), '') return { title, label, quality } diff --git a/tests/__data__/expected/playlist_export/.api/streams.json b/tests/__data__/expected/playlist_export/.api/streams.json index fc0df498bc..92dbef6f8c 100644 --- a/tests/__data__/expected/playlist_export/.api/streams.json +++ b/tests/__data__/expected/playlist_export/.api/streams.json @@ -1,15 +1,25 @@ [ - { - "channel": null, - "feed": null, - "title": "Daawah TV", + { + "channel": null, + "feed": null, + "title": "Daawah TV", "url": "http://51.15.246.58:8081/daawahtv/daawahtv2/playlist.m3u8", "referrer": null, "user_agent": null, - "quality": null, - "label": null - }, - { + "quality": null, + "label": null + }, + { + "channel": null, + "feed": null, + "title": "Example (720|)", + "url": "https://example.com/live.m3u8", + "referrer": null, + "user_agent": null, + "quality": null, + "label": null + }, + { "channel": null, "feed": null, "title": "Andorra TV", @@ -79,4 +89,4 @@ "quality": "720p", "label": null } -] \ No newline at end of file +] diff --git a/tests/__data__/input/playlist_export/unsorted.m3u b/tests/__data__/input/playlist_export/unsorted.m3u index 96f9299e2d..f11e03cb17 100644 --- a/tests/__data__/input/playlist_export/unsorted.m3u +++ b/tests/__data__/input/playlist_export/unsorted.m3u @@ -1,9 +1,11 @@ #EXTM3U #EXTINF:-1 tvg-id="LDPRTV.ru",ЛДПР ТВ (1080p) http://46.46.143.222:1935/live/mp4:ldpr.stream/blocked.m3u8 -#EXTINF:-1 tvg-id="VisitXTV.nl",Visit-X TV -https://stream.visit-x.tv/vxtv/ngrp:live_all/30fps.m3u8 -#EXTINF:-1 tvg-id="" user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",Andorra TV (720p) [Not 24/7] +#EXTINF:-1 tvg-id="VisitXTV.nl",Visit-X TV +https://stream.visit-x.tv/vxtv/ngrp:live_all/30fps.m3u8 +#EXTINF:-1 tvg-id="",Example (720|) +https://example.com/live.m3u8 +#EXTINF:-1 tvg-id="" user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",Andorra TV (720p) [Not 24/7] #EXTVLCOPT:http-referrer=http://imn.iq #EXTVLCOPT:http-user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index2.m3u8 diff --git a/tests/commands/playlist/export.test.ts b/tests/commands/playlist/export.test.ts index 43f4c4b9e2..7026c0a55c 100644 --- a/tests/commands/playlist/export.test.ts +++ b/tests/commands/playlist/export.test.ts @@ -19,6 +19,7 @@ describe('playlist:export', () => { content('tests/__data__/expected/playlist_export/.api/streams.json') ) }) + }) function content(filepath: string) {