Update scripts

This commit is contained in:
freearhey 2025-04-23 20:56:19 +03:00
parent 696fdf5780
commit ec5cdf0864
15 changed files with 144 additions and 118 deletions

View file

@ -1,7 +1,7 @@
import { Storage, Collection, Logger, Dictionary } from '@freearhey/core' import { Storage, Collection, Logger, Dictionary } from '@freearhey/core'
import { DataLoader, DataProcessor, PlaylistParser } from '../../core' import { DataLoader, DataProcessor, PlaylistParser } from '../../core'
import { Channel, Feed, Playlist, Stream } from '../../models'
import type { ChannelSearchableData } from '../../types/channel' import type { ChannelSearchableData } from '../../types/channel'
import { Channel, Feed, Playlist, Stream } from '../../models'
import { DataProcessorData } from '../../types/dataProcessor' import { DataProcessorData } from '../../types/dataProcessor'
import { DataLoaderData } from '../../types/dataLoader' import { DataLoaderData } from '../../types/dataLoader'
import { select, input } from '@inquirer/prompts' import { select, input } from '@inquirer/prompts'

View file

@ -1,27 +1,25 @@
import { Logger, Storage } from '@freearhey/core'
import { PlaylistParser, DataProcessor, DataLoader } from '../../core' import { PlaylistParser, DataProcessor, DataLoader } from '../../core'
import type { DataProcessorData } from '../../types/dataProcessor'
import { DATA_DIR, LOGS_DIR, STREAMS_DIR } from '../../constants'
import type { DataLoaderData } from '../../types/dataLoader'
import { Logger, Storage, File } from '@freearhey/core'
import { Stream } from '../../models' import { Stream } from '../../models'
import { uniqueId } from 'lodash' import { uniqueId } from 'lodash'
import { import {
IndexCategoryGenerator,
IndexLanguageGenerator,
IndexCountryGenerator,
IndexRegionGenerator,
CategoriesGenerator, CategoriesGenerator,
CountriesGenerator, CountriesGenerator,
LanguagesGenerator, LanguagesGenerator,
RegionsGenerator, RegionsGenerator,
IndexGenerator, IndexGenerator
IndexCategoryGenerator,
IndexCountryGenerator,
IndexLanguageGenerator,
IndexRegionGenerator
} from '../../generators' } from '../../generators'
import { DATA_DIR, LOGS_DIR, STREAMS_DIR } from '../../constants'
import type { DataProcessorData } from '../../types/dataProcessor'
import type { DataLoaderData } from '../../types/dataLoader'
async function main() { async function main() {
const logger = new Logger() const logger = new Logger()
const generatorsLogger = new Logger({ const logFile = new File('generators.log')
stream: await new Storage(LOGS_DIR).createStream(`generators.log`)
})
logger.info('loading data from api...') logger.info('loading data from api...')
const processor = new DataProcessor() const processor = new DataProcessor()
@ -29,19 +27,19 @@ async function main() {
const loader = new DataLoader({ storage: dataStorage }) const loader = new DataLoader({ storage: dataStorage })
const data: DataLoaderData = await loader.load() const data: DataLoaderData = await loader.load()
const { const {
feedsGroupedByChannelId,
channelsKeyById,
categories, categories,
countries, countries,
regions, regions
channelsKeyById,
feedsGroupedByChannelId
}: DataProcessorData = processor.process(data) }: DataProcessorData = processor.process(data)
logger.info('loading streams...') logger.info('loading streams...')
const streamsStorage = new Storage(STREAMS_DIR) const streamsStorage = new Storage(STREAMS_DIR)
const parser = new PlaylistParser({ const parser = new PlaylistParser({
storage: streamsStorage, storage: streamsStorage,
channelsKeyById, feedsGroupedByChannelId,
feedsGroupedByChannelId channelsKeyById
}) })
const files = await streamsStorage.list('**/*.m3u') const files = await streamsStorage.list('**/*.m3u')
let streams = await parser.parse(files) let streams = await parser.parse(files)
@ -62,42 +60,46 @@ async function main() {
) )
logger.info('generating categories/...') logger.info('generating categories/...')
await new CategoriesGenerator({ categories, streams, logger: generatorsLogger }).generate() await new CategoriesGenerator({ categories, streams, logFile }).generate()
logger.info('generating countries/...') logger.info('generating countries/...')
await new CountriesGenerator({ await new CountriesGenerator({
countries, countries,
streams, streams,
logger: generatorsLogger logFile
}).generate() }).generate()
logger.info('generating languages/...') logger.info('generating languages/...')
await new LanguagesGenerator({ streams, logger: generatorsLogger }).generate() await new LanguagesGenerator({ streams, logFile }).generate()
logger.info('generating regions/...') logger.info('generating regions/...')
await new RegionsGenerator({ await new RegionsGenerator({
streams, streams,
regions, regions,
logger: generatorsLogger logFile
}).generate() }).generate()
logger.info('generating index.m3u...') logger.info('generating index.m3u...')
await new IndexGenerator({ streams, logger: generatorsLogger }).generate() await new IndexGenerator({ streams, logFile }).generate()
logger.info('generating index.category.m3u...') logger.info('generating index.category.m3u...')
await new IndexCategoryGenerator({ streams, logger: generatorsLogger }).generate() await new IndexCategoryGenerator({ streams, logFile }).generate()
logger.info('generating index.country.m3u...') logger.info('generating index.country.m3u...')
await new IndexCountryGenerator({ await new IndexCountryGenerator({
streams, streams,
logger: generatorsLogger logFile
}).generate() }).generate()
logger.info('generating index.language.m3u...') logger.info('generating index.language.m3u...')
await new IndexLanguageGenerator({ streams, logger: generatorsLogger }).generate() await new IndexLanguageGenerator({ streams, logFile }).generate()
logger.info('generating index.region.m3u...') logger.info('generating index.region.m3u...')
await new IndexRegionGenerator({ streams, regions, logger: generatorsLogger }).generate() await new IndexRegionGenerator({ streams, regions, logFile }).generate()
logger.info('saving generators.log...')
const logStorage = new Storage(LOGS_DIR)
logStorage.saveFile(logFile)
} }
main() main()

View file

@ -159,7 +159,7 @@ function onFinish() {
drawTable() drawTable()
logger.error(`\n${errors + warnings} problems (${errors} errors, ${warnings} warnings)`) console.log(chalk.red(`\n${errors + warnings} problems (${errors} errors, ${warnings} warnings)`))
if (errors > 0) { if (errors > 0) {
process.exit(1) process.exit(1)

View file

@ -94,14 +94,14 @@ async function main() {
}) })
if (log.notEmpty()) { if (log.notEmpty()) {
logger.info(`\n${chalk.underline(filepath)}`) console.log(`\n${chalk.underline(filepath)}`)
log.forEach((logItem: LogItem) => { log.forEach((logItem: LogItem) => {
const position = logItem.line.toString().padEnd(6, ' ') const position = logItem.line.toString().padEnd(6, ' ')
const type = logItem.type.padEnd(9, ' ') const type = logItem.type.padEnd(9, ' ')
const status = logItem.type === 'error' ? chalk.red(type) : chalk.yellow(type) const status = logItem.type === 'error' ? chalk.red(type) : chalk.yellow(type)
logger.info(` ${chalk.gray(position)}${status}${logItem.message}`) console.log(` ${chalk.gray(position)}${status}${logItem.message}`)
}) })
errors = errors.concat(log.filter((logItem: LogItem) => logItem.type === 'error')) errors = errors.concat(log.filter((logItem: LogItem) => logItem.type === 'error'))
@ -109,7 +109,7 @@ async function main() {
} }
} }
logger.error( console.log(
chalk.red( chalk.red(
`\n${ `\n${
errors.count() + warnings.count() errors.count() + warnings.count()

View file

@ -1,25 +1,26 @@
import { Generator } from './generator' import { Collection, Storage, Logger, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Stream, Category, Playlist } from '../models' import { Stream, Category, Playlist } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type CategoriesGeneratorProps = { type CategoriesGeneratorProps = {
streams: Collection streams: Collection
categories: Collection categories: Collection
logger: Logger logFile: File
} }
export class CategoriesGenerator implements Generator { export class CategoriesGenerator implements Generator {
streams: Collection streams: Collection
categories: Collection categories: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, categories, logger }: CategoriesGeneratorProps) { constructor({ streams, categories, logFile }: CategoriesGeneratorProps) {
this.streams = streams this.streams = streams
this.categories = categories this.categories = categories
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate() { async generate() {
@ -37,8 +38,8 @@ export class CategoriesGenerator implements Generator {
const playlist = new Playlist(categoryStreams, { public: true }) const playlist = new Playlist(categoryStreams, { public: true })
const filepath = `categories/${category.id}.m3u` const filepath = `categories/${category.id}.m3u`
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'category', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'category', filepath, count: playlist.streams.count() }) + EOL
) )
}) })
@ -46,8 +47,8 @@ export class CategoriesGenerator implements Generator {
const playlist = new Playlist(undefinedStreams, { public: true }) const playlist = new Playlist(undefinedStreams, { public: true })
const filepath = 'categories/undefined.m3u' const filepath = 'categories/undefined.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'category', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'category', filepath, count: playlist.streams.count() }) + EOL
) )
} }
} }

View file

@ -1,25 +1,26 @@
import { Generator } from './generator'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Country, Subdivision, Stream, Playlist } from '../models' import { Country, Subdivision, Stream, Playlist } from '../models'
import { Collection, Storage, File } from '@freearhey/core'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type CountriesGeneratorProps = { type CountriesGeneratorProps = {
streams: Collection streams: Collection
countries: Collection countries: Collection
logger: Logger logFile: File
} }
export class CountriesGenerator implements Generator { export class CountriesGenerator implements Generator {
streams: Collection streams: Collection
countries: Collection countries: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, countries, logger }: CountriesGeneratorProps) { constructor({ streams, countries, logFile }: CountriesGeneratorProps) {
this.streams = streams this.streams = streams
this.countries = countries this.countries = countries
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -36,8 +37,8 @@ export class CountriesGenerator implements Generator {
const playlist = new Playlist(countryStreams, { public: true }) const playlist = new Playlist(countryStreams, { public: true })
const filepath = `countries/${country.code.toLowerCase()}.m3u` const filepath = `countries/${country.code.toLowerCase()}.m3u`
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'country', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'country', filepath, count: playlist.streams.count() }) + EOL
) )
country.getSubdivisions().forEach(async (subdivision: Subdivision) => { country.getSubdivisions().forEach(async (subdivision: Subdivision) => {
@ -50,8 +51,8 @@ export class CountriesGenerator implements Generator {
const playlist = new Playlist(subdivisionStreams, { public: true }) const playlist = new Playlist(subdivisionStreams, { public: true })
const filepath = `subdivisions/${subdivision.code.toLowerCase()}.m3u` const filepath = `subdivisions/${subdivision.code.toLowerCase()}.m3u`
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'subdivision', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'subdivision', filepath, count: playlist.streams.count() }) + EOL
) )
}) })
}) })
@ -60,12 +61,12 @@ export class CountriesGenerator implements Generator {
const undefinedPlaylist = new Playlist(undefinedStreams, { public: true }) const undefinedPlaylist = new Playlist(undefinedStreams, { public: true })
const undefinedFilepath = 'countries/undefined.m3u' const undefinedFilepath = 'countries/undefined.m3u'
await this.storage.save(undefinedFilepath, undefinedPlaylist.toString()) await this.storage.save(undefinedFilepath, undefinedPlaylist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ JSON.stringify({
type: 'country', type: 'country',
filepath: undefinedFilepath, filepath: undefinedFilepath,
count: undefinedPlaylist.streams.count() count: undefinedPlaylist.streams.count()
}) }) + EOL
) )
} }
} }

View file

@ -1,22 +1,23 @@
import { Generator } from './generator' import { Collection, Storage, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Stream, Playlist, Category } from '../models' import { Stream, Playlist, Category } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexCategoryGeneratorProps = { type IndexCategoryGeneratorProps = {
streams: Collection streams: Collection
logger: Logger logFile: File
} }
export class IndexCategoryGenerator implements Generator { export class IndexCategoryGenerator implements Generator {
streams: Collection streams: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, logger }: IndexCategoryGeneratorProps) { constructor({ streams, logFile }: IndexCategoryGeneratorProps) {
this.streams = streams this.streams = streams
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -48,6 +49,8 @@ export class IndexCategoryGenerator implements Generator {
const playlist = new Playlist(groupedStreams, { public: true }) const playlist = new Playlist(groupedStreams, { public: true })
const filepath = 'index.category.m3u' const filepath = 'index.category.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -1,22 +1,23 @@
import { Generator } from './generator' import { Collection, Storage, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Stream, Playlist, Country } from '../models' import { Stream, Playlist, Country } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexCountryGeneratorProps = { type IndexCountryGeneratorProps = {
streams: Collection streams: Collection
logger: Logger logFile: File
} }
export class IndexCountryGenerator implements Generator { export class IndexCountryGenerator implements Generator {
streams: Collection streams: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, logger }: IndexCountryGeneratorProps) { constructor({ streams, logFile }: IndexCountryGeneratorProps) {
this.streams = streams this.streams = streams
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -56,6 +57,8 @@ export class IndexCountryGenerator implements Generator {
const playlist = new Playlist(groupedStreams, { public: true }) const playlist = new Playlist(groupedStreams, { public: true })
const filepath = 'index.country.m3u' const filepath = 'index.country.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -1,22 +1,23 @@
import { Collection, Logger, Storage } from '@freearhey/core' import { Collection, File, Storage } from '@freearhey/core'
import { Stream, Playlist } from '../models' import { Stream, Playlist } from '../models'
import { Generator } from './generator'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexGeneratorProps = { type IndexGeneratorProps = {
streams: Collection streams: Collection
logger: Logger logFile: File
} }
export class IndexGenerator implements Generator { export class IndexGenerator implements Generator {
streams: Collection streams: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, logger }: IndexGeneratorProps) { constructor({ streams, logFile }: IndexGeneratorProps) {
this.streams = streams this.streams = streams
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -27,6 +28,8 @@ export class IndexGenerator implements Generator {
const playlist = new Playlist(sfwStreams, { public: true }) const playlist = new Playlist(sfwStreams, { public: true })
const filepath = 'index.m3u' const filepath = 'index.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -1,22 +1,23 @@
import { Generator } from './generator' import { Collection, Storage, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Stream, Playlist, Language } from '../models' import { Stream, Playlist, Language } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexLanguageGeneratorProps = { type IndexLanguageGeneratorProps = {
streams: Collection streams: Collection
logger: Logger logFile: File
} }
export class IndexLanguageGenerator implements Generator { export class IndexLanguageGenerator implements Generator {
streams: Collection streams: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, logger }: IndexLanguageGeneratorProps) { constructor({ streams, logFile }: IndexLanguageGeneratorProps) {
this.streams = streams this.streams = streams
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -47,6 +48,8 @@ export class IndexLanguageGenerator implements Generator {
const playlist = new Playlist(groupedStreams, { public: true }) const playlist = new Playlist(groupedStreams, { public: true })
const filepath = 'index.language.m3u' const filepath = 'index.language.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -1,22 +1,23 @@
import { Collection, Logger, Storage } from '@freearhey/core' import { Collection, File, Storage } from '@freearhey/core'
import { Stream, Playlist } from '../models' import { Stream, Playlist } from '../models'
import { Generator } from './generator'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexNsfwGeneratorProps = { type IndexNsfwGeneratorProps = {
streams: Collection streams: Collection
logger: Logger logFile: File
} }
export class IndexNsfwGenerator implements Generator { export class IndexNsfwGenerator implements Generator {
streams: Collection streams: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, logger }: IndexNsfwGeneratorProps) { constructor({ streams, logFile }: IndexNsfwGeneratorProps) {
this.streams = streams this.streams = streams
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -25,6 +26,8 @@ export class IndexNsfwGenerator implements Generator {
const playlist = new Playlist(allStreams, { public: true }) const playlist = new Playlist(allStreams, { public: true })
const filepath = 'index.nsfw.m3u' const filepath = 'index.nsfw.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -1,25 +1,26 @@
import { Generator } from './generator' import { Collection, Storage, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Stream, Playlist, Region } from '../models' import { Stream, Playlist, Region } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexRegionGeneratorProps = { type IndexRegionGeneratorProps = {
streams: Collection streams: Collection
regions: Collection regions: Collection
logger: Logger logFile: File
} }
export class IndexRegionGenerator implements Generator { export class IndexRegionGenerator implements Generator {
streams: Collection streams: Collection
regions: Collection regions: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, regions, logger }: IndexRegionGeneratorProps) { constructor({ streams, regions, logFile }: IndexRegionGeneratorProps) {
this.streams = streams this.streams = streams
this.regions = regions this.regions = regions
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -58,6 +59,8 @@ export class IndexRegionGenerator implements Generator {
const playlist = new Playlist(groupedStreams, { public: true }) const playlist = new Playlist(groupedStreams, { public: true })
const filepath = 'index.region.m3u' const filepath = 'index.region.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -1,19 +1,20 @@
import { Generator } from './generator' import { Collection, Storage, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Playlist, Language, Stream } from '../models' import { Playlist, Language, Stream } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type LanguagesGeneratorProps = { streams: Collection; logger: Logger } type LanguagesGeneratorProps = { streams: Collection; logFile: File }
export class LanguagesGenerator implements Generator { export class LanguagesGenerator implements Generator {
streams: Collection streams: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, logger }: LanguagesGeneratorProps) { constructor({ streams, logFile }: LanguagesGeneratorProps) {
this.streams = streams this.streams = streams
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -38,8 +39,8 @@ export class LanguagesGenerator implements Generator {
const playlist = new Playlist(languageStreams, { public: true }) const playlist = new Playlist(languageStreams, { public: true })
const filepath = `languages/${language.code}.m3u` const filepath = `languages/${language.code}.m3u`
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'language', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'language', filepath, count: playlist.streams.count() }) + EOL
) )
}) })
@ -50,8 +51,8 @@ export class LanguagesGenerator implements Generator {
const playlist = new Playlist(undefinedStreams, { public: true }) const playlist = new Playlist(undefinedStreams, { public: true })
const filepath = 'languages/undefined.m3u' const filepath = 'languages/undefined.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'language', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'language', filepath, count: playlist.streams.count() }) + EOL
) )
} }
} }

View file

@ -1,25 +1,26 @@
import { Generator } from './generator' import { Collection, Storage, File } from '@freearhey/core'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Playlist, Region, Stream } from '../models' import { Playlist, Region, Stream } from '../models'
import { PUBLIC_DIR } from '../constants' import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type RegionsGeneratorProps = { type RegionsGeneratorProps = {
streams: Collection streams: Collection
regions: Collection regions: Collection
logger: Logger logFile: File
} }
export class RegionsGenerator implements Generator { export class RegionsGenerator implements Generator {
streams: Collection streams: Collection
regions: Collection regions: Collection
storage: Storage storage: Storage
logger: Logger logFile: File
constructor({ streams, regions, logger }: RegionsGeneratorProps) { constructor({ streams, regions, logFile }: RegionsGeneratorProps) {
this.streams = streams this.streams = streams
this.regions = regions this.regions = regions
this.storage = new Storage(PUBLIC_DIR) this.storage = new Storage(PUBLIC_DIR)
this.logger = logger this.logFile = logFile
} }
async generate(): Promise<void> { async generate(): Promise<void> {
@ -35,8 +36,8 @@ export class RegionsGenerator implements Generator {
const playlist = new Playlist(regionStreams, { public: true }) const playlist = new Playlist(regionStreams, { public: true })
const filepath = `regions/${region.code.toLowerCase()}.m3u` const filepath = `regions/${region.code.toLowerCase()}.m3u`
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ type: 'region', filepath, count: playlist.streams.count() }) JSON.stringify({ type: 'region', filepath, count: playlist.streams.count() }) + EOL
) )
}) })
@ -44,18 +45,20 @@ export class RegionsGenerator implements Generator {
const internationalPlaylist = new Playlist(internationalStreams, { public: true }) const internationalPlaylist = new Playlist(internationalStreams, { public: true })
const internationalFilepath = 'regions/int.m3u' const internationalFilepath = 'regions/int.m3u'
await this.storage.save(internationalFilepath, internationalPlaylist.toString()) await this.storage.save(internationalFilepath, internationalPlaylist.toString())
this.logger.info( this.logFile.append(
JSON.stringify({ JSON.stringify({
type: 'region', type: 'region',
filepath: internationalFilepath, filepath: internationalFilepath,
count: internationalPlaylist.streams.count() count: internationalPlaylist.streams.count()
}) }) + EOL
) )
const undefinedStreams = streams.filter((stream: Stream) => !stream.hasBroadcastArea()) const undefinedStreams = streams.filter((stream: Stream) => !stream.hasBroadcastArea())
const playlist = new Playlist(undefinedStreams, { public: true }) const playlist = new Playlist(undefinedStreams, { public: true })
const filepath = 'regions/undefined.m3u' const filepath = 'regions/undefined.m3u'
await this.storage.save(filepath, playlist.toString()) await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'region', filepath, count: playlist.streams.count() })) this.logFile.append(
JSON.stringify({ type: 'region', filepath, count: playlist.streams.count() }) + EOL
)
} }
} }

View file

@ -144,8 +144,8 @@ export class Feed {
this.broadcastRegions = regions.filter((region: Region) => { this.broadcastRegions = regions.filter((region: Region) => {
if (region.code === 'INT') return false if (region.code === 'INT') return false
const intersected = region.countryCodes.intersects(countriesCodes)
return region.countryCodes.intersects(countriesCodes) return intersected.notEmpty()
}) })
return this return this