mirror of https://github.com/iptv-org/iptv
Update scripts
parent
5887997bb3
commit
adec9dd131
@ -0,0 +1,151 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { DATA_DIR } from './constants'
|
||||
import cliProgress from 'cli-progress'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
|
||||
const data = {
|
||||
categoriesKeyById: new Dictionary<sdk.Models.Category>(),
|
||||
countriesKeyByCode: new Dictionary<sdk.Models.Country>(),
|
||||
subdivisionsKeyByCode: new Dictionary<sdk.Models.Subdivision>(),
|
||||
citiesKeyByCode: new Dictionary<sdk.Models.City>(),
|
||||
regionsKeyByCode: new Dictionary<sdk.Models.Region>(),
|
||||
languagesKeyByCode: new Dictionary<sdk.Models.Language>(),
|
||||
channelsKeyById: new Dictionary<sdk.Models.Channel>(),
|
||||
feedsKeyByStreamId: new Dictionary<sdk.Models.Feed>(),
|
||||
feedsGroupedByChannel: new Dictionary<sdk.Models.Feed[]>(),
|
||||
blocklistRecordsGroupedByChannel: new Dictionary<sdk.Models.BlocklistRecord[]>(),
|
||||
categories: new Collection<sdk.Models.Category>(),
|
||||
countries: new Collection<sdk.Models.Country>(),
|
||||
subdivisions: new Collection<sdk.Models.Subdivision>(),
|
||||
cities: new Collection<sdk.Models.City>(),
|
||||
regions: new Collection<sdk.Models.Region>()
|
||||
}
|
||||
|
||||
let searchIndex
|
||||
|
||||
async function loadData() {
|
||||
const dataManager = new sdk.DataManager({ dataDir: DATA_DIR })
|
||||
await dataManager.loadFromDisk()
|
||||
dataManager.processData()
|
||||
|
||||
const {
|
||||
channels,
|
||||
feeds,
|
||||
categories,
|
||||
languages,
|
||||
countries,
|
||||
subdivisions,
|
||||
cities,
|
||||
regions,
|
||||
blocklist
|
||||
} = dataManager.getProcessedData()
|
||||
|
||||
searchIndex = sdk.SearchEngine.createIndex<sdk.Models.Channel>(channels)
|
||||
|
||||
data.categoriesKeyById = categories.keyBy((category: sdk.Models.Category) => category.id)
|
||||
data.countriesKeyByCode = countries.keyBy((country: sdk.Models.Country) => country.code)
|
||||
data.subdivisionsKeyByCode = subdivisions.keyBy(
|
||||
(subdivision: sdk.Models.Subdivision) => subdivision.code
|
||||
)
|
||||
data.citiesKeyByCode = cities.keyBy((city: sdk.Models.City) => city.code)
|
||||
data.regionsKeyByCode = regions.keyBy((region: sdk.Models.Region) => region.code)
|
||||
data.languagesKeyByCode = languages.keyBy((language: sdk.Models.Language) => language.code)
|
||||
data.channelsKeyById = channels.keyBy((channel: sdk.Models.Channel) => channel.id)
|
||||
data.feedsKeyByStreamId = feeds.keyBy((feed: sdk.Models.Feed) => feed.getStreamId())
|
||||
data.feedsGroupedByChannel = feeds.groupBy((feed: sdk.Models.Feed) => feed.channel)
|
||||
data.blocklistRecordsGroupedByChannel = blocklist.groupBy(
|
||||
(blocklistRecord: sdk.Models.BlocklistRecord) => blocklistRecord.channel
|
||||
)
|
||||
data.categories = categories
|
||||
data.countries = countries
|
||||
data.subdivisions = subdivisions
|
||||
data.cities = cities
|
||||
data.regions = regions
|
||||
}
|
||||
|
||||
async function downloadData() {
|
||||
function formatBytes(bytes: number) {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
const files = [
|
||||
'blocklist',
|
||||
'categories',
|
||||
'channels',
|
||||
'cities',
|
||||
'countries',
|
||||
'feeds',
|
||||
'guides',
|
||||
'languages',
|
||||
'logos',
|
||||
'regions',
|
||||
'streams',
|
||||
'subdivisions',
|
||||
'timezones'
|
||||
]
|
||||
|
||||
const multiBar = new cliProgress.MultiBar({
|
||||
stopOnComplete: true,
|
||||
hideCursor: true,
|
||||
forceRedraw: true,
|
||||
barsize: 36,
|
||||
format(options, params, payload) {
|
||||
const filename = payload.filename.padEnd(18, ' ')
|
||||
const barsize = options.barsize || 40
|
||||
const percent = (params.progress * 100).toFixed(2)
|
||||
const speed = payload.speed ? formatBytes(payload.speed) + '/s' : 'N/A'
|
||||
const total = formatBytes(params.total)
|
||||
const completeSize = Math.round(params.progress * barsize)
|
||||
const incompleteSize = barsize - completeSize
|
||||
const bar =
|
||||
options.barCompleteString && options.barIncompleteString
|
||||
? options.barCompleteString.substr(0, completeSize) +
|
||||
options.barGlue +
|
||||
options.barIncompleteString.substr(0, incompleteSize)
|
||||
: '-'.repeat(barsize)
|
||||
|
||||
return `${filename} [${bar}] ${percent}% | ETA: ${params.eta}s | ${total} | ${speed}`
|
||||
}
|
||||
})
|
||||
|
||||
const dataManager = new sdk.DataManager({ dataDir: DATA_DIR })
|
||||
|
||||
const requests: Promise<unknown>[] = []
|
||||
for (const basename of files) {
|
||||
const filename = `${basename}.json`
|
||||
const progressBar = multiBar.create(0, 0, { filename })
|
||||
const request = dataManager.downloadFileToDisk(basename, {
|
||||
onDownloadProgress({ total, loaded, rate }) {
|
||||
if (total) progressBar.setTotal(total)
|
||||
progressBar.update(loaded, { speed: rate })
|
||||
}
|
||||
})
|
||||
|
||||
requests.push(request)
|
||||
}
|
||||
|
||||
await Promise.allSettled(requests).catch(console.error)
|
||||
}
|
||||
|
||||
function searchChannels(query: string): Collection<sdk.Models.Channel> {
|
||||
if (!searchIndex) return new Collection<sdk.Models.Channel>()
|
||||
|
||||
const results = searchIndex.search(query)
|
||||
|
||||
const channels = new Collection<sdk.Models.Channel>()
|
||||
|
||||
new Collection<sdk.Types.ChannelSearchableData>(results).forEach(
|
||||
(item: sdk.Types.ChannelSearchableData) => {
|
||||
const channel = data.channelsKeyById.get(item.id)
|
||||
if (channel) channels.add(channel)
|
||||
}
|
||||
)
|
||||
|
||||
return channels
|
||||
}
|
||||
|
||||
export { data, loadData, downloadData, searchChannels }
|
||||
@ -1,39 +1,31 @@
|
||||
import { DataLoader, DataProcessor, PlaylistParser } from '../../core'
|
||||
import type { DataProcessorData } from '../../types/dataProcessor'
|
||||
import { API_DIR, STREAMS_DIR, DATA_DIR } from '../../constants'
|
||||
import type { DataLoaderData } from '../../types/dataLoader'
|
||||
import { Logger, Storage } from '@freearhey/core'
|
||||
import { API_DIR, STREAMS_DIR } from '../../constants'
|
||||
import { Storage } from '@freearhey/storage-js'
|
||||
import { PlaylistParser } from '../../core'
|
||||
import { Logger } from '@freearhey/core'
|
||||
import { Stream } from '../../models'
|
||||
import { loadData } from '../../api'
|
||||
|
||||
async function main() {
|
||||
const logger = new Logger()
|
||||
|
||||
logger.info('loading data from api...')
|
||||
const processor = new DataProcessor()
|
||||
const dataStorage = new Storage(DATA_DIR)
|
||||
const dataLoader = new DataLoader({ storage: dataStorage })
|
||||
const data: DataLoaderData = await dataLoader.load()
|
||||
const { channelsKeyById, feedsGroupedByChannelId, logosGroupedByStreamId }: DataProcessorData =
|
||||
processor.process(data)
|
||||
await loadData()
|
||||
|
||||
logger.info('loading streams...')
|
||||
const streamsStorage = new Storage(STREAMS_DIR)
|
||||
const parser = new PlaylistParser({
|
||||
storage: streamsStorage,
|
||||
channelsKeyById,
|
||||
logosGroupedByStreamId,
|
||||
feedsGroupedByChannelId
|
||||
storage: streamsStorage
|
||||
})
|
||||
const files = await streamsStorage.list('**/*.m3u')
|
||||
let streams = await parser.parse(files)
|
||||
streams = streams
|
||||
.orderBy((stream: Stream) => stream.getId())
|
||||
.map((stream: Stream) => stream.toJSON())
|
||||
logger.info(`found ${streams.count()} streams`)
|
||||
const parsed = await parser.parse(files)
|
||||
const _streams = parsed
|
||||
.sortBy((stream: Stream) => stream.getId())
|
||||
.map((stream: Stream) => stream.toObject())
|
||||
logger.info(`found ${_streams.count()} streams`)
|
||||
|
||||
logger.info('saving to .api/streams.json...')
|
||||
const apiStorage = new Storage(API_DIR)
|
||||
await apiStorage.save('streams.json', streams.toJSON())
|
||||
await apiStorage.save('streams.json', _streams.toJSON())
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@ -1,26 +1,7 @@
|
||||
import { DATA_DIR } from '../../constants'
|
||||
import { Storage } from '@freearhey/core'
|
||||
import { DataLoader } from '../../core'
|
||||
import { downloadData } from '../../api'
|
||||
|
||||
async function main() {
|
||||
const storage = new Storage(DATA_DIR)
|
||||
const loader = new DataLoader({ storage })
|
||||
|
||||
await Promise.all([
|
||||
loader.download('blocklist.json'),
|
||||
loader.download('categories.json'),
|
||||
loader.download('channels.json'),
|
||||
loader.download('countries.json'),
|
||||
loader.download('languages.json'),
|
||||
loader.download('regions.json'),
|
||||
loader.download('subdivisions.json'),
|
||||
loader.download('feeds.json'),
|
||||
loader.download('logos.json'),
|
||||
loader.download('timezones.json'),
|
||||
loader.download('guides.json'),
|
||||
loader.download('streams.json'),
|
||||
loader.download('cities.json')
|
||||
])
|
||||
await downloadData()
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
import axios, { AxiosInstance, AxiosResponse, AxiosRequestConfig } from 'axios'
|
||||
|
||||
export class ApiClient {
|
||||
instance: AxiosInstance
|
||||
|
||||
constructor() {
|
||||
this.instance = axios.create({
|
||||
baseURL: 'https://iptv-org.github.io/api',
|
||||
responseType: 'stream'
|
||||
})
|
||||
}
|
||||
|
||||
get(url: string, options: AxiosRequestConfig): Promise<AxiosResponse> {
|
||||
return this.instance.get(url, options)
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
import { ApiClient } from './apiClient'
|
||||
import { Storage } from '@freearhey/core'
|
||||
import cliProgress, { MultiBar } from 'cli-progress'
|
||||
import type { DataLoaderProps, DataLoaderData } from '../types/dataLoader'
|
||||
|
||||
const formatBytes = (bytes: number) => {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
export class DataLoader {
|
||||
client: ApiClient
|
||||
storage: Storage
|
||||
progressBar: MultiBar
|
||||
|
||||
constructor(props: DataLoaderProps) {
|
||||
this.client = new ApiClient()
|
||||
this.storage = props.storage
|
||||
this.progressBar = new cliProgress.MultiBar({
|
||||
stopOnComplete: true,
|
||||
hideCursor: true,
|
||||
forceRedraw: true,
|
||||
barsize: 36,
|
||||
format(options, params, payload) {
|
||||
const filename = payload.filename.padEnd(18, ' ')
|
||||
const barsize = options.barsize || 40
|
||||
const percent = (params.progress * 100).toFixed(2)
|
||||
const speed = payload.speed ? formatBytes(payload.speed) + '/s' : 'N/A'
|
||||
const total = formatBytes(params.total)
|
||||
const completeSize = Math.round(params.progress * barsize)
|
||||
const incompleteSize = barsize - completeSize
|
||||
const bar =
|
||||
options.barCompleteString && options.barIncompleteString
|
||||
? options.barCompleteString.substr(0, completeSize) +
|
||||
options.barGlue +
|
||||
options.barIncompleteString.substr(0, incompleteSize)
|
||||
: '-'.repeat(barsize)
|
||||
|
||||
return `${filename} [${bar}] ${percent}% | ETA: ${params.eta}s | ${total} | ${speed}`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async load(): Promise<DataLoaderData> {
|
||||
const [
|
||||
countries,
|
||||
regions,
|
||||
subdivisions,
|
||||
languages,
|
||||
categories,
|
||||
blocklist,
|
||||
channels,
|
||||
feeds,
|
||||
logos,
|
||||
timezones,
|
||||
guides,
|
||||
streams,
|
||||
cities
|
||||
] = await Promise.all([
|
||||
this.storage.json('countries.json'),
|
||||
this.storage.json('regions.json'),
|
||||
this.storage.json('subdivisions.json'),
|
||||
this.storage.json('languages.json'),
|
||||
this.storage.json('categories.json'),
|
||||
this.storage.json('blocklist.json'),
|
||||
this.storage.json('channels.json'),
|
||||
this.storage.json('feeds.json'),
|
||||
this.storage.json('logos.json'),
|
||||
this.storage.json('timezones.json'),
|
||||
this.storage.json('guides.json'),
|
||||
this.storage.json('streams.json'),
|
||||
this.storage.json('cities.json')
|
||||
])
|
||||
|
||||
return {
|
||||
countries,
|
||||
regions,
|
||||
subdivisions,
|
||||
languages,
|
||||
categories,
|
||||
blocklist,
|
||||
channels,
|
||||
feeds,
|
||||
logos,
|
||||
timezones,
|
||||
guides,
|
||||
streams,
|
||||
cities
|
||||
}
|
||||
}
|
||||
|
||||
async download(filename: string) {
|
||||
if (!this.storage || !this.progressBar) return
|
||||
|
||||
const stream = await this.storage.createStream(filename)
|
||||
const progressBar = this.progressBar.create(0, 0, { filename })
|
||||
|
||||
this.client
|
||||
.get(filename, {
|
||||
responseType: 'stream',
|
||||
onDownloadProgress({ total, loaded, rate }) {
|
||||
if (total) progressBar.setTotal(total)
|
||||
progressBar.update(loaded, { speed: rate })
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
response.data.pipe(stream)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,165 +0,0 @@
|
||||
import { DataProcessorData } from '../types/dataProcessor'
|
||||
import { DataLoaderData } from '../types/dataLoader'
|
||||
import { Collection } from '@freearhey/core'
|
||||
import {
|
||||
BlocklistRecord,
|
||||
Subdivision,
|
||||
Category,
|
||||
Language,
|
||||
Timezone,
|
||||
Channel,
|
||||
Country,
|
||||
Region,
|
||||
Stream,
|
||||
Guide,
|
||||
City,
|
||||
Feed,
|
||||
Logo
|
||||
} from '../models'
|
||||
|
||||
export class DataProcessor {
|
||||
process(data: DataLoaderData): DataProcessorData {
|
||||
let regions = new Collection(data.regions).map(data => new Region(data))
|
||||
let regionsKeyByCode = regions.keyBy((region: Region) => region.code)
|
||||
|
||||
const categories = new Collection(data.categories).map(data => new Category(data))
|
||||
const categoriesKeyById = categories.keyBy((category: Category) => category.id)
|
||||
|
||||
const languages = new Collection(data.languages).map(data => new Language(data))
|
||||
const languagesKeyByCode = languages.keyBy((language: Language) => language.code)
|
||||
|
||||
let subdivisions = new Collection(data.subdivisions).map(data => new Subdivision(data))
|
||||
let subdivisionsKeyByCode = subdivisions.keyBy((subdivision: Subdivision) => subdivision.code)
|
||||
let subdivisionsGroupedByCountryCode = subdivisions.groupBy(
|
||||
(subdivision: Subdivision) => subdivision.countryCode
|
||||
)
|
||||
|
||||
let countries = new Collection(data.countries).map(data => new Country(data))
|
||||
let countriesKeyByCode = countries.keyBy((country: Country) => country.code)
|
||||
|
||||
const cities = new Collection(data.cities).map(data =>
|
||||
new City(data)
|
||||
.withRegions(regions)
|
||||
.withCountry(countriesKeyByCode)
|
||||
.withSubdivision(subdivisionsKeyByCode)
|
||||
)
|
||||
const citiesKeyByCode = cities.keyBy((city: City) => city.code)
|
||||
const citiesGroupedByCountryCode = cities.groupBy((city: City) => city.countryCode)
|
||||
const citiesGroupedBySubdivisionCode = cities.groupBy((city: City) => city.subdivisionCode)
|
||||
|
||||
const timezones = new Collection(data.timezones).map(data =>
|
||||
new Timezone(data).withCountries(countriesKeyByCode)
|
||||
)
|
||||
const timezonesKeyById = timezones.keyBy((timezone: Timezone) => timezone.id)
|
||||
|
||||
const blocklistRecords = new Collection(data.blocklist).map(data => new BlocklistRecord(data))
|
||||
const blocklistRecordsGroupedByChannelId = blocklistRecords.groupBy(
|
||||
(blocklistRecord: BlocklistRecord) => blocklistRecord.channelId
|
||||
)
|
||||
|
||||
let channels = new Collection(data.channels).map(data => new Channel(data))
|
||||
let channelsKeyById = channels.keyBy((channel: Channel) => channel.id)
|
||||
|
||||
let feeds = new Collection(data.feeds).map(data => new Feed(data))
|
||||
let feedsGroupedByChannelId = feeds.groupBy((feed: Feed) => feed.channelId)
|
||||
let feedsGroupedById = feeds.groupBy((feed: Feed) => feed.id)
|
||||
|
||||
const logos = new Collection(data.logos).map(data => new Logo(data).withFeed(feedsGroupedById))
|
||||
const logosGroupedByChannelId = logos.groupBy((logo: Logo) => logo.channelId)
|
||||
const logosGroupedByStreamId = logos.groupBy((logo: Logo) => logo.getStreamId())
|
||||
|
||||
const streams = new Collection(data.streams).map(data =>
|
||||
new Stream(data).withLogos(logosGroupedByStreamId)
|
||||
)
|
||||
const streamsGroupedById = streams.groupBy((stream: Stream) => stream.getId())
|
||||
|
||||
const guides = new Collection(data.guides).map(data => new Guide(data))
|
||||
const guidesGroupedByStreamId = guides.groupBy((guide: Guide) => guide.getStreamId())
|
||||
|
||||
regions = regions.map((region: Region) =>
|
||||
region
|
||||
.withCountries(countriesKeyByCode)
|
||||
.withRegions(regions)
|
||||
.withSubdivisions(subdivisions)
|
||||
.withCities(cities)
|
||||
)
|
||||
regionsKeyByCode = regions.keyBy((region: Region) => region.code)
|
||||
|
||||
countries = countries.map((country: Country) =>
|
||||
country
|
||||
.withCities(citiesGroupedByCountryCode)
|
||||
.withSubdivisions(subdivisionsGroupedByCountryCode)
|
||||
.withRegions(regions)
|
||||
.withLanguage(languagesKeyByCode)
|
||||
)
|
||||
countriesKeyByCode = countries.keyBy((country: Country) => country.code)
|
||||
|
||||
subdivisions = subdivisions.map((subdivision: Subdivision) =>
|
||||
subdivision
|
||||
.withCities(citiesGroupedBySubdivisionCode)
|
||||
.withCountry(countriesKeyByCode)
|
||||
.withRegions(regions)
|
||||
.withParent(subdivisionsKeyByCode)
|
||||
)
|
||||
subdivisionsKeyByCode = subdivisions.keyBy((subdivision: Subdivision) => subdivision.code)
|
||||
subdivisionsGroupedByCountryCode = subdivisions.groupBy(
|
||||
(subdivision: Subdivision) => subdivision.countryCode
|
||||
)
|
||||
|
||||
channels = channels.map((channel: Channel) =>
|
||||
channel
|
||||
.withFeeds(feedsGroupedByChannelId)
|
||||
.withLogos(logosGroupedByChannelId)
|
||||
.withCategories(categoriesKeyById)
|
||||
.withCountry(countriesKeyByCode)
|
||||
.withSubdivision(subdivisionsKeyByCode)
|
||||
.withCategories(categoriesKeyById)
|
||||
)
|
||||
channelsKeyById = channels.keyBy((channel: Channel) => channel.id)
|
||||
|
||||
feeds = feeds.map((feed: Feed) =>
|
||||
feed
|
||||
.withChannel(channelsKeyById)
|
||||
.withLanguages(languagesKeyByCode)
|
||||
.withTimezones(timezonesKeyById)
|
||||
.withBroadcastArea(
|
||||
citiesKeyByCode,
|
||||
subdivisionsKeyByCode,
|
||||
countriesKeyByCode,
|
||||
regionsKeyByCode
|
||||
)
|
||||
)
|
||||
feedsGroupedByChannelId = feeds.groupBy((feed: Feed) => feed.channelId)
|
||||
feedsGroupedById = feeds.groupBy((feed: Feed) => feed.id)
|
||||
|
||||
return {
|
||||
blocklistRecordsGroupedByChannelId,
|
||||
subdivisionsGroupedByCountryCode,
|
||||
feedsGroupedByChannelId,
|
||||
guidesGroupedByStreamId,
|
||||
logosGroupedByStreamId,
|
||||
subdivisionsKeyByCode,
|
||||
countriesKeyByCode,
|
||||
languagesKeyByCode,
|
||||
streamsGroupedById,
|
||||
categoriesKeyById,
|
||||
timezonesKeyById,
|
||||
regionsKeyByCode,
|
||||
blocklistRecords,
|
||||
channelsKeyById,
|
||||
citiesKeyByCode,
|
||||
subdivisions,
|
||||
categories,
|
||||
countries,
|
||||
languages,
|
||||
timezones,
|
||||
channels,
|
||||
regions,
|
||||
streams,
|
||||
cities,
|
||||
guides,
|
||||
feeds,
|
||||
logos
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
import { Collection, File, Storage } from '@freearhey/core'
|
||||
import { Stream, Playlist } from '../models'
|
||||
import { PUBLIC_DIR, EOL } from '../constants'
|
||||
import { Generator } from './generator'
|
||||
|
||||
type IndexNsfwGeneratorProps = {
|
||||
streams: Collection
|
||||
logFile: File
|
||||
}
|
||||
|
||||
export class IndexNsfwGenerator implements Generator {
|
||||
streams: Collection
|
||||
storage: Storage
|
||||
logFile: File
|
||||
|
||||
constructor({ streams, logFile }: IndexNsfwGeneratorProps) {
|
||||
this.streams = streams.clone()
|
||||
this.storage = new Storage(PUBLIC_DIR)
|
||||
this.logFile = logFile
|
||||
}
|
||||
|
||||
async generate(): Promise<void> {
|
||||
const allStreams = this.streams.orderBy((stream: Stream) => stream.getTitle())
|
||||
|
||||
const playlist = new Playlist(allStreams, { public: true })
|
||||
const filepath = 'index.nsfw.m3u'
|
||||
await this.storage.save(filepath, playlist.toString())
|
||||
this.logFile.append(
|
||||
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
import type { BlocklistRecordData } from '../types/blocklistRecord'
|
||||
|
||||
export class BlocklistRecord {
|
||||
channelId: string
|
||||
reason: string
|
||||
ref: string
|
||||
|
||||
constructor(data?: BlocklistRecordData) {
|
||||
if (!data) return
|
||||
|
||||
this.channelId = data.channel
|
||||
this.reason = data.reason
|
||||
this.ref = data.ref
|
||||
}
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { City, Subdivision, Region, Country } from './'
|
||||
|
||||
export class BroadcastArea {
|
||||
codes: Collection
|
||||
citiesIncluded: Collection
|
||||
subdivisionsIncluded: Collection
|
||||
countriesIncluded: Collection
|
||||
regionsIncluded: Collection
|
||||
|
||||
constructor(codes: Collection) {
|
||||
this.codes = codes
|
||||
}
|
||||
|
||||
withLocations(
|
||||
citiesKeyByCode: Dictionary,
|
||||
subdivisionsKeyByCode: Dictionary,
|
||||
countriesKeyByCode: Dictionary,
|
||||
regionsKeyByCode: Dictionary
|
||||
): this {
|
||||
const citiesIncluded = new Collection()
|
||||
const subdivisionsIncluded = new Collection()
|
||||
const countriesIncluded = new Collection()
|
||||
let regionsIncluded = new Collection()
|
||||
|
||||
this.codes.forEach((value: string) => {
|
||||
const [type, code] = value.split('/')
|
||||
|
||||
switch (type) {
|
||||
case 'ct': {
|
||||
const city: City = citiesKeyByCode.get(code)
|
||||
if (!city) return
|
||||
citiesIncluded.add(city)
|
||||
if (city.subdivision) subdivisionsIncluded.add(city.subdivision)
|
||||
if (city.subdivision && city.subdivision.parent)
|
||||
subdivisionsIncluded.add(city.subdivision.parent)
|
||||
if (city.country) countriesIncluded.add(city.country)
|
||||
regionsIncluded = regionsIncluded.concat(city.getRegions())
|
||||
break
|
||||
}
|
||||
case 's': {
|
||||
const subdivision: Subdivision = subdivisionsKeyByCode.get(code)
|
||||
if (!subdivision) return
|
||||
subdivisionsIncluded.add(subdivision)
|
||||
if (subdivision.country) countriesIncluded.add(subdivision.country)
|
||||
regionsIncluded = regionsIncluded.concat(subdivision.getRegions())
|
||||
break
|
||||
}
|
||||
case 'c': {
|
||||
const country: Country = countriesKeyByCode.get(code)
|
||||
if (!country) return
|
||||
countriesIncluded.add(country)
|
||||
regionsIncluded = regionsIncluded.concat(country.getRegions())
|
||||
break
|
||||
}
|
||||
case 'r': {
|
||||
const region: Region = regionsKeyByCode.get(code)
|
||||
if (!region) return
|
||||
regionsIncluded = regionsIncluded.concat(region.getRegions())
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.citiesIncluded = citiesIncluded.uniqBy((city: City) => city.code)
|
||||
this.subdivisionsIncluded = subdivisionsIncluded.uniqBy(
|
||||
(subdivision: Subdivision) => subdivision.code
|
||||
)
|
||||
this.countriesIncluded = countriesIncluded.uniqBy((country: Country) => country.code)
|
||||
this.regionsIncluded = regionsIncluded.uniqBy((region: Region) => region.code)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getCountries(): Collection {
|
||||
return this.countriesIncluded || new Collection()
|
||||
}
|
||||
|
||||
getSubdivisions(): Collection {
|
||||
return this.subdivisionsIncluded || new Collection()
|
||||
}
|
||||
|
||||
getCities(): Collection {
|
||||
return this.citiesIncluded || new Collection()
|
||||
}
|
||||
|
||||
getRegions(): Collection {
|
||||
return this.regionsIncluded || new Collection()
|
||||
}
|
||||
|
||||
includesCountry(country: Country): boolean {
|
||||
return this.getCountries().includes((_country: Country) => _country.code === country.code)
|
||||
}
|
||||
|
||||
includesSubdivision(subdivision: Subdivision): boolean {
|
||||
return this.getSubdivisions().includes(
|
||||
(_subdivision: Subdivision) => _subdivision.code === subdivision.code
|
||||
)
|
||||
}
|
||||
|
||||
includesRegion(region: Region): boolean {
|
||||
return this.getRegions().includes((_region: Region) => _region.code === region.code)
|
||||
}
|
||||
|
||||
includesCity(city: City): boolean {
|
||||
return this.getCities().includes((_city: City) => _city.code === city.code)
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
import type { CategoryData, CategorySerializedData } from '../types/category'
|
||||
|
||||
export class Category {
|
||||
id: string
|
||||
name: string
|
||||
|
||||
constructor(data: CategoryData) {
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
}
|
||||
|
||||
serialize(): CategorySerializedData {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,233 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { Category, Country, Feed, Guide, Logo, Stream, Subdivision } from './index'
|
||||
import type { ChannelData, ChannelSearchableData, ChannelSerializedData } from '../types/channel'
|
||||
|
||||
export class Channel {
|
||||
id: string
|
||||
name: string
|
||||
altNames: Collection
|
||||
network?: string
|
||||
owners: Collection
|
||||
countryCode: string
|
||||
country?: Country
|
||||
subdivisionCode?: string
|
||||
subdivision?: Subdivision
|
||||
cityName?: string
|
||||
categoryIds: Collection
|
||||
categories: Collection = new Collection()
|
||||
isNSFW: boolean
|
||||
launched?: string
|
||||
closed?: string
|
||||
replacedBy?: string
|
||||
isClosed: boolean
|
||||
website?: string
|
||||
feeds?: Collection
|
||||
logos: Collection = new Collection()
|
||||
|
||||
constructor(data?: ChannelData) {
|
||||
if (!data) return
|
||||
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
this.altNames = new Collection(data.alt_names)
|
||||
this.network = data.network || undefined
|
||||
this.owners = new Collection(data.owners)
|
||||
this.countryCode = data.country
|
||||
this.subdivisionCode = data.subdivision || undefined
|
||||
this.cityName = data.city || undefined
|
||||
this.categoryIds = new Collection(data.categories)
|
||||
this.isNSFW = data.is_nsfw
|
||||
this.launched = data.launched || undefined
|
||||
this.closed = data.closed || undefined
|
||||
this.replacedBy = data.replaced_by || undefined
|
||||
this.website = data.website || undefined
|
||||
this.isClosed = !!data.closed || !!data.replaced_by
|
||||
}
|
||||
|
||||
withSubdivision(subdivisionsKeyByCode: Dictionary): this {
|
||||
if (!this.subdivisionCode) return this
|
||||
|
||||
this.subdivision = subdivisionsKeyByCode.get(this.subdivisionCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withCountry(countriesKeyByCode: Dictionary): this {
|
||||
this.country = countriesKeyByCode.get(this.countryCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withCategories(categoriesKeyById: Dictionary): this {
|
||||
this.categories = this.categoryIds
|
||||
.map((id: string) => categoriesKeyById.get(id))
|
||||
.filter(Boolean)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withFeeds(feedsGroupedByChannelId: Dictionary): this {
|
||||
this.feeds = new Collection(feedsGroupedByChannelId.get(this.id))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withLogos(logosGroupedByChannelId: Dictionary): this {
|
||||
if (this.id) this.logos = new Collection(logosGroupedByChannelId.get(this.id))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getCountry(): Country | undefined {
|
||||
return this.country
|
||||
}
|
||||
|
||||
getSubdivision(): Subdivision | undefined {
|
||||
return this.subdivision
|
||||
}
|
||||
|
||||
getCategories(): Collection {
|
||||
return this.categories || new Collection()
|
||||
}
|
||||
|
||||
hasCategories(): boolean {
|
||||
return !!this.categories && this.categories.notEmpty()
|
||||
}
|
||||
|
||||
hasCategory(category: Category): boolean {
|
||||
return (
|
||||
!!this.categories &&
|
||||
this.categories.includes((_category: Category) => _category.id === category.id)
|
||||
)
|
||||
}
|
||||
|
||||
getFeeds(): Collection {
|
||||
if (!this.feeds) return new Collection()
|
||||
|
||||
return this.feeds
|
||||
}
|
||||
|
||||
getGuides(): Collection {
|
||||
let guides = new Collection()
|
||||
|
||||
this.getFeeds().forEach((feed: Feed) => {
|
||||
guides = guides.concat(feed.getGuides())
|
||||
})
|
||||
|
||||
return guides
|
||||
}
|
||||
|
||||
getGuideNames(): Collection {
|
||||
return this.getGuides()
|
||||
.map((guide: Guide) => guide.siteName)
|
||||
.uniq()
|
||||
}
|
||||
|
||||
getStreams(): Collection {
|
||||
let streams = new Collection()
|
||||
|
||||
this.getFeeds().forEach((feed: Feed) => {
|
||||
streams = streams.concat(feed.getStreams())
|
||||
})
|
||||
|
||||
return streams
|
||||
}
|
||||
|
||||
getStreamTitles(): Collection {
|
||||
return this.getStreams()
|
||||
.map((stream: Stream) => stream.getTitle())
|
||||
.uniq()
|
||||
}
|
||||
|
||||
getFeedFullNames(): Collection {
|
||||
return this.getFeeds()
|
||||
.map((feed: Feed) => feed.getFullName())
|
||||
.uniq()
|
||||
}
|
||||
|
||||
isSFW(): boolean {
|
||||
return this.isNSFW === false
|
||||
}
|
||||
|
||||
getLogos(): Collection {
|
||||
function feed(logo: Logo): number {
|
||||
if (!logo.feed) return 1
|
||||
if (logo.feed.isMain) return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function format(logo: Logo): number {
|
||||
const levelByFormat = { SVG: 0, PNG: 3, APNG: 1, WebP: 1, AVIF: 1, JPEG: 2, GIF: 1 }
|
||||
|
||||
return logo.format ? levelByFormat[logo.format] : 0
|
||||
}
|
||||
|
||||
function size(logo: Logo): number {
|
||||
return Math.abs(512 - logo.width) + Math.abs(512 - logo.height)
|
||||
}
|
||||
|
||||
return this.logos.orderBy([feed, format, size], ['desc', 'desc', 'asc'], false)
|
||||
}
|
||||
|
||||
getLogo(): Logo | undefined {
|
||||
return this.getLogos().first()
|
||||
}
|
||||
|
||||
hasLogo(): boolean {
|
||||
return this.getLogos().notEmpty()
|
||||
}
|
||||
|
||||
getSearchable(): ChannelSearchableData {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
altNames: this.altNames.all(),
|
||||
guideNames: this.getGuideNames().all(),
|
||||
streamTitles: this.getStreamTitles().all(),
|
||||
feedFullNames: this.getFeedFullNames().all()
|
||||
}
|
||||
}
|
||||
|
||||
serialize(): ChannelSerializedData {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
altNames: this.altNames.all(),
|
||||
network: this.network,
|
||||
owners: this.owners.all(),
|
||||
countryCode: this.countryCode,
|
||||
country: this.country ? this.country.serialize() : undefined,
|
||||
subdivisionCode: this.subdivisionCode,
|
||||
subdivision: this.subdivision ? this.subdivision.serialize() : undefined,
|
||||
cityName: this.cityName,
|
||||
categoryIds: this.categoryIds.all(),
|
||||
categories: this.categories.map((category: Category) => category.serialize()).all(),
|
||||
isNSFW: this.isNSFW,
|
||||
launched: this.launched,
|
||||
closed: this.closed,
|
||||
replacedBy: this.replacedBy,
|
||||
website: this.website
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: ChannelSerializedData): this {
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
this.altNames = new Collection(data.altNames)
|
||||
this.network = data.network
|
||||
this.owners = new Collection(data.owners)
|
||||
this.countryCode = data.countryCode
|
||||
this.country = data.country ? new Country().deserialize(data.country) : undefined
|
||||
this.subdivisionCode = data.subdivisionCode
|
||||
this.cityName = data.cityName
|
||||
this.categoryIds = new Collection(data.categoryIds)
|
||||
this.isNSFW = data.isNSFW
|
||||
this.launched = data.launched
|
||||
this.closed = data.closed
|
||||
this.replacedBy = data.replacedBy
|
||||
this.website = data.website
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { Country, Region, Subdivision } from '.'
|
||||
import type { CityData, CitySerializedData } from '../types/city'
|
||||
|
||||
export class City {
|
||||
code: string
|
||||
name: string
|
||||
countryCode: string
|
||||
country?: Country
|
||||
subdivisionCode?: string
|
||||
subdivision?: Subdivision
|
||||
wikidataId: string
|
||||
regions?: Collection
|
||||
|
||||
constructor(data?: CityData) {
|
||||
if (!data) return
|
||||
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.country
|
||||
this.subdivisionCode = data.subdivision || undefined
|
||||
this.wikidataId = data.wikidata_id
|
||||
}
|
||||
|
||||
withCountry(countriesKeyByCode: Dictionary): this {
|
||||
this.country = countriesKeyByCode.get(this.countryCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withSubdivision(subdivisionsKeyByCode: Dictionary): this {
|
||||
if (!this.subdivisionCode) return this
|
||||
|
||||
this.subdivision = subdivisionsKeyByCode.get(this.subdivisionCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withRegions(regions: Collection): this {
|
||||
this.regions = regions.filter((region: Region) =>
|
||||
region.countryCodes.includes(this.countryCode)
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getRegions(): Collection {
|
||||
if (!this.regions) return new Collection()
|
||||
|
||||
return this.regions
|
||||
}
|
||||
|
||||
serialize(): CitySerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
countryCode: this.countryCode,
|
||||
country: this.country ? this.country.serialize() : undefined,
|
||||
subdivisionCode: this.subdivisionCode || null,
|
||||
subdivision: this.subdivision ? this.subdivision.serialize() : undefined,
|
||||
wikidataId: this.wikidataId
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: CitySerializedData): this {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.countryCode
|
||||
this.country = data.country ? new Country().deserialize(data.country) : undefined
|
||||
this.subdivisionCode = data.subdivisionCode || undefined
|
||||
this.subdivision = data.subdivision
|
||||
? new Subdivision().deserialize(data.subdivision)
|
||||
: undefined
|
||||
this.wikidataId = data.wikidataId
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { Region, Language, Subdivision } from '.'
|
||||
import type { CountryData, CountrySerializedData } from '../types/country'
|
||||
import { SubdivisionSerializedData } from '../types/subdivision'
|
||||
import { RegionSerializedData } from '../types/region'
|
||||
|
||||
export class Country {
|
||||
code: string
|
||||
name: string
|
||||
flag: string
|
||||
languageCode: string
|
||||
language?: Language
|
||||
subdivisions?: Collection
|
||||
regions?: Collection
|
||||
cities?: Collection
|
||||
|
||||
constructor(data?: CountryData) {
|
||||
if (!data) return
|
||||
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.flag = data.flag
|
||||
this.languageCode = data.lang
|
||||
}
|
||||
|
||||
withSubdivisions(subdivisionsGroupedByCountryCode: Dictionary): this {
|
||||
this.subdivisions = new Collection(subdivisionsGroupedByCountryCode.get(this.code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withRegions(regions: Collection): this {
|
||||
this.regions = regions.filter((region: Region) => region.includesCountryCode(this.code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withCities(citiesGroupedByCountryCode: Dictionary): this {
|
||||
this.cities = new Collection(citiesGroupedByCountryCode.get(this.code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withLanguage(languagesKeyByCode: Dictionary): this {
|
||||
this.language = languagesKeyByCode.get(this.languageCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getLanguage(): Language | undefined {
|
||||
return this.language
|
||||
}
|
||||
|
||||
getRegions(): Collection {
|
||||
return this.regions || new Collection()
|
||||
}
|
||||
|
||||
getSubdivisions(): Collection {
|
||||
return this.subdivisions || new Collection()
|
||||
}
|
||||
|
||||
getCities(): Collection {
|
||||
return this.cities || new Collection()
|
||||
}
|
||||
|
||||
serialize(): CountrySerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
flag: this.flag,
|
||||
languageCode: this.languageCode,
|
||||
language: this.language ? this.language.serialize() : null,
|
||||
subdivisions: this.subdivisions
|
||||
? this.subdivisions.map((subdivision: Subdivision) => subdivision.serialize()).all()
|
||||
: [],
|
||||
regions: this.regions ? this.regions.map((region: Region) => region.serialize()).all() : []
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: CountrySerializedData): this {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.flag = data.flag
|
||||
this.languageCode = data.languageCode
|
||||
this.language = data.language ? new Language().deserialize(data.language) : undefined
|
||||
this.subdivisions = new Collection(data.subdivisions).map((data: SubdivisionSerializedData) =>
|
||||
new Subdivision().deserialize(data)
|
||||
)
|
||||
this.regions = new Collection(data.regions).map((data: RegionSerializedData) =>
|
||||
new Region().deserialize(data)
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,170 +0,0 @@
|
||||
import { Country, Language, Region, Channel, Subdivision, BroadcastArea, City } from './index'
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import type { FeedData } from '../types/feed'
|
||||
|
||||
export class Feed {
|
||||
channelId: string
|
||||
channel?: Channel
|
||||
id: string
|
||||
name: string
|
||||
isMain: boolean
|
||||
broadcastAreaCodes: Collection
|
||||
broadcastArea?: BroadcastArea
|
||||
languageCodes: Collection
|
||||
languages?: Collection
|
||||
timezoneIds: Collection
|
||||
timezones?: Collection
|
||||
videoFormat: string
|
||||
guides?: Collection
|
||||
streams?: Collection
|
||||
|
||||
constructor(data: FeedData) {
|
||||
this.channelId = data.channel
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
this.isMain = data.is_main
|
||||
this.broadcastAreaCodes = new Collection(data.broadcast_area)
|
||||
this.languageCodes = new Collection(data.languages)
|
||||
this.timezoneIds = new Collection(data.timezones)
|
||||
this.videoFormat = data.video_format
|
||||
}
|
||||
|
||||
withChannel(channelsKeyById: Dictionary): this {
|
||||
this.channel = channelsKeyById.get(this.channelId)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withStreams(streamsGroupedById: Dictionary): this {
|
||||
this.streams = new Collection(streamsGroupedById.get(`${this.channelId}@${this.id}`))
|
||||
|
||||
if (this.isMain) {
|
||||
this.streams = this.streams.concat(new Collection(streamsGroupedById.get(this.channelId)))
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withGuides(guidesGroupedByStreamId: Dictionary): this {
|
||||
this.guides = new Collection(guidesGroupedByStreamId.get(`${this.channelId}@${this.id}`))
|
||||
|
||||
if (this.isMain) {
|
||||
this.guides = this.guides.concat(new Collection(guidesGroupedByStreamId.get(this.channelId)))
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withLanguages(languagesKeyByCode: Dictionary): this {
|
||||
this.languages = this.languageCodes
|
||||
.map((code: string) => languagesKeyByCode.get(code))
|
||||
.filter(Boolean)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withTimezones(timezonesKeyById: Dictionary): this {
|
||||
this.timezones = this.timezoneIds.map((id: string) => timezonesKeyById.get(id)).filter(Boolean)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withBroadcastArea(
|
||||
citiesKeyByCode: Dictionary,
|
||||
subdivisionsKeyByCode: Dictionary,
|
||||
countriesKeyByCode: Dictionary,
|
||||
regionsKeyByCode: Dictionary
|
||||
): this {
|
||||
this.broadcastArea = new BroadcastArea(this.broadcastAreaCodes).withLocations(
|
||||
citiesKeyByCode,
|
||||
subdivisionsKeyByCode,
|
||||
countriesKeyByCode,
|
||||
regionsKeyByCode
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
hasBroadcastArea(): boolean {
|
||||
return !!this.broadcastArea
|
||||
}
|
||||
|
||||
getBroadcastCountries(): Collection {
|
||||
if (!this.broadcastArea) return new Collection()
|
||||
|
||||
return this.broadcastArea.getCountries()
|
||||
}
|
||||
|
||||
getBroadcastRegions(): Collection {
|
||||
if (!this.broadcastArea) return new Collection()
|
||||
|
||||
return this.broadcastArea.getRegions()
|
||||
}
|
||||
|
||||
getTimezones(): Collection {
|
||||
return this.timezones || new Collection()
|
||||
}
|
||||
|
||||
getLanguages(): Collection {
|
||||
return this.languages || new Collection()
|
||||
}
|
||||
|
||||
hasLanguages(): boolean {
|
||||
return !!this.languages && this.languages.notEmpty()
|
||||
}
|
||||
|
||||
hasLanguage(language: Language): boolean {
|
||||
return (
|
||||
!!this.languages &&
|
||||
this.languages.includes((_language: Language) => _language.code === language.code)
|
||||
)
|
||||
}
|
||||
|
||||
isBroadcastInCity(city: City): boolean {
|
||||
if (!this.broadcastArea) return false
|
||||
|
||||
return this.broadcastArea.includesCity(city)
|
||||
}
|
||||
|
||||
isBroadcastInSubdivision(subdivision: Subdivision): boolean {
|
||||
if (!this.broadcastArea) return false
|
||||
|
||||
return this.broadcastArea.includesSubdivision(subdivision)
|
||||
}
|
||||
|
||||
isBroadcastInCountry(country: Country): boolean {
|
||||
if (!this.broadcastArea) return false
|
||||
|
||||
return this.broadcastArea.includesCountry(country)
|
||||
}
|
||||
|
||||
isBroadcastInRegion(region: Region): boolean {
|
||||
if (!this.broadcastArea) return false
|
||||
|
||||
return this.broadcastArea.includesRegion(region)
|
||||
}
|
||||
|
||||
isInternational(): boolean {
|
||||
if (!this.broadcastArea) return false
|
||||
|
||||
return this.broadcastArea.codes.join(',').includes('r/')
|
||||
}
|
||||
|
||||
getGuides(): Collection {
|
||||
if (!this.guides) return new Collection()
|
||||
|
||||
return this.guides
|
||||
}
|
||||
|
||||
getStreams(): Collection {
|
||||
if (!this.streams) return new Collection()
|
||||
|
||||
return this.streams
|
||||
}
|
||||
|
||||
getFullName(): string {
|
||||
if (!this.channel) return ''
|
||||
|
||||
return `${this.channel.name} ${this.name}`
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
import type { GuideData, GuideSerializedData } from '../types/guide'
|
||||
|
||||
export class Guide {
|
||||
channelId?: string
|
||||
feedId?: string
|
||||
siteDomain: string
|
||||
siteId: string
|
||||
siteName: string
|
||||
languageCode: string
|
||||
|
||||
constructor(data?: GuideData) {
|
||||
if (!data) return
|
||||
|
||||
this.channelId = data.channel
|
||||
this.feedId = data.feed
|
||||
this.siteDomain = data.site
|
||||
this.siteId = data.site_id
|
||||
this.siteName = data.site_name
|
||||
this.languageCode = data.lang
|
||||
}
|
||||
|
||||
getUUID(): string {
|
||||
return this.getStreamId() + this.siteId
|
||||
}
|
||||
|
||||
getStreamId(): string | undefined {
|
||||
if (!this.channelId) return undefined
|
||||
if (!this.feedId) return this.channelId
|
||||
|
||||
return `${this.channelId}@${this.feedId}`
|
||||
}
|
||||
|
||||
serialize(): GuideSerializedData {
|
||||
return {
|
||||
channelId: this.channelId,
|
||||
feedId: this.feedId,
|
||||
siteDomain: this.siteDomain,
|
||||
siteId: this.siteId,
|
||||
siteName: this.siteName,
|
||||
languageCode: this.languageCode
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: GuideSerializedData): this {
|
||||
this.channelId = data.channelId
|
||||
this.feedId = data.feedId
|
||||
this.siteDomain = data.siteDomain
|
||||
this.siteId = data.siteId
|
||||
this.siteName = data.siteName
|
||||
this.languageCode = data.languageCode
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
import type { LanguageData, LanguageSerializedData } from '../types/language'
|
||||
|
||||
export class Language {
|
||||
code: string
|
||||
name: string
|
||||
|
||||
constructor(data?: LanguageData) {
|
||||
if (!data) return
|
||||
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
}
|
||||
|
||||
serialize(): LanguageSerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: LanguageSerializedData): this {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
import { Collection, type Dictionary } from '@freearhey/core'
|
||||
import type { LogoData } from '../types/logo'
|
||||
import { type Feed } from './feed'
|
||||
|
||||
export class Logo {
|
||||
channelId: string
|
||||
feedId?: string
|
||||
feed: Feed
|
||||
tags: Collection
|
||||
width: number
|
||||
height: number
|
||||
format?: string
|
||||
url: string
|
||||
|
||||
constructor(data?: LogoData) {
|
||||
if (!data) return
|
||||
|
||||
this.channelId = data.channel
|
||||
this.feedId = data.feed || undefined
|
||||
this.tags = new Collection(data.tags)
|
||||
this.width = data.width
|
||||
this.height = data.height
|
||||
this.format = data.format || undefined
|
||||
this.url = data.url
|
||||
}
|
||||
|
||||
withFeed(feedsKeyById: Dictionary): this {
|
||||
if (!this.feedId) return this
|
||||
|
||||
this.feed = feedsKeyById.get(this.feedId)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getStreamId(): string {
|
||||
if (!this.feedId) return this.channelId
|
||||
|
||||
return `${this.channelId}@${this.feedId}`
|
||||
}
|
||||
}
|
||||
@ -1,118 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { City, Country, Subdivision } from '.'
|
||||
import type { RegionData, RegionSerializedData } from '../types/region'
|
||||
import { CountrySerializedData } from '../types/country'
|
||||
import { SubdivisionSerializedData } from '../types/subdivision'
|
||||
import { CitySerializedData } from '../types/city'
|
||||
|
||||
export class Region {
|
||||
code: string
|
||||
name: string
|
||||
countryCodes: Collection
|
||||
countries?: Collection
|
||||
subdivisions?: Collection
|
||||
cities?: Collection
|
||||
regions?: Collection
|
||||
|
||||
constructor(data?: RegionData) {
|
||||
if (!data) return
|
||||
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCodes = new Collection(data.countries)
|
||||
}
|
||||
|
||||
withCountries(countriesKeyByCode: Dictionary): this {
|
||||
this.countries = this.countryCodes.map((code: string) => countriesKeyByCode.get(code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withSubdivisions(subdivisions: Collection): this {
|
||||
this.subdivisions = subdivisions.filter(
|
||||
(subdivision: Subdivision) => this.countryCodes.indexOf(subdivision.countryCode) > -1
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withCities(cities: Collection): this {
|
||||
this.cities = cities.filter((city: City) => this.countryCodes.indexOf(city.countryCode) > -1)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withRegions(regions: Collection): this {
|
||||
this.regions = regions.filter(
|
||||
(region: Region) => !region.countryCodes.intersects(this.countryCodes).isEmpty()
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getSubdivisions(): Collection {
|
||||
if (!this.subdivisions) return new Collection()
|
||||
|
||||
return this.subdivisions
|
||||
}
|
||||
|
||||
getCountries(): Collection {
|
||||
if (!this.countries) return new Collection()
|
||||
|
||||
return this.countries
|
||||
}
|
||||
|
||||
getCities(): Collection {
|
||||
if (!this.cities) return new Collection()
|
||||
|
||||
return this.cities
|
||||
}
|
||||
|
||||
getRegions(): Collection {
|
||||
if (!this.regions) return new Collection()
|
||||
|
||||
return this.regions
|
||||
}
|
||||
|
||||
includesCountryCode(code: string): boolean {
|
||||
return this.countryCodes.includes((countryCode: string) => countryCode === code)
|
||||
}
|
||||
|
||||
isWorldwide(): boolean {
|
||||
return ['INT', 'WW'].includes(this.code)
|
||||
}
|
||||
|
||||
serialize(): RegionSerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
countryCodes: this.countryCodes.all(),
|
||||
countries: this.getCountries()
|
||||
.map((country: Country) => country.serialize())
|
||||
.all(),
|
||||
subdivisions: this.getSubdivisions()
|
||||
.map((subdivision: Subdivision) => subdivision.serialize())
|
||||
.all(),
|
||||
cities: this.getCities()
|
||||
.map((city: City) => city.serialize())
|
||||
.all()
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: RegionSerializedData): this {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCodes = new Collection(data.countryCodes)
|
||||
this.countries = new Collection(data.countries).map((data: CountrySerializedData) =>
|
||||
new Country().deserialize(data)
|
||||
)
|
||||
this.subdivisions = new Collection(data.subdivisions).map((data: SubdivisionSerializedData) =>
|
||||
new Subdivision().deserialize(data)
|
||||
)
|
||||
this.cities = new Collection(data.cities).map((data: CitySerializedData) =>
|
||||
new City().deserialize(data)
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
import { SubdivisionData, SubdivisionSerializedData } from '../types/subdivision'
|
||||
import { Dictionary, Collection } from '@freearhey/core'
|
||||
import { Country, Region } from '.'
|
||||
|
||||
export class Subdivision {
|
||||
code: string
|
||||
name: string
|
||||
countryCode: string
|
||||
country?: Country
|
||||
parentCode?: string
|
||||
parent?: Subdivision
|
||||
regions?: Collection
|
||||
cities?: Collection
|
||||
|
||||
constructor(data?: SubdivisionData) {
|
||||
if (!data) return
|
||||
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.country
|
||||
this.parentCode = data.parent || undefined
|
||||
}
|
||||
|
||||
withCountry(countriesKeyByCode: Dictionary): this {
|
||||
this.country = countriesKeyByCode.get(this.countryCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withRegions(regions: Collection): this {
|
||||
this.regions = regions.filter((region: Region) =>
|
||||
region.countryCodes.includes(this.countryCode)
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withCities(citiesGroupedBySubdivisionCode: Dictionary): this {
|
||||
this.cities = new Collection(citiesGroupedBySubdivisionCode.get(this.code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
withParent(subdivisionsKeyByCode: Dictionary): this {
|
||||
if (!this.parentCode) return this
|
||||
|
||||
this.parent = subdivisionsKeyByCode.get(this.parentCode)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getRegions(): Collection {
|
||||
if (!this.regions) return new Collection()
|
||||
|
||||
return this.regions
|
||||
}
|
||||
|
||||
getCities(): Collection {
|
||||
if (!this.cities) return new Collection()
|
||||
|
||||
return this.cities
|
||||
}
|
||||
|
||||
serialize(): SubdivisionSerializedData {
|
||||
return {
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
countryCode: this.countryCode,
|
||||
country: this.country ? this.country.serialize() : undefined,
|
||||
parentCode: this.parentCode || null
|
||||
}
|
||||
}
|
||||
|
||||
deserialize(data: SubdivisionSerializedData): this {
|
||||
this.code = data.code
|
||||
this.name = data.name
|
||||
this.countryCode = data.countryCode
|
||||
this.country = data.country ? new Country().deserialize(data.country) : undefined
|
||||
this.parentCode = data.parentCode || undefined
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
|
||||
type TimezoneData = {
|
||||
id: string
|
||||
utc_offset: string
|
||||
countries: string[]
|
||||
}
|
||||
|
||||
export class Timezone {
|
||||
id: string
|
||||
utcOffset: string
|
||||
countryCodes: Collection
|
||||
countries?: Collection
|
||||
|
||||
constructor(data: TimezoneData) {
|
||||
this.id = data.id
|
||||
this.utcOffset = data.utc_offset
|
||||
this.countryCodes = new Collection(data.countries)
|
||||
}
|
||||
|
||||
withCountries(countriesKeyByCode: Dictionary): this {
|
||||
this.countries = this.countryCodes.map((code: string) => countriesKeyByCode.get(code))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
getCountries(): Collection {
|
||||
return this.countries || new Collection()
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,3 @@
|
||||
export interface Table {
|
||||
make(): void
|
||||
create(): void
|
||||
}
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
export type BlocklistRecordData = {
|
||||
channel: string
|
||||
reason: string
|
||||
ref: string
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
export type CategorySerializedData = {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type CategoryData = {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
import { Collection } from '@freearhey/core'
|
||||
import type { CountrySerializedData } from './country'
|
||||
import type { SubdivisionSerializedData } from './subdivision'
|
||||
import type { CategorySerializedData } from './category'
|
||||
|
||||
export type ChannelSerializedData = {
|
||||
id: string
|
||||
name: string
|
||||
altNames: string[]
|
||||
network?: string
|
||||
owners: string[]
|
||||
countryCode: string
|
||||
country?: CountrySerializedData
|
||||
subdivisionCode?: string
|
||||
subdivision?: SubdivisionSerializedData
|
||||
cityName?: string
|
||||
categoryIds: string[]
|
||||
categories?: CategorySerializedData[]
|
||||
isNSFW: boolean
|
||||
launched?: string
|
||||
closed?: string
|
||||
replacedBy?: string
|
||||
website?: string
|
||||
}
|
||||
|
||||
export type ChannelData = {
|
||||
id: string
|
||||
name: string
|
||||
alt_names: string[]
|
||||
network: string
|
||||
owners: Collection
|
||||
country: string
|
||||
subdivision: string
|
||||
city: string
|
||||
categories: Collection
|
||||
is_nsfw: boolean
|
||||
launched: string
|
||||
closed: string
|
||||
replaced_by: string
|
||||
website: string
|
||||
}
|
||||
|
||||
export type ChannelSearchableData = {
|
||||
id: string
|
||||
name: string
|
||||
altNames: string[]
|
||||
guideNames: string[]
|
||||
streamTitles: string[]
|
||||
feedFullNames: string[]
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
import { CountrySerializedData } from './country'
|
||||
import { SubdivisionSerializedData } from './subdivision'
|
||||
|
||||
export type CitySerializedData = {
|
||||
code: string
|
||||
name: string
|
||||
countryCode: string
|
||||
country?: CountrySerializedData
|
||||
subdivisionCode: string | null
|
||||
subdivision?: SubdivisionSerializedData
|
||||
wikidataId: string
|
||||
}
|
||||
|
||||
export type CityData = {
|
||||
code: string
|
||||
name: string
|
||||
country: string
|
||||
subdivision: string | null
|
||||
wikidata_id: string
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
import type { LanguageSerializedData } from './language'
|
||||
import type { SubdivisionSerializedData } from './subdivision'
|
||||
import type { RegionSerializedData } from './region'
|
||||
|
||||
export type CountrySerializedData = {
|
||||
code: string
|
||||
name: string
|
||||
flag: string
|
||||
languageCode: string
|
||||
language: LanguageSerializedData | null
|
||||
subdivisions: SubdivisionSerializedData[]
|
||||
regions: RegionSerializedData[]
|
||||
}
|
||||
|
||||
export type CountryData = {
|
||||
code: string
|
||||
name: string
|
||||
lang: string
|
||||
flag: string
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
import { Storage } from '@freearhey/core'
|
||||
|
||||
export type DataLoaderProps = {
|
||||
storage: Storage
|
||||
}
|
||||
|
||||
export type DataLoaderData = {
|
||||
countries: object | object[]
|
||||
regions: object | object[]
|
||||
subdivisions: object | object[]
|
||||
languages: object | object[]
|
||||
categories: object | object[]
|
||||
blocklist: object | object[]
|
||||
channels: object | object[]
|
||||
feeds: object | object[]
|
||||
logos: object | object[]
|
||||
timezones: object | object[]
|
||||
guides: object | object[]
|
||||
streams: object | object[]
|
||||
cities: object | object[]
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
|
||||
export type DataProcessorData = {
|
||||
blocklistRecordsGroupedByChannelId: Dictionary
|
||||
subdivisionsGroupedByCountryCode: Dictionary
|
||||
feedsGroupedByChannelId: Dictionary
|
||||
guidesGroupedByStreamId: Dictionary
|
||||
logosGroupedByStreamId: Dictionary
|
||||
subdivisionsKeyByCode: Dictionary
|
||||
countriesKeyByCode: Dictionary
|
||||
languagesKeyByCode: Dictionary
|
||||
streamsGroupedById: Dictionary
|
||||
categoriesKeyById: Dictionary
|
||||
timezonesKeyById: Dictionary
|
||||
regionsKeyByCode: Dictionary
|
||||
blocklistRecords: Collection
|
||||
channelsKeyById: Dictionary
|
||||
citiesKeyByCode: Dictionary
|
||||
subdivisions: Collection
|
||||
categories: Collection
|
||||
countries: Collection
|
||||
languages: Collection
|
||||
timezones: Collection
|
||||
channels: Collection
|
||||
regions: Collection
|
||||
streams: Collection
|
||||
cities: Collection
|
||||
guides: Collection
|
||||
feeds: Collection
|
||||
logos: Collection
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
export type FeedData = {
|
||||
channel: string
|
||||
id: string
|
||||
name: string
|
||||
is_main: boolean
|
||||
broadcast_area: string[]
|
||||
languages: string[]
|
||||
timezones: string[]
|
||||
video_format: string
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
export type GuideSerializedData = {
|
||||
channelId?: string
|
||||
feedId?: string
|
||||
siteDomain: string
|
||||
siteId: string
|
||||
siteName: string
|
||||
languageCode: string
|
||||
}
|
||||
|
||||
export type GuideData = {
|
||||
channel: string
|
||||
feed: string
|
||||
site: string
|
||||
site_id: string
|
||||
site_name: string
|
||||
lang: string
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
export type LanguageSerializedData = {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type LanguageData = {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
export type LogoData = {
|
||||
channel: string
|
||||
feed: string | null
|
||||
tags: string[]
|
||||
width: number
|
||||
height: number
|
||||
format: string | null
|
||||
url: string
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
import { CitySerializedData } from './city'
|
||||
import { CountrySerializedData } from './country'
|
||||
import { SubdivisionSerializedData } from './subdivision'
|
||||
|
||||
export type RegionSerializedData = {
|
||||
code: string
|
||||
name: string
|
||||
countryCodes: string[]
|
||||
countries?: CountrySerializedData[]
|
||||
subdivisions?: SubdivisionSerializedData[]
|
||||
cities?: CitySerializedData[]
|
||||
}
|
||||
|
||||
export type RegionData = {
|
||||
code: string
|
||||
name: string
|
||||
countries: string[]
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
export type StreamData = {
|
||||
channelId: string | null
|
||||
feedId: string | null
|
||||
title: string | null
|
||||
url: string
|
||||
referrer: string | null
|
||||
userAgent: string | null
|
||||
quality: string | null
|
||||
label: string | null
|
||||
directives: string[]
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
import { CountrySerializedData } from './country'
|
||||
|
||||
export type SubdivisionSerializedData = {
|
||||
code: string
|
||||
name: string
|
||||
countryCode: string
|
||||
country?: CountrySerializedData
|
||||
parentCode: string | null
|
||||
}
|
||||
|
||||
export type SubdivisionData = {
|
||||
code: string
|
||||
name: string
|
||||
country: string
|
||||
parent: string | null
|
||||
}
|
||||
Loading…
Reference in New Issue