mirror of
https://github.com/iptv-org/iptv
synced 2025-12-17 02:47:33 -05:00
Update scripts
This commit is contained in:
56
scripts/tables/categoriesTable.ts
Normal file
56
scripts/tables/categoriesTable.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Storage, Collection, File, Dictionary } from '@freearhey/core'
|
||||
import { HTMLTable, LogParser, LogItem } from '../core'
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Category } from '../models'
|
||||
import { Table } from './table'
|
||||
|
||||
type CategoriesTableProps = {
|
||||
categoriesKeyById: Dictionary
|
||||
}
|
||||
|
||||
export class CategoriesTable implements Table {
|
||||
categoriesKeyById: Dictionary
|
||||
|
||||
constructor({ categoriesKeyById }: CategoriesTableProps) {
|
||||
this.categoriesKeyById = categoriesKeyById
|
||||
}
|
||||
|
||||
async make() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
|
||||
let items = new Collection()
|
||||
parser
|
||||
.parse(generatorsLog)
|
||||
.filter((logItem: LogItem) => logItem.type === 'category')
|
||||
.forEach((logItem: LogItem) => {
|
||||
const file = new File(logItem.filepath)
|
||||
const categoryId = file.name()
|
||||
const category: Category = this.categoriesKeyById.get(categoryId)
|
||||
|
||||
items.add([
|
||||
category ? category.name : 'ZZ',
|
||||
category ? category.name : 'Undefined',
|
||||
logItem.count,
|
||||
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
|
||||
])
|
||||
})
|
||||
|
||||
items = items
|
||||
.orderBy(item => item[0])
|
||||
.map(item => {
|
||||
item.shift()
|
||||
return item
|
||||
})
|
||||
|
||||
const table = new HTMLTable(items.all(), [
|
||||
{ name: 'Category' },
|
||||
{ name: 'Channels', align: 'right' },
|
||||
{ name: 'Playlist', nowrap: true }
|
||||
])
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_categories.md', table.toString())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user