mirror of
https://github.com/iptv-org/iptv
synced 2025-12-16 18:37:17 -05:00
Update scripts
This commit is contained in:
@@ -1,56 +1,63 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
import { HTMLTable, HTMLTableItem, LogParser, LogItem, HTMLTableColumn } from '../core'
|
||||
import { Storage, File } from '@freearhey/storage-js'
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
import { Table } from './table'
|
||||
import { data } from '../api'
|
||||
|
||||
export class CategoriesTable implements Table {
|
||||
async create() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
|
||||
let items = new Collection<HTMLTableItem>()
|
||||
parser
|
||||
.parse(generatorsLog)
|
||||
.filter((logItem: LogItem) => logItem.type === 'category')
|
||||
.forEach((logItem: LogItem) => {
|
||||
if (logItem.filepath.includes('undefined')) {
|
||||
items.add([
|
||||
'ZZ',
|
||||
'Undefined',
|
||||
logItem.count.toString(),
|
||||
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
|
||||
])
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const file = new File(logItem.filepath)
|
||||
const categoryId = file.name()
|
||||
const category: sdk.Models.Category | undefined = data.categoriesKeyById.get(categoryId)
|
||||
|
||||
if (!category) return
|
||||
|
||||
items.add([
|
||||
category.name,
|
||||
category.name,
|
||||
logItem.count.toString(),
|
||||
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
|
||||
])
|
||||
})
|
||||
|
||||
items = items
|
||||
.sortBy(item => item[0])
|
||||
.map(item => {
|
||||
item.shift()
|
||||
return item
|
||||
})
|
||||
|
||||
const columns = new Collection<HTMLTableColumn>([
|
||||
{ name: 'Category' },
|
||||
{ name: 'Channels', align: 'right' },
|
||||
{ name: 'Playlist', nowrap: true }
|
||||
])
|
||||
|
||||
const table = new HTMLTable(items, columns)
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_categories.md', table.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,189 +1,176 @@
|
||||
import { Storage, Collection, Dictionary } from '@freearhey/core'
|
||||
import { City, Country, Subdivision } from '../models'
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { LogParser, LogItem } from '../core'
|
||||
import { Table } from './table'
|
||||
|
||||
type CountriesTableProps = {
|
||||
countriesKeyByCode: Dictionary
|
||||
subdivisionsKeyByCode: Dictionary
|
||||
countries: Collection
|
||||
subdivisions: Collection
|
||||
cities: Collection
|
||||
}
|
||||
|
||||
export class CountriesTable implements Table {
|
||||
countriesKeyByCode: Dictionary
|
||||
subdivisionsKeyByCode: Dictionary
|
||||
countries: Collection
|
||||
subdivisions: Collection
|
||||
cities: Collection
|
||||
|
||||
constructor({
|
||||
countriesKeyByCode,
|
||||
subdivisionsKeyByCode,
|
||||
countries,
|
||||
subdivisions,
|
||||
cities
|
||||
}: CountriesTableProps) {
|
||||
this.countriesKeyByCode = countriesKeyByCode
|
||||
this.subdivisionsKeyByCode = subdivisionsKeyByCode
|
||||
this.countries = countries
|
||||
this.subdivisions = subdivisions
|
||||
this.cities = cities
|
||||
}
|
||||
|
||||
async make() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
const parsed = parser.parse(generatorsLog)
|
||||
const logCountries = parsed.filter((logItem: LogItem) => logItem.type === 'country')
|
||||
const logSubdivisions = parsed.filter((logItem: LogItem) => logItem.type === 'subdivision')
|
||||
const logCities = parsed.filter((logItem: LogItem) => logItem.type === 'city')
|
||||
|
||||
let items = new Collection()
|
||||
this.countries.forEach((country: Country) => {
|
||||
const countriesLogItem = logCountries.find(
|
||||
(logItem: LogItem) => logItem.filepath === `countries/${country.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
const countryItem = {
|
||||
index: country.name,
|
||||
count: 0,
|
||||
link: `https://iptv-org.github.io/iptv/countries/${country.code.toLowerCase()}.m3u`,
|
||||
name: `${country.flag} ${country.name}`,
|
||||
children: new Collection()
|
||||
}
|
||||
|
||||
if (countriesLogItem) {
|
||||
countryItem.count = countriesLogItem.count
|
||||
}
|
||||
|
||||
const countrySubdivisions = this.subdivisions.filter(
|
||||
(subdivision: Subdivision) => subdivision.countryCode === country.code
|
||||
)
|
||||
const countryCities = this.cities.filter((city: City) => city.countryCode === country.code)
|
||||
if (countrySubdivisions.notEmpty()) {
|
||||
this.subdivisions.forEach((subdivision: Subdivision) => {
|
||||
if (subdivision.countryCode !== country.code) return
|
||||
const subdivisionCities = countryCities.filter(
|
||||
(city: City) =>
|
||||
(city.subdivisionCode && city.subdivisionCode === subdivision.code) ||
|
||||
city.countryCode === subdivision.countryCode
|
||||
)
|
||||
const subdivisionsLogItem = logSubdivisions.find(
|
||||
(logItem: LogItem) =>
|
||||
logItem.filepath === `subdivisions/${subdivision.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
const subdivisionItem = {
|
||||
index: subdivision.name,
|
||||
name: subdivision.name,
|
||||
count: 0,
|
||||
link: `https://iptv-org.github.io/iptv/subdivisions/${subdivision.code.toLowerCase()}.m3u`,
|
||||
children: new Collection()
|
||||
}
|
||||
|
||||
if (subdivisionsLogItem) {
|
||||
subdivisionItem.count = subdivisionsLogItem.count
|
||||
}
|
||||
|
||||
subdivisionCities.forEach((city: City) => {
|
||||
if (city.countryCode !== country.code || city.subdivisionCode !== subdivision.code)
|
||||
return
|
||||
const citiesLogItem = logCities.find(
|
||||
(logItem: LogItem) => logItem.filepath === `cities/${city.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
if (!citiesLogItem) return
|
||||
|
||||
subdivisionItem.children.add({
|
||||
index: city.name,
|
||||
name: city.name,
|
||||
count: citiesLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${citiesLogItem.filepath}`
|
||||
})
|
||||
})
|
||||
|
||||
if (subdivisionItem.count > 0 || subdivisionItem.children.notEmpty()) {
|
||||
countryItem.children.add(subdivisionItem)
|
||||
}
|
||||
})
|
||||
} else if (countryCities.notEmpty()) {
|
||||
countryCities.forEach((city: City) => {
|
||||
const citiesLogItem = logCities.find(
|
||||
(logItem: LogItem) => logItem.filepath === `cities/${city.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
if (!citiesLogItem) return
|
||||
|
||||
countryItem.children.add({
|
||||
index: city.name,
|
||||
name: city.name,
|
||||
count: citiesLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${citiesLogItem.filepath}`,
|
||||
children: new Collection()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (countryItem.count > 0 || countryItem.children.notEmpty()) {
|
||||
items.add(countryItem)
|
||||
}
|
||||
})
|
||||
|
||||
const internationalLogItem = logCountries.find(
|
||||
(logItem: LogItem) => logItem.filepath === 'countries/int.m3u'
|
||||
)
|
||||
|
||||
if (internationalLogItem) {
|
||||
items.push({
|
||||
index: 'ZZ',
|
||||
name: '🌐 International',
|
||||
count: internationalLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${internationalLogItem.filepath}`,
|
||||
children: new Collection()
|
||||
})
|
||||
}
|
||||
|
||||
const undefinedLogItem = logCountries.find(
|
||||
(logItem: LogItem) => logItem.filepath === 'countries/undefined.m3u'
|
||||
)
|
||||
|
||||
if (undefinedLogItem) {
|
||||
items.push({
|
||||
index: 'ZZZ',
|
||||
name: 'Undefined',
|
||||
count: undefinedLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${undefinedLogItem.filepath}`,
|
||||
children: new Collection()
|
||||
})
|
||||
}
|
||||
|
||||
items = items.orderBy(item => item.index)
|
||||
|
||||
const output = items
|
||||
.map(item => {
|
||||
let row = `- ${item.name} <code>${item.link}</code>`
|
||||
|
||||
item.children
|
||||
.orderBy(item => item.index)
|
||||
.forEach(item => {
|
||||
row += `\r\n - ${item.name} <code>${item.link}</code>`
|
||||
|
||||
item.children
|
||||
.orderBy(item => item.index)
|
||||
.forEach(item => {
|
||||
row += `\r\n - ${item.name} <code>${item.link}</code>`
|
||||
})
|
||||
})
|
||||
|
||||
return row
|
||||
})
|
||||
.join('\r\n')
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_countries.md', output)
|
||||
}
|
||||
}
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Storage } from '@freearhey/storage-js'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import { LogParser, LogItem } from '../core'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
import { Table } from './table'
|
||||
import { data } from '../api'
|
||||
|
||||
type ListItem = {
|
||||
index: string
|
||||
count: number
|
||||
link: string
|
||||
name: string
|
||||
children: Collection<ListItem>
|
||||
}
|
||||
|
||||
export class CountriesTable implements Table {
|
||||
async create() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
const parsed = parser.parse(generatorsLog)
|
||||
const logCountries = parsed.filter((logItem: LogItem) => logItem.type === 'country')
|
||||
const logSubdivisions = parsed.filter((logItem: LogItem) => logItem.type === 'subdivision')
|
||||
const logCities = parsed.filter((logItem: LogItem) => logItem.type === 'city')
|
||||
|
||||
let items = new Collection()
|
||||
data.countries.forEach((country: sdk.Models.Country) => {
|
||||
const countryCode = country.code
|
||||
const countriesLogItem = logCountries.find(
|
||||
(logItem: LogItem) => logItem.filepath === `countries/${countryCode.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
const countryItem: ListItem = {
|
||||
index: country.name,
|
||||
count: 0,
|
||||
link: `https://iptv-org.github.io/iptv/countries/${countryCode.toLowerCase()}.m3u`,
|
||||
name: `${country.flag} ${country.name}`,
|
||||
children: new Collection()
|
||||
}
|
||||
|
||||
if (countriesLogItem) {
|
||||
countryItem.count = countriesLogItem.count
|
||||
}
|
||||
|
||||
const countrySubdivisions = data.subdivisions.filter(
|
||||
(subdivision: sdk.Models.Subdivision) => subdivision.country === countryCode
|
||||
)
|
||||
const countryCities = data.cities.filter(
|
||||
(city: sdk.Models.City) => city.country === countryCode
|
||||
)
|
||||
if (countrySubdivisions.isNotEmpty()) {
|
||||
data.subdivisions.forEach((subdivision: sdk.Models.Subdivision) => {
|
||||
if (subdivision.country !== countryCode) return
|
||||
|
||||
const subdivisionCode = subdivision.code
|
||||
const subdivisionCities = countryCities.filter(
|
||||
(city: sdk.Models.City) =>
|
||||
(city.subdivision && city.subdivision === subdivisionCode) ||
|
||||
city.country === subdivision.country
|
||||
)
|
||||
const subdivisionsLogItem = logSubdivisions.find(
|
||||
(logItem: LogItem) =>
|
||||
logItem.filepath === `subdivisions/${subdivisionCode.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
const subdivisionItem: ListItem = {
|
||||
index: subdivision.name,
|
||||
name: subdivision.name,
|
||||
count: 0,
|
||||
link: `https://iptv-org.github.io/iptv/subdivisions/${subdivisionCode.toLowerCase()}.m3u`,
|
||||
children: new Collection<ListItem>()
|
||||
}
|
||||
|
||||
if (subdivisionsLogItem) {
|
||||
subdivisionItem.count = subdivisionsLogItem.count
|
||||
}
|
||||
|
||||
subdivisionCities.forEach((city: sdk.Models.City) => {
|
||||
if (city.country !== countryCode || city.subdivision !== subdivisionCode) return
|
||||
const citiesLogItem = logCities.find(
|
||||
(logItem: LogItem) => logItem.filepath === `cities/${city.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
if (!citiesLogItem) return
|
||||
|
||||
subdivisionItem.children.add({
|
||||
index: city.name,
|
||||
name: city.name,
|
||||
count: citiesLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${citiesLogItem.filepath}`,
|
||||
children: new Collection<ListItem>()
|
||||
})
|
||||
})
|
||||
|
||||
if (subdivisionItem.count > 0 || subdivisionItem.children.isNotEmpty()) {
|
||||
countryItem.children.add(subdivisionItem)
|
||||
}
|
||||
})
|
||||
} else if (countryCities.isNotEmpty()) {
|
||||
countryCities.forEach((city: sdk.Models.City) => {
|
||||
const citiesLogItem = logCities.find(
|
||||
(logItem: LogItem) => logItem.filepath === `cities/${city.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
if (!citiesLogItem) return
|
||||
|
||||
countryItem.children.add({
|
||||
index: city.name,
|
||||
name: city.name,
|
||||
count: citiesLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${citiesLogItem.filepath}`,
|
||||
children: new Collection()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (countryItem.count > 0 || countryItem.children.isNotEmpty()) {
|
||||
items.add(countryItem)
|
||||
}
|
||||
})
|
||||
|
||||
const internationalLogItem = logCountries.find(
|
||||
(logItem: LogItem) => logItem.filepath === 'countries/int.m3u'
|
||||
)
|
||||
|
||||
if (internationalLogItem) {
|
||||
items.add({
|
||||
index: 'ZZ',
|
||||
name: '🌐 International',
|
||||
count: internationalLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${internationalLogItem.filepath}`,
|
||||
children: new Collection()
|
||||
})
|
||||
}
|
||||
|
||||
const undefinedLogItem = logCountries.find(
|
||||
(logItem: LogItem) => logItem.filepath === 'countries/undefined.m3u'
|
||||
)
|
||||
|
||||
if (undefinedLogItem) {
|
||||
items.add({
|
||||
index: 'ZZZ',
|
||||
name: 'Undefined',
|
||||
count: undefinedLogItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${undefinedLogItem.filepath}`,
|
||||
children: new Collection()
|
||||
})
|
||||
}
|
||||
|
||||
items = items.sortBy(item => item.index)
|
||||
|
||||
const output = items
|
||||
.map((item: ListItem) => {
|
||||
let row = `- ${item.name} <code>${item.link}</code>`
|
||||
|
||||
item.children
|
||||
.sortBy((item: ListItem) => item.index)
|
||||
.forEach((item: ListItem) => {
|
||||
row += `\r\n - ${item.name} <code>${item.link}</code>`
|
||||
|
||||
item.children
|
||||
.sortBy((item: ListItem) => item.index)
|
||||
.forEach((item: ListItem) => {
|
||||
row += `\r\n - ${item.name} <code>${item.link}</code>`
|
||||
})
|
||||
})
|
||||
|
||||
return row
|
||||
})
|
||||
.join('\r\n')
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_countries.md', output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,63 @@
|
||||
import { Storage, Collection, File, Dictionary } from '@freearhey/core'
|
||||
import { HTMLTable, LogParser, LogItem } from '../core'
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Language } from '../models'
|
||||
import { Table } from './table'
|
||||
|
||||
type LanguagesTableProps = {
|
||||
languagesKeyByCode: Dictionary
|
||||
}
|
||||
|
||||
export class LanguagesTable implements Table {
|
||||
languagesKeyByCode: Dictionary
|
||||
|
||||
constructor({ languagesKeyByCode }: LanguagesTableProps) {
|
||||
this.languagesKeyByCode = languagesKeyByCode
|
||||
}
|
||||
|
||||
async make() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
|
||||
let data = new Collection()
|
||||
parser
|
||||
.parse(generatorsLog)
|
||||
.filter((logItem: LogItem) => logItem.type === 'language')
|
||||
.forEach((logItem: LogItem) => {
|
||||
const file = new File(logItem.filepath)
|
||||
const languageCode = file.name()
|
||||
const language: Language = this.languagesKeyByCode.get(languageCode)
|
||||
|
||||
data.add([
|
||||
language ? language.name : 'ZZ',
|
||||
language ? language.name : 'Undefined',
|
||||
logItem.count,
|
||||
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
|
||||
])
|
||||
})
|
||||
|
||||
data = data
|
||||
.orderBy(item => item[0])
|
||||
.map(item => {
|
||||
item.shift()
|
||||
return item
|
||||
})
|
||||
|
||||
const table = new HTMLTable(data.all(), [
|
||||
{ name: 'Language', align: 'left' },
|
||||
{ name: 'Channels', align: 'right' },
|
||||
{ name: 'Playlist', align: 'left', nowrap: true }
|
||||
])
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_languages.md', table.toString())
|
||||
}
|
||||
}
|
||||
import { HTMLTable, LogParser, LogItem, HTMLTableColumn, HTMLTableItem } from '../core'
|
||||
import { Storage, File } from '@freearhey/storage-js'
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
import { Table } from './table'
|
||||
import { data } from '../api'
|
||||
|
||||
export class LanguagesTable implements Table {
|
||||
async create() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
|
||||
let items = new Collection<HTMLTableItem>()
|
||||
parser
|
||||
.parse(generatorsLog)
|
||||
.filter((logItem: LogItem) => logItem.type === 'language')
|
||||
.forEach((logItem: LogItem) => {
|
||||
if (logItem.filepath.includes('undefined')) {
|
||||
items.add([
|
||||
'ZZ',
|
||||
'Undefined',
|
||||
logItem.count.toString(),
|
||||
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
|
||||
])
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const file = new File(logItem.filepath)
|
||||
const languageCode = file.name()
|
||||
const language: sdk.Models.Language | undefined = data.languagesKeyByCode.get(languageCode)
|
||||
|
||||
if (!language) return
|
||||
|
||||
items.add([
|
||||
language.name,
|
||||
language.name,
|
||||
logItem.count.toString(),
|
||||
`<code>https://iptv-org.github.io/iptv/${logItem.filepath}</code>`
|
||||
])
|
||||
})
|
||||
|
||||
items = items
|
||||
.sortBy(item => item[0])
|
||||
.map(item => {
|
||||
item.shift()
|
||||
return item
|
||||
})
|
||||
|
||||
const columns = new Collection<HTMLTableColumn>([
|
||||
{ name: 'Language', align: 'left' },
|
||||
{ name: 'Channels', align: 'right' },
|
||||
{ name: 'Playlist', align: 'left', nowrap: true }
|
||||
])
|
||||
|
||||
const table = new HTMLTable(items, columns)
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_languages.md', table.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,49 @@
|
||||
import { Storage, Collection } from '@freearhey/core'
|
||||
import { LogParser, LogItem } from '../core'
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Region } from '../models'
|
||||
import { Table } from './table'
|
||||
|
||||
type RegionsTableProps = {
|
||||
regions: Collection
|
||||
}
|
||||
|
||||
export class RegionsTable implements Table {
|
||||
regions: Collection
|
||||
|
||||
constructor({ regions }: RegionsTableProps) {
|
||||
this.regions = regions
|
||||
}
|
||||
|
||||
async make() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
const parsed = parser.parse(generatorsLog)
|
||||
const logRegions = parsed.filter((logItem: LogItem) => logItem.type === 'region')
|
||||
|
||||
let items = new Collection()
|
||||
this.regions.forEach((region: Region) => {
|
||||
const logItem = logRegions.find(
|
||||
(logItem: LogItem) => logItem.filepath === `regions/${region.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
if (!logItem) return
|
||||
|
||||
items.add({
|
||||
index: region.name,
|
||||
name: region.name,
|
||||
count: logItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${logItem.filepath}`
|
||||
})
|
||||
})
|
||||
|
||||
items = items.orderBy(item => item.index)
|
||||
|
||||
const output = items
|
||||
.map(item => {
|
||||
return `- ${item.name} <code>${item.link}</code>`
|
||||
})
|
||||
.join('\r\n')
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_regions.md', output)
|
||||
}
|
||||
}
|
||||
import { LOGS_DIR, README_DIR } from '../constants'
|
||||
import { Storage } from '@freearhey/storage-js'
|
||||
import { LogParser, LogItem } from '../core'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
import { Table } from './table'
|
||||
import { data } from '../api'
|
||||
|
||||
type ListItem = {
|
||||
name: string
|
||||
count: number
|
||||
link: string
|
||||
}
|
||||
|
||||
export class RegionsTable implements Table {
|
||||
async create() {
|
||||
const parser = new LogParser()
|
||||
const logsStorage = new Storage(LOGS_DIR)
|
||||
const generatorsLog = await logsStorage.load('generators.log')
|
||||
const parsed = parser.parse(generatorsLog)
|
||||
const logRegions = parsed.filter((logItem: LogItem) => logItem.type === 'region')
|
||||
|
||||
let items = new Collection<ListItem>()
|
||||
data.regions.forEach((region: sdk.Models.Region) => {
|
||||
const logItem = logRegions.find(
|
||||
(logItem: LogItem) => logItem.filepath === `regions/${region.code.toLowerCase()}.m3u`
|
||||
)
|
||||
|
||||
if (!logItem) return
|
||||
|
||||
items.add({
|
||||
name: region.name,
|
||||
count: logItem.count,
|
||||
link: `https://iptv-org.github.io/iptv/${logItem.filepath}`
|
||||
})
|
||||
})
|
||||
|
||||
items = items.sortBy(item => item.name)
|
||||
|
||||
const output = items
|
||||
.map(item => {
|
||||
return `- ${item.name} <code>${item.link}</code>`
|
||||
})
|
||||
.join('\r\n')
|
||||
|
||||
const readmeStorage = new Storage(README_DIR)
|
||||
await readmeStorage.save('_regions.md', output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface Table {
|
||||
make(): void
|
||||
}
|
||||
export interface Table {
|
||||
create(): void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user