Update scripts

This commit is contained in:
freearhey 2023-09-17 04:08:50 +03:00
parent 89b87ad5c8
commit bb2935878d
16 changed files with 248 additions and 231 deletions

View file

@ -1,16 +1,16 @@
import { API_DIR, DB_DIR } from '../../constants'
import { Logger, Database, Collection, Storage } from '../../core'
import { API_DIR, STREAMS_DIR } from '../../constants'
import { Logger, PlaylistParser, Storage } from '../../core'
import { Stream } from '../../models'
async function main() {
const logger = new Logger()
logger.info(`loading streams...`)
const db = new Database(DB_DIR)
const dbStreams = await db.load('streams.db')
const docs = await dbStreams.find({})
const streams = new Collection(docs as any[])
logger.info('loading streams...')
const streamsStorage = new Storage(STREAMS_DIR)
const parser = new PlaylistParser({ storage: streamsStorage })
const files = await streamsStorage.list('**/*.m3u')
let streams = await parser.parse(files)
streams = streams
.map(data => new Stream(data))
.orderBy((stream: Stream) => stream.channel)
.map((stream: Stream) => stream.toJSON())
@ -18,8 +18,8 @@ async function main() {
logger.info(`found ${streams.count()} streams`)
logger.info('saving to .api/streams.json...')
const storage = new Storage(API_DIR)
await storage.save('streams.json', streams.toJSON())
const apiStorage = new Storage(API_DIR)
await apiStorage.save('streams.json', streams.toJSON())
}
main()

View file

@ -4,7 +4,6 @@ mkdir -p temp/data
curl -L -o temp/data/blocklist.json https://iptv-org.github.io/api/blocklist.json
curl -L -o temp/data/categories.json https://iptv-org.github.io/api/categories.json
curl -L -o temp/data/channels.json https://iptv-org.github.io/api/channels.json
curl -L -o temp/data/streams.json https://iptv-org.github.io/api/streams.json
curl -L -o temp/data/countries.json https://iptv-org.github.io/api/countries.json
curl -L -o temp/data/languages.json https://iptv-org.github.io/api/languages.json
curl -L -o temp/data/regions.json https://iptv-org.github.io/api/regions.json