mirror of
https://github.com/iptv-org/iptv
synced 2026-05-07 01:57:21 -04:00
wip
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { isURI, getStreamInfo, loadIssues } from '../../utils'
|
import { isURI, getStreamInfo, loadIssues } from '../../utils'
|
||||||
|
import { STREAMS_DIR, LOGS_DIR } from '../../constants'
|
||||||
import { Playlist, Issue, Stream } from '../../models'
|
import { Playlist, Issue, Stream } from '../../models'
|
||||||
import { loadData, data as apiData } from '../../api'
|
import { loadData, data as apiData } from '../../api'
|
||||||
import { Logger, Collection } from '@freearhey/core'
|
import { Logger, Collection } from '@freearhey/core'
|
||||||
import { Storage } from '@freearhey/storage-js'
|
import { Storage } from '@freearhey/storage-js'
|
||||||
import { STREAMS_DIR } from '../../constants'
|
|
||||||
import { PlaylistParser } from '../../core'
|
import { PlaylistParser } from '../../core'
|
||||||
import * as sdk from '@iptv-org/sdk'
|
import * as sdk from '@iptv-org/sdk'
|
||||||
|
|
||||||
@@ -12,51 +12,61 @@ const processedIssues = new Collection()
|
|||||||
async function main() {
|
async function main() {
|
||||||
const logger = new Logger({ level: -999 })
|
const logger = new Logger({ level: -999 })
|
||||||
|
|
||||||
logger.info('loading issues...')
|
|
||||||
const issues = await loadIssues()
|
|
||||||
|
|
||||||
logger.info('loading data from api...')
|
logger.info('loading data from api...')
|
||||||
await loadData()
|
await loadData()
|
||||||
|
|
||||||
|
logger.info('loading issues...')
|
||||||
|
const issues = await loadIssues()
|
||||||
|
|
||||||
logger.info('loading streams...')
|
logger.info('loading streams...')
|
||||||
const streamsStorage = new Storage(STREAMS_DIR)
|
const streams = await loadStreams()
|
||||||
const parser = new PlaylistParser({
|
|
||||||
storage: streamsStorage
|
|
||||||
})
|
|
||||||
const files = await streamsStorage.list('**/*.m3u')
|
|
||||||
const streams = await parser.parse(files)
|
|
||||||
|
|
||||||
logger.info('removing streams...')
|
logger.info('removing streams...')
|
||||||
await removeStreams({ streams, issues })
|
await removeStreams({ streams, issues })
|
||||||
|
|
||||||
logger.info('edit stream description...')
|
logger.info('edit stream description...')
|
||||||
await editStreams({
|
await editStreams({ streams, issues })
|
||||||
streams,
|
|
||||||
issues
|
|
||||||
})
|
|
||||||
|
|
||||||
logger.info('add new streams...')
|
logger.info('add new streams...')
|
||||||
await addStreams({
|
await addStreams({ streams, issues })
|
||||||
streams,
|
|
||||||
issues
|
|
||||||
})
|
|
||||||
|
|
||||||
logger.info('saving...')
|
logger.info('saving streams...')
|
||||||
const groupedStreams = streams.groupBy((stream: Stream) => stream.getFilepath())
|
await saveStreams({ streams })
|
||||||
for (const filepath of groupedStreams.keys()) {
|
|
||||||
let streams = new Collection(groupedStreams.get(filepath))
|
|
||||||
streams = streams.filter((stream: Stream) => stream.removed === false)
|
|
||||||
|
|
||||||
const playlist = new Playlist(streams, { public: false })
|
logger.info('saving logs...')
|
||||||
await streamsStorage.save(filepath, playlist.toString())
|
await saveLogs()
|
||||||
}
|
|
||||||
|
|
||||||
const output = processedIssues.map(issue_number => `closes #${issue_number}`).join(', ')
|
|
||||||
console.log(`OUTPUT=${output}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
async function saveLogs() {
|
||||||
|
const logStorage = new Storage(LOGS_DIR)
|
||||||
|
const output = processedIssues.map((issue: Issue) => `closes #${issue.number}`).join(', ')
|
||||||
|
await logStorage.save('playlist_update.log', output)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveStreams({ streams }) {
|
||||||
|
const streamsStorage = new Storage(STREAMS_DIR)
|
||||||
|
const groupedStreams = streams.groupBy((stream: Stream) => stream.getFilepath())
|
||||||
|
for (const filepath of groupedStreams.keys()) {
|
||||||
|
let filteredStreams = new Collection<Stream>(groupedStreams.get(filepath))
|
||||||
|
filteredStreams = filteredStreams.filter((stream: Stream) => stream.removed === false)
|
||||||
|
|
||||||
|
const playlist = new Playlist(filteredStreams, { public: false })
|
||||||
|
await streamsStorage.save(filepath, playlist.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadStreams() {
|
||||||
|
const streamsStorage = new Storage(STREAMS_DIR)
|
||||||
|
const parser = new PlaylistParser({
|
||||||
|
storage: streamsStorage
|
||||||
|
})
|
||||||
|
const files = await streamsStorage.list('**/*.m3u')
|
||||||
|
|
||||||
|
return await parser.parse(files)
|
||||||
|
}
|
||||||
|
|
||||||
async function removeStreams({
|
async function removeStreams({
|
||||||
streams,
|
streams,
|
||||||
issues
|
issues
|
||||||
@@ -86,7 +96,7 @@ async function removeStreams({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (changed) processedIssues.add(issue.number)
|
if (changed) processedIssues.add(issue)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +131,7 @@ async function editStreams({
|
|||||||
|
|
||||||
stream.updateWithIssue(data)
|
stream.updateWithIssue(data)
|
||||||
|
|
||||||
processedIssues.add(issue.number)
|
processedIssues.add(issue)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +191,6 @@ async function addStreams({
|
|||||||
stream.updateTitle().updateFilepath()
|
stream.updateTitle().updateFilepath()
|
||||||
|
|
||||||
streams.add(stream)
|
streams.add(stream)
|
||||||
processedIssues.add(issue.number)
|
processedIssues.add(issue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
closes #14151, closes #14150, closes #14110, closes #14120, closes #14175, closes #14105, closes #14104, closes #14057, closes #14034, closes #13964, closes #13893, closes #13881, closes #13793, closes #13751, closes #13715
|
||||||
@@ -4,7 +4,7 @@ import * as fs from 'fs-extra'
|
|||||||
import { glob } from 'glob'
|
import { glob } from 'glob'
|
||||||
|
|
||||||
const ENV_VAR =
|
const ENV_VAR =
|
||||||
'cross-env DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams'
|
'cross-env DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams LOGS_DIR=tests/__data__/output/logs'
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fs.emptyDirSync('tests/__data__/output')
|
fs.emptyDirSync('tests/__data__/output')
|
||||||
@@ -19,21 +19,25 @@ describe('playlist:update', () => {
|
|||||||
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)
|
||||||
|
|
||||||
const files = glob.sync('tests/__data__/expected/playlist_update/*.m3u').map(filepath => {
|
const files = glob
|
||||||
const fileUrl = pathToFileURL(filepath).toString()
|
.sync('tests/__data__/expected/playlist_update/streams/*.m3u')
|
||||||
const pathToRemove = pathToFileURL('tests/__data__/expected/playlist_update/').toString()
|
.map(filepath => {
|
||||||
|
const fileUrl = pathToFileURL(filepath).toString()
|
||||||
|
const pathToRemove = pathToFileURL(
|
||||||
|
'tests/__data__/expected/playlist_update/streams/'
|
||||||
|
).toString()
|
||||||
|
|
||||||
return fileUrl.replace(pathToRemove, '')
|
return fileUrl.replace(pathToRemove, '')
|
||||||
})
|
})
|
||||||
|
|
||||||
files.forEach(filepath => {
|
files.forEach(filepath => {
|
||||||
expect(content(`tests/__data__/output/streams/${filepath}`)).toBe(
|
expect(content(`tests/__data__/output/streams/${filepath}`)).toBe(
|
||||||
content(`tests/__data__/expected/playlist_update/${filepath}`)
|
content(`tests/__data__/expected/playlist_update/streams/${filepath}`)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(stdout).toBe(
|
expect(content('tests/__data__/output/logs/playlist_update.log')).toBe(
|
||||||
'OUTPUT=closes #14151, closes #14150, closes #14110, closes #14120, closes #14175, closes #14105, closes #14104, closes #14057, closes #14034, closes #13964, closes #13893, closes #13881, closes #13793, closes #13751, closes #13715\n'
|
content('tests/__data__/expected/playlist_update/playlist_update.log')
|
||||||
)
|
)
|
||||||
|
|
||||||
done()
|
done()
|
||||||
|
|||||||
Reference in New Issue
Block a user