mirror of
https://github.com/iptv-org/iptv
synced 2025-12-18 11:27:34 -05:00
Update scripts
This commit is contained in:
@@ -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(data: BroadcastAreaProps) {
|
||||
this.code = data.code
|
||||
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)
|
||||
}
|
||||
|
||||
includesCity(city: City): boolean {
|
||||
return this.getCities().includes((_city: City) => _city.code === city.code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user