Update scripts

This commit is contained in:
freearhey 2025-04-19 02:06:15 +03:00
parent d681fcb3d5
commit 8e363d0e83
19 changed files with 562 additions and 141 deletions

View file

@ -1,40 +1,24 @@
import { Collection } from '@freearhey/core'
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
logo: string
}
import { ChannelData, ChannelSearchableData } from '../types/channel'
import { Collection, Dictionary } from '@freearhey/core'
import { Stream, Guide, Feed } from './'
export class Channel {
id: string
name: string
altNames: Collection
altNames?: Collection
network?: string
owners: Collection
owners?: Collection
countryCode: string
subdivisionCode?: string
cityName?: string
categoryIds: Collection
categories?: Collection
categoryIds?: Collection
isNSFW: boolean
launched?: string
closed?: string
replacedBy?: string
website?: string
logo: string
logo?: string
feeds?: Collection
constructor(data: ChannelData) {
this.id = data.id
@ -53,4 +37,77 @@ export class Channel {
this.website = data.website || undefined
this.logo = data.logo
}
withFeeds(feedsGroupedByChannelId: Dictionary): this {
this.feeds = new Collection(feedsGroupedByChannelId.get(this.id))
return this
}
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
}
getStreamNames(): Collection {
return this.getStreams()
.map((stream: Stream) => stream.getName())
.uniq()
}
getFeedFullNames(): Collection {
return this.getFeeds()
.map((feed: Feed) => feed.getFullName())
.uniq()
}
getName(): string {
return this.name || ''
}
getId(): string {
return this.id || ''
}
getAltNames(): Collection {
return this.altNames || new Collection()
}
getSearchable(): ChannelSearchableData {
return {
id: this.getId(),
name: this.getName(),
altNames: this.getAltNames().all(),
guideNames: this.getGuideNames().all(),
streamNames: this.getStreamNames().all(),
feedFullNames: this.getFeedFullNames().all()
}
}
}