mirror of
https://github.com/iptv-org/iptv
synced 2026-04-04 18:21:51 -04:00
Update scripts
This commit is contained in:
43
scripts/generators/citiesGenerator.ts
Normal file
43
scripts/generators/citiesGenerator.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { City, Stream, Playlist } from '../models'
|
||||
import { Collection, Storage, File } from '@freearhey/core'
|
||||
import { PUBLIC_DIR, EOL } from '../constants'
|
||||
import { Generator } from './generator'
|
||||
|
||||
type CitiesGeneratorProps = {
|
||||
streams: Collection
|
||||
cities: Collection
|
||||
logFile: File
|
||||
}
|
||||
|
||||
export class CitiesGenerator implements Generator {
|
||||
streams: Collection
|
||||
cities: Collection
|
||||
storage: Storage
|
||||
logFile: File
|
||||
|
||||
constructor({ streams, cities, logFile }: CitiesGeneratorProps) {
|
||||
this.streams = streams.clone()
|
||||
this.cities = cities
|
||||
this.storage = new Storage(PUBLIC_DIR)
|
||||
this.logFile = logFile
|
||||
}
|
||||
|
||||
async generate(): Promise<void> {
|
||||
const streams = this.streams
|
||||
.orderBy((stream: Stream) => stream.getTitle())
|
||||
.filter((stream: Stream) => stream.isSFW())
|
||||
|
||||
this.cities.forEach(async (city: City) => {
|
||||
const cityStreams = streams.filter((stream: Stream) => stream.isBroadcastInCity(city))
|
||||
|
||||
if (cityStreams.isEmpty()) return
|
||||
|
||||
const playlist = new Playlist(cityStreams, { public: true })
|
||||
const filepath = `cities/${city.code.toLowerCase()}.m3u`
|
||||
await this.storage.save(filepath, playlist.toString())
|
||||
this.logFile.append(
|
||||
JSON.stringify({ type: 'city', filepath, count: playlist.streams.count() }) + EOL
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,18 @@ export class CountriesGenerator implements Generator {
|
||||
)
|
||||
})
|
||||
|
||||
const internationalStreams = streams.filter((stream: Stream) => stream.isInternational())
|
||||
const internationalPlaylist = new Playlist(internationalStreams, { public: true })
|
||||
const internationalFilepath = 'countries/int.m3u'
|
||||
await this.storage.save(internationalFilepath, internationalPlaylist.toString())
|
||||
this.logFile.append(
|
||||
JSON.stringify({
|
||||
type: 'country',
|
||||
filepath: internationalFilepath,
|
||||
count: internationalPlaylist.streams.count()
|
||||
}) + EOL
|
||||
)
|
||||
|
||||
const undefinedStreams = streams.filter((stream: Stream) => !stream.hasBroadcastArea())
|
||||
const undefinedPlaylist = new Playlist(undefinedStreams, { public: true })
|
||||
const undefinedFilepath = 'countries/undefined.m3u'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './categoriesGenerator'
|
||||
export * from './citiesGenerator'
|
||||
export * from './countriesGenerator'
|
||||
export * from './indexCategoryGenerator'
|
||||
export * from './indexCountryGenerator'
|
||||
|
||||
@@ -26,6 +26,13 @@ export class IndexCountryGenerator implements Generator {
|
||||
.orderBy((stream: Stream) => stream.getTitle())
|
||||
.filter((stream: Stream) => stream.isSFW())
|
||||
.forEach((stream: Stream) => {
|
||||
if (stream.isInternational()) {
|
||||
const streamClone = stream.clone()
|
||||
streamClone.groupTitle = 'International'
|
||||
groupedStreams.add(streamClone)
|
||||
return
|
||||
}
|
||||
|
||||
if (!stream.hasBroadcastArea()) {
|
||||
const streamClone = stream.clone()
|
||||
streamClone.groupTitle = 'Undefined'
|
||||
@@ -41,6 +48,7 @@ export class IndexCountryGenerator implements Generator {
|
||||
})
|
||||
|
||||
groupedStreams = groupedStreams.orderBy((stream: Stream) => {
|
||||
if (stream.groupTitle === 'International') return 'ZZ'
|
||||
if (stream.groupTitle === 'Undefined') return 'ZZZ'
|
||||
|
||||
return stream.groupTitle
|
||||
|
||||
@@ -31,6 +31,8 @@ export class IndexRegionGenerator implements Generator {
|
||||
if (!stream.hasBroadcastArea()) return
|
||||
|
||||
stream.getBroadcastRegions().forEach((region: Region) => {
|
||||
if (region.isWorldwide()) return
|
||||
|
||||
const streamClone = stream.clone()
|
||||
streamClone.groupTitle = region.name
|
||||
groupedStreams.push(streamClone)
|
||||
|
||||
@@ -28,6 +28,8 @@ export class RegionsGenerator implements Generator {
|
||||
.filter((stream: Stream) => stream.isSFW())
|
||||
|
||||
this.regions.forEach(async (region: Region) => {
|
||||
if (region.isWorldwide()) return
|
||||
|
||||
const regionStreams = streams.filter((stream: Stream) => stream.isBroadcastInRegion(region))
|
||||
|
||||
const playlist = new Playlist(regionStreams, { public: true })
|
||||
|
||||
Reference in New Issue
Block a user