Merge pull request #59523 from Dev-next-gen/fix/format-duplicate-only-stream

fix: rewrite playlists whose only streams were duplicates in playlist:format
This commit is contained in:
LPhilip1999
2026-11-22 14:35:08 +08:00
committed by GitHub
4 changed files with 23 additions and 4 deletions
+2 -4
View File
@@ -58,6 +58,7 @@ async function main() {
})
logger.info('removing duplicates...')
const filepaths = streams.map((stream: Stream) => stream.getFilepath()).uniq()
streams = streams.uniqBy(stream => stream.url)
logger.info('removing wrong id...')
@@ -115,11 +116,8 @@ async function main() {
logger.info('saving...')
const groupedStreams = streams.groupBy((stream: Stream) => stream.getFilepath())
for (const filepath of groupedStreams.keys()) {
for (const filepath of filepaths.all()) {
const streams = new Collection(groupedStreams.get(filepath))
if (streams.isEmpty()) return
const playlist = new Playlist(streams, { public: false, raw: true })
await streamsStorage.save(filepath, playlist.toString())
}
@@ -0,0 +1,5 @@
#EXTM3U
#EXTINF:-1 tvg-id="",Alpha (720p)
https://example.com/alpha.m3u8?a=1&b=2
#EXTINF:-1 tvg-id="",Bravo (720p)
https://example.com/bravo.m3u8
@@ -0,0 +1,3 @@
#EXTM3U
#EXTINF:-1 tvg-id="",Alpha (720p)
https://example.com/alpha.m3u8?b=2&a=1
+13
View File
@@ -71,6 +71,19 @@ describe('playlist:format', () => {
'http://example.com/index.m3u8?name=TV%2B&url=http%3A%2F%2Fexample.org%2Fa.m3u8%3Fk%3D1%26exp%3D2'
)
})
it('removes a duplicate that was the only stream in its file', () => {
fs.emptyDirSync('tests/__data__/output')
fs.copySync('tests/__data__/input/playlist_format_duplicates', 'tests/__data__/output/streams')
const cmd = `${ENV_VAR} npm run playlist:format`
execSync(cmd, { encoding: 'utf8' })
expect(content('tests/__data__/output/streams/a.m3u')).toContain(
'https://example.com/alpha.m3u8?a=1&b=2'
)
expect(content('tests/__data__/output/streams/b.m3u')).toBe('#EXTM3U\r\n')
})
})
function content(filepath: string) {