mirror of
https://github.com/iptv-org/iptv
synced 2026-09-09 05:17:04 -04:00
fix: preserve nested playlist paths when formatting
This commit is contained in:
@@ -4,11 +4,10 @@ import { Stream, Playlist } from '../../models'
|
|||||||
import { Storage } from '@freearhey/storage-js'
|
import { Storage } from '@freearhey/storage-js'
|
||||||
import { STREAMS_DIR } from '../../constants'
|
import { STREAMS_DIR } from '../../constants'
|
||||||
import { PlaylistParser } from '../../core'
|
import { PlaylistParser } from '../../core'
|
||||||
import { getStreamInfo } from '../../utils'
|
import { getStoragePath, getStreamInfo } from '../../utils'
|
||||||
import { loadData, data } from '../../api'
|
import { loadData, data } from '../../api'
|
||||||
import cliProgress from 'cli-progress'
|
import cliProgress from 'cli-progress'
|
||||||
import { eachLimit } from 'async'
|
import { eachLimit } from 'async'
|
||||||
import path from 'node:path'
|
|
||||||
import os from 'node:os'
|
import os from 'node:os'
|
||||||
|
|
||||||
program
|
program
|
||||||
@@ -42,7 +41,7 @@ async function main() {
|
|||||||
storage: streamsStorage
|
storage: streamsStorage
|
||||||
})
|
})
|
||||||
let files = program.args.length ? program.args : await streamsStorage.list('**/*.m3u')
|
let files = program.args.length ? program.args : await streamsStorage.list('**/*.m3u')
|
||||||
files = files.map((filepath: string) => path.basename(filepath))
|
files = files.map((filepath: string) => getStoragePath(filepath, STREAMS_DIR))
|
||||||
let streams = await parser.parse(files)
|
let streams = await parser.parse(files)
|
||||||
streams = streams.map((stream: Stream) => {
|
streams = streams.map((stream: Stream) => {
|
||||||
stream.setGuides(data.guidesGroupedByStreamId.get(stream.getId()))
|
stream.setGuides(data.guidesGroupedByStreamId.get(stream.getId()))
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ export function normalizeURL(url: string): string {
|
|||||||
return decodeURIComponent(normalized).replace(/\s/g, '+').toString()
|
return decodeURIComponent(normalized).replace(/\s/g, '+').toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getStoragePath(filepath: string, rootDir: string): string {
|
||||||
|
const relative = path.relative(path.resolve(rootDir), path.resolve(filepath))
|
||||||
|
|
||||||
|
if (relative && relative !== '..' && !relative.startsWith(`..${path.sep}`)) {
|
||||||
|
return relative
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath
|
||||||
|
}
|
||||||
|
|
||||||
export function truncate(string: string, limit: number = 100) {
|
export function truncate(string: string, limit: number = 100) {
|
||||||
if (!string) return string
|
if (!string) return string
|
||||||
if (string.length < limit) return string
|
if (string.length < limit) return string
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#EXTM3U
|
||||||
|
#EXTINF:-1 tvg-id="",Zulu (720p)
|
||||||
|
https://example.com/zulu.m3u8
|
||||||
|
#EXTINF:-1 tvg-id="",Alpha (720p)
|
||||||
|
https://example.com/alpha.m3u8
|
||||||
@@ -30,7 +30,18 @@ describe('playlist:format', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
it('formats playlists in nested directories', () => {
|
||||||
|
fs.emptyDirSync('tests/__data__/output')
|
||||||
|
fs.copySync('tests/__data__/input/playlist_paths', 'tests/__data__/output/streams')
|
||||||
|
|
||||||
|
const cmd =
|
||||||
|
'cross-env STREAMS_DIR=tests/__data__/output/streams DATA_DIR=tests/__data__/input/data npm run playlist:format'
|
||||||
|
execSync(cmd, { encoding: 'utf8' })
|
||||||
|
|
||||||
|
const output = content('tests/__data__/output/streams/nested/nested.m3u')
|
||||||
|
expect(output.indexOf(',Alpha (720p)')).toBeLessThan(output.indexOf(',Zulu (720p)'))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
function content(filepath: string) {
|
function content(filepath: string) {
|
||||||
return fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' })
|
return fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' })
|
||||||
|
|||||||
Reference in New Issue
Block a user