Update scripts

This commit is contained in:
freearhey 2023-09-15 18:40:35 +03:00
parent 8a83f23243
commit f1d2add19a
98 changed files with 2423 additions and 1499 deletions

View file

@ -1,28 +0,0 @@
const { logger, db, file } = require('../../core')
const _ = require('lodash')
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.api'
async function main() {
logger.info(`loading streams...`)
await db.streams.load()
let streams = await db.streams.find({})
streams = _.sortBy(streams, 'channel')
streams = streams.map(stream => {
let data = {
channel: stream.channel,
url: stream.url,
http_referrer: stream.http_referrer,
user_agent: stream.user_agent
}
return data
})
logger.info(`found ${streams.length} streams`)
logger.info('saving to .api/streams.json...')
await file.create(`${PUBLIC_DIR}/streams.json`, JSON.stringify(streams))
}
main()

View file

@ -0,0 +1,25 @@
import { API_DIR, DB_DIR } from '../../constants'
import { Logger, Database, Collection, 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[])
.map(data => new Stream(data))
.orderBy((stream: Stream) => stream.channel)
.map((stream: Stream) => stream.toJSON())
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())
}
main()

View file

@ -1,11 +1,11 @@
#!/bin/bash
mkdir -p scripts/tmp/data
curl -L -o scripts/tmp/data/blocklist.json https://iptv-org.github.io/api/blocklist.json
curl -L -o scripts/tmp/data/categories.json https://iptv-org.github.io/api/categories.json
curl -L -o scripts/tmp/data/channels.json https://iptv-org.github.io/api/channels.json
curl -L -o scripts/tmp/data/streams.json https://iptv-org.github.io/api/streams.json
curl -L -o scripts/tmp/data/countries.json https://iptv-org.github.io/api/countries.json
curl -L -o scripts/tmp/data/languages.json https://iptv-org.github.io/api/languages.json
curl -L -o scripts/tmp/data/regions.json https://iptv-org.github.io/api/regions.json
curl -L -o scripts/tmp/data/subdivisions.json https://iptv-org.github.io/api/subdivisions.json
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
curl -L -o temp/data/subdivisions.json https://iptv-org.github.io/api/subdivisions.json