mirror of
https://github.com/iptv-org/iptv.git
synced 2026-11-25 17:51:16 +02:00
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:
@@ -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
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user