mirror of https://github.com/iptv-org/iptv
Update scripts
parent
f665512bfc
commit
63262842e7
@ -1,11 +1,101 @@
|
||||
type BroadcastAreaProps = {
|
||||
code: string
|
||||
}
|
||||
import { Collection, Dictionary } from '@freearhey/core'
|
||||
import { City, Subdivision, Region, Country } from './'
|
||||
|
||||
export class BroadcastArea {
|
||||
code: string
|
||||
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 {
|
||||
let citiesIncluded = new Collection()
|
||||
let subdivisionsIncluded = new Collection()
|
||||
let 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)
|
||||
}
|
||||
case 's': {
|
||||
const subdivision: Subdivision = subdivisionsKeyByCode.get(code)
|
||||
if (!subdivision) return
|
||||
citiesIncluded = citiesIncluded.concat(subdivision.getCities())
|
||||
subdivisionsIncluded.add(subdivision)
|
||||
}
|
||||
case 'c': {
|
||||
const country: Country = countriesKeyByCode.get(code)
|
||||
if (!country) return
|
||||
citiesIncluded = citiesIncluded.concat(country.getCities())
|
||||
subdivisionsIncluded = subdivisionsIncluded.concat(country.getSubdivisions())
|
||||
countriesIncluded.add(country)
|
||||
regionsIncluded = regionsIncluded.concat(country.getRegions())
|
||||
}
|
||||
case 'r': {
|
||||
const region: Region = regionsKeyByCode.get(code)
|
||||
if (!region) return
|
||||
countriesIncluded = countriesIncluded.concat(region.getCountries())
|
||||
regionsIncluded = regionsIncluded.concat(region.getRegions())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
constructor(data: BroadcastAreaProps) {
|
||||
this.code = data.code
|
||||
includesCity(city: City): boolean {
|
||||
return this.getCities().includes((_city: City) => _city.code === city.code)
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
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,12 +1,10 @@
|
||||
import { Collection } from '@freearhey/core'
|
||||
|
||||
export type FeedData = {
|
||||
channel: string
|
||||
id: string
|
||||
name: string
|
||||
is_main: boolean
|
||||
broadcast_area: Collection
|
||||
languages: Collection
|
||||
timezones: Collection
|
||||
broadcast_area: string[]
|
||||
languages: string[]
|
||||
timezones: string[]
|
||||
video_format: string
|
||||
}
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
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