This commit is contained in:
AntiPontifex 2023-10-17 10:00:07 -04:00
commit ae5cc571c0
20 changed files with 470 additions and 260 deletions

View file

@ -13,7 +13,7 @@ body:
id: name
attributes:
label: Channel Name
description: "Official channel name in English or call sign. May include: `a-z`, `0-9`, `space`, `-`, `!`, `:`, `&`, `.`, `+`, `'`, `/`, `»`, `#`, `%`, `°`, `$`, `@`, `?`"
description: "Official channel name in English or call sign. May include: `a-z`, `0-9`, `space`, `-`, `!`, `:`, `&`, `.`, `+`, `'`, `/`, `»`, `#`, `%`, `°`, `$`, `@`, `?`, `|`"
placeholder: 'Anhui TV'
validations:
required: true

View file

@ -22,7 +22,7 @@ body:
id: name
attributes:
label: Channel Name
description: "Official channel name in English or call sign. May include: `a-z`, `0-9`, `space`, `-`, `!`, `:`, `&`, `.`, `+`, `'`, `/`, `»`, `#`, `%`, `°`, `$`, `@`, `?`"
description: "Official channel name in English or call sign. May include: `a-z`, `0-9`, `space`, `-`, `!`, `:`, `&`, `.`, `+`, `'`, `/`, `»`, `#`, `%`, `°`, `$`, `@`, `?`, `|`"
placeholder: 'Anhui TV'
- type: input
@ -96,8 +96,6 @@ body:
options:
- 'FALSE'
- 'TRUE'
validations:
required: true
- type: input
id: launched

View file

@ -11,9 +11,9 @@
### channels
| Field | Description | Required | Example |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------ |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------ | ---------- |
| id | Unique channel ID derived from the `name` and `country` separated by dot. May only contain Latin letters, numbers and dot. | Required | `AnhuiTV.cn` |
| name | Official channel name in English or call sign. May include: `a-z`, `0-9`, `space`, `-`, `!`, `:`, `&`, `.`, `+`, `'`, `/`, `»`, `#`, `%`, `°`, `$`, `@`, `?`. | Required | `Anhui TV` |
| name | Official channel name in English or call sign. May include: `a-z`, `0-9`, `space`, `-`, `!`, `:`, `&`, `.`, `+`, `'`, `/`, `»`, `#`, `%`, `°`, `$`, `@`, `?`, ` | `. | Required | `Anhui TV` |
| alt_names | List of alternative channel names separated by `;`. May contain any characters except `,` and `"`. | Optional | `安徽卫视;AHTV` |
| network | Network of which this channel is a part. May contain any characters except `,` and `"`. | Optional | `Anhui` |
| owners | List of channel owners separated by `;`. May contain any characters except `,` and `"`. | Optional | `China Central Television` |

File diff suppressed because it is too large Load diff

View file

@ -3,3 +3,5 @@ export * from './issueParser'
export * from './issueLoader'
export * from './csvParser'
export * from './idCreator'
export * from './issueData'
export * from './issue'

View file

@ -1,15 +1,15 @@
import { Dictionary } from '@freearhey/core'
import { IssueData } from './'
type IssueProps = {
number: number
labels: string[]
data: Dictionary
data: IssueData
}
export class Issue {
number: number
labels: string[]
data: Dictionary
data: IssueData
constructor({ number, labels, data }: IssueProps) {
this.number = number

40
scripts/core/issueData.ts Normal file
View file

@ -0,0 +1,40 @@
import { Dictionary } from '@freearhey/core'
export class IssueData {
_data: Dictionary
constructor(data: Dictionary) {
this._data = data
}
has(key: string): boolean {
return this._data.has(key)
}
missing(key: string): boolean {
return this._data.missing(key) || this._data.get(key) === undefined
}
getBoolean(key: string): boolean | undefined {
return this.missing(key) ? undefined : this._data.get(key)
}
getString(key: string): string | undefined {
const deleteSymbol = '~'
return this.missing(key)
? undefined
: this._data.get(key) === deleteSymbol
? ''
: this._data.get(key)
}
getArray(key: string): string[] | undefined {
const deleteSymbol = '~'
return this.missing(key)
? undefined
: this._data.get(key) === deleteSymbol
? []
: this._data.get(key).split(';')
}
}

View file

@ -1,5 +1,5 @@
import { Dictionary } from '@freearhey/core'
import { Issue } from '../models'
import { IssueData, Issue } from '../core'
const FIELDS = new Dictionary({
'Channel ID': 'channel_id',
@ -52,7 +52,8 @@ export class IssueParser {
if (!_label || !_value) return data
const id: string = FIELDS.get(_label)
const value: string = _value === '_No response_' || _value === 'None' ? '' : _value
const value: string | undefined =
_value === '_No response_' || _value === 'None' ? undefined : _value
if (!id) return
@ -61,6 +62,6 @@ export class IssueParser {
const labels = issue.labels.map(label => label.name)
return new Issue({ number: issue.number, labels, data })
return new Issue({ number: issue.number, labels, data: new IssueData(data) })
}
}

View file

@ -1,5 +1,5 @@
import { CSV, IssueLoader, CSVParser, IDCreator } from '../core'
import { Channel, Blocked, Issue } from '../models'
import { CSV, IssueLoader, CSVParser, IDCreator, Issue, IssueData } from '../core'
import { Channel, Blocked } from '../models'
import { DATA_DIR } from '../constants'
import { Storage, Collection } from '@freearhey/core'
@ -57,7 +57,9 @@ async function removeChannels({ loader }: { loader: IssueLoader }) {
issues.forEach((issue: Issue) => {
if (issue.data.missing('channel_id')) return
const found = channels.first((channel: Channel) => channel.id === issue.data.get('channel_id'))
const found = channels.first(
(channel: Channel) => channel.id === issue.data.getString('channel_id')
)
if (!found) return
channels.remove((channel: Channel) => channel.id === found.id)
@ -69,55 +71,41 @@ async function removeChannels({ loader }: { loader: IssueLoader }) {
async function editChannels({ loader, idCreator }: { loader: IssueLoader; idCreator: IDCreator }) {
const issues = await loader.load({ labels: ['channels:edit,approved'] })
issues.forEach((issue: Issue) => {
const data = issue.data
const data: IssueData = issue.data
if (data.missing('channel_id')) return
const found: Channel = channels.first(
(channel: Channel) => channel.id === data.get('channel_id')
(channel: Channel) => channel.id === data.getString('channel_id')
)
if (!found) return
let channelId = found.id
if (data.has('name') || data.has('country')) {
const name = data.get('name') || found.name
const country = data.get('country') || found.country
channelId = idCreator.create(name, country)
const name = data.getString('name') || found.name
const country = data.getString('country') || found.country
if (name && country) {
channelId = idCreator.create(name, country)
}
}
const deleteSymbol = '~'
const updated = new Channel({
id: channelId,
name: data.get('name') !== deleteSymbol ? data.get('name') : '',
alt_names:
data.has('alt_names') && data.get('alt_names') !== deleteSymbol
? data.get('alt_names').split(';')
: [],
network: data.get('network') !== deleteSymbol ? data.get('network') : '',
owners:
data.has('owners') && data.get('owners') !== deleteSymbol
? data.get('owners').split(';')
: [],
country: data.get('country') !== deleteSymbol ? data.get('country') : '',
subdivision: data.get('subdivision') !== deleteSymbol ? data.get('subdivision') : '',
city: data.get('city') !== deleteSymbol ? data.get('city') : '',
broadcast_area:
data.has('broadcast_area') && data.get('broadcast_area') !== deleteSymbol
? data.get('broadcast_area').split(';')
: [],
languages:
data.has('languages') && data.get('languages') !== deleteSymbol
? data.get('languages').split(';')
: [],
categories:
data.has('categories') && data.get('categories') !== deleteSymbol
? data.get('categories').split(';')
: [],
is_nsfw: data.has('is_nsfw') ? data.get('is_nsfw') === 'TRUE' : false,
launched: data.get('launched') !== deleteSymbol ? data.get('launched') : '',
closed: data.get('closed') !== deleteSymbol ? data.get('closed') : '',
replaced_by: data.get('replaced_by') !== deleteSymbol ? data.get('replaced_by') : '',
website: data.get('website') !== deleteSymbol ? data.get('website') : '',
logo: data.get('logo') !== deleteSymbol ? data.get('logo') : ''
name: data.getString('name'),
alt_names: data.getArray('alt_names'),
network: data.getString('network'),
owners: data.getArray('owners'),
country: data.getString('country'),
subdivision: data.getString('subdivision'),
city: data.getString('city'),
broadcast_area: data.getArray('broadcast_area'),
languages: data.getArray('languages'),
categories: data.getArray('categories'),
is_nsfw: data.getBoolean('is_nsfw'),
launched: data.getString('launched'),
closed: data.getString('closed'),
replaced_by: data.getString('replaced_by'),
website: data.getString('website'),
logo: data.getString('logo')
})
found.merge(updated)
@ -129,10 +117,13 @@ async function editChannels({ loader, idCreator }: { loader: IssueLoader; idCrea
async function addChannels({ loader, idCreator }: { loader: IssueLoader; idCreator: IDCreator }) {
const issues = await loader.load({ labels: ['channels:add,approved'] })
issues.forEach((issue: Issue) => {
const data = issue.data
if (data.missing('name') || data.missing('country')) return
const data: IssueData = issue.data
const name = data.getString('name')
const country = data.getString('country')
const channelId = idCreator.create(data.get('name'), data.get('country'))
if (!name || !country) return
const channelId = idCreator.create(name, country)
const found: Channel = channels.first((channel: Channel) => channel.id === channelId)
if (found) return
@ -140,22 +131,22 @@ async function addChannels({ loader, idCreator }: { loader: IssueLoader; idCreat
channels.push(
new Channel({
id: channelId,
name: data.get('name'),
alt_names: data.get('alt_names'),
network: data.get('network'),
owners: data.get('owners'),
country: data.get('country'),
subdivision: data.get('subdivision'),
city: data.get('city'),
broadcast_area: data.get('broadcast_area'),
languages: data.get('languages'),
categories: data.get('categories'),
is_nsfw: data.get('is_nsfw'),
launched: data.get('launched'),
closed: data.get('closed'),
replaced_by: data.get('replaced_by'),
website: data.get('website'),
logo: data.get('logo')
name: data.getString('name'),
alt_names: data.getArray('alt_names'),
network: data.getString('network'),
owners: data.getArray('owners'),
country: data.getString('country'),
subdivision: data.getString('subdivision'),
city: data.getString('city'),
broadcast_area: data.getArray('broadcast_area'),
languages: data.getArray('languages'),
categories: data.getArray('categories'),
is_nsfw: data.getBoolean('is_nsfw'),
launched: data.getString('launched'),
closed: data.getString('closed'),
replaced_by: data.getString('replaced_by'),
website: data.getString('website'),
logo: data.getString('logo')
})
)
@ -170,7 +161,7 @@ async function unblockChannels({ loader }: { loader: IssueLoader }) {
if (data.missing('channel_id')) return
const found: Blocked = blocklist.first(
(blocked: Blocked) => blocked.channel === data.get('channel_id')
(blocked: Blocked) => blocked.channel === data.getString('channel_id')
)
if (!found) return
@ -187,14 +178,18 @@ async function blockChannels({ loader }: { loader: IssueLoader }) {
if (data.missing('channel_id')) return
const found: Blocked = blocklist.first(
(blocked: Blocked) => blocked.channel === data.get('channel_id')
(blocked: Blocked) => blocked.channel === data.getString('channel_id')
)
if (found) return
const channel = data.getString('channel_id')
const ref = data.getString('ref')
if (!channel || !ref) return
blocklist.push(
new Blocked({
channel: data.get('channel_id'),
ref: data.get('ref')
channel,
ref
})
)

View file

@ -1,41 +1,41 @@
type ChannelProps = {
id: string
name: string
alt_names: string[]
network: string
owners: string[]
country: string
subdivision: string
city: string
broadcast_area: string[]
languages: string[]
categories: string[]
is_nsfw: boolean
launched: string
closed: string
replaced_by: string
website: string
logo: string
name?: string
alt_names?: string[]
network?: string
owners?: string[]
country?: string
subdivision?: string
city?: string
broadcast_area?: string[]
languages?: string[]
categories?: string[]
is_nsfw?: boolean
launched?: string
closed?: string
replaced_by?: string
website?: string
logo?: string
}
export class Channel {
id: string
name: string
alt_names: string[]
network: string
owners: string[]
country: string
subdivision: string
city: string
broadcast_area: string[]
languages: string[]
categories: string[]
is_nsfw: boolean
launched: string
closed: string
replaced_by: string
website: string
logo: string
name?: string
alt_names?: string[]
network?: string
owners?: string[]
country?: string
subdivision?: string
city?: string
broadcast_area?: string[]
languages?: string[]
categories?: string[]
is_nsfw?: boolean
launched?: string
closed?: string
replaced_by?: string
website?: string
logo?: string
constructor({
id,
@ -82,10 +82,9 @@ export class Channel {
}
merge(channel: Channel) {
const data: { [key: string]: string | string[] | boolean } = channel.data()
const data: { [key: string]: string | string[] | boolean | undefined } = channel.data()
for (const prop in data) {
if (data[prop] === undefined) continue
if (Array.isArray(data[prop]) && !(data[prop] as string[]).length) continue
this[prop] = data[prop]
}
}

View file

@ -1,3 +1,2 @@
export * from './channel'
export * from './issue'
export * from './blocked'

View file

@ -7,7 +7,7 @@ module.exports = {
.regex(/^[A-Za-z0-9]+\.[a-z]{2}$/)
.required(),
name: Joi.string()
.regex(/^[a-z0-9-!:&.+'/»#%°$@?\s]+$/i)
.regex(/^[a-z0-9-!:&.+'/»#%°$@?|\s]+$/i)
.required(),
alt_names: Joi.array().items(
Joi.string()

View file

@ -1 +1 @@
[{"id":"002RadioTV.do","name":"002 Radio TV","alt_names":[],"network":null,"owners":[],"country":"DO","subdivision":null,"city":null,"broadcast_area":["c/DO"],"languages":["spa"],"categories":["general"],"is_nsfw":false,"launched":null,"closed":null,"replaced_by":null,"website":"https://www.002radio.com/","logo":"https://i.imgur.com/7oNe8xj.png"},{"id":"BeijingSatelliteTV.cn","name":"Beijing Satellite TV","alt_names":["北京卫视"],"network":null,"owners":[],"country":"CN","subdivision":null,"city":"Beijing","broadcast_area":["c/CN"],"languages":["zho"],"categories":["general"],"is_nsfw":false,"launched":"1979-05-16","closed":null,"replaced_by":null,"website":"https://www.brtn.cn/btv/","logo":"https://i.imgur.com/vsktAez.png"},{"id":"M5.hu","name":"M5","alt_names":[],"network":null,"owners":[],"country":"HU","subdivision":null,"city":null,"broadcast_area":["c/HU"],"languages":["hun"],"categories":[],"is_nsfw":false,"launched":null,"closed":"2001-01-01","replaced_by":null,"website":"https://www.mediaklikk.hu/m5/","logo":"https://i.imgur.com/y21wFd0.png"}]
[{"id":"002RadioTV.do","name":"002 Radio TV","alt_names":[],"network":null,"owners":[],"country":"DO","subdivision":null,"city":null,"broadcast_area":["c/DO"],"languages":["spa"],"categories":["general"],"is_nsfw":false,"launched":null,"closed":null,"replaced_by":null,"website":"https://www.002radio.com/","logo":"https://i.imgur.com/7oNe8xj.png"},{"id":"BeijingSatelliteTV.cn","name":"Beijing Satellite TV","alt_names":["北京卫视"],"network":null,"owners":[],"country":"CN","subdivision":null,"city":"Beijing","broadcast_area":["c/CN"],"languages":["zho"],"categories":["general"],"is_nsfw":false,"launched":"1979-05-16","closed":null,"replaced_by":null,"website":"https://www.brtn.cn/btv/","logo":"https://i.imgur.com/vsktAez.png"},{"id":"M5.hu","name":"M5","alt_names":[],"network":null,"owners":[],"country":"HU","subdivision":null,"city":null,"broadcast_area":["c/HU"],"languages":["hun"],"categories":["auto"],"is_nsfw":true,"launched":null,"closed":"2001-01-01","replaced_by":null,"website":"https://www.mediaklikk.hu/m5/","logo":"https://i.imgur.com/y21wFd0.png"}]

View file

@ -1,6 +1,6 @@
id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo
beINMoviesTurk.tr,beIN Movies Turk,beIN Movies Türk,BBC,Gazprom Media,TR,US-CA,London,c/TR,tur,movies,FALSE,1979-05-16,1980-05-16,M5.hu,http://www.digiturk.com.tr/,https://i.imgur.com/nw8Sa2z.png
M5.hu,M5,,,Duna Médiaszolgáltató Nonprofit Zrt.,HU,,,c/HU,hun,,FALSE,,,,https://www.mediaklikk.hu/m5/,https://i.imgur.com/y21wFd0.png
M5.hu,M5,,,Duna Médiaszolgáltató Nonprofit Zrt.,HU,,,c/HU,hun,,TRUE,,,,https://www.mediaklikk.hu/m5/,https://i.imgur.com/y21wFd0.png
WenzhouEconomicandEducation.cn,Wenzhou Economic and Education,,,,CN,,Wenzhou,c/CN,zho,science,FALSE,,,,,https://www.tvchinese.net/uploads/tv/wzjjkj.jpg
YiwuBusinessChannel.cn,Yiwu Business Channel,,,,CN,,,c/CN,zho,business,FALSE,,,,,https://www.tvchinese.net/uploads/tv/yiwutv.jpg
YiwuNewsIntegratedChannel.cn,Yiwu News Integrated Channel,,,,CN,,,c/CN,zho,news,FALSE,,,,,https://www.tvchinese.net/uploads/tv/yiwutv.jpg
1 id name alt_names network owners country subdivision city broadcast_area languages categories is_nsfw launched closed replaced_by website logo
2 beINMoviesTurk.tr beIN Movies Turk beIN Movies Türk BBC Gazprom Media TR US-CA London c/TR tur movies FALSE 1979-05-16 1980-05-16 M5.hu http://www.digiturk.com.tr/ https://i.imgur.com/nw8Sa2z.png
3 M5.hu M5 Duna Médiaszolgáltató Nonprofit Zrt. HU c/HU hun FALSE TRUE https://www.mediaklikk.hu/m5/ https://i.imgur.com/y21wFd0.png
4 WenzhouEconomicandEducation.cn Wenzhou Economic and Education CN Wenzhou c/CN zho science FALSE https://www.tvchinese.net/uploads/tv/wzjjkj.jpg
5 YiwuBusinessChannel.cn Yiwu Business Channel CN c/CN zho business FALSE https://www.tvchinese.net/uploads/tv/yiwutv.jpg
6 YiwuNewsIntegratedChannel.cn Yiwu News Integrated Channel CN c/CN zho news FALSE https://www.tvchinese.net/uploads/tv/yiwutv.jpg

View file

@ -1,4 +1,4 @@
id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo
002RadioTV.do,002 Radio TV,,,,DO,,,c/DO,spa,general,FALSE,,,,https://www.002radio.com/,https://i.imgur.com/7oNe8xj.png
BeijingSatelliteTV.cn,Beijing Satellite TV,北京卫视,,,CN,,Beijing,c/CN,zho,general,FALSE,1979-05-16,,,https://www.brtn.cn/btv/,https://i.imgur.com/vsktAez.png
M5.hu,M5,,,,HU,,,c/HU,hun,,FALSE,,2001-01-01,,https://www.mediaklikk.hu/m5/,https://i.imgur.com/y21wFd0.png
M5.hu,M5,,,,HU,,,c/HU,hun,auto,TRUE,,2001-01-01,,https://www.mediaklikk.hu/m5/,https://i.imgur.com/y21wFd0.png
1 id name alt_names network owners country subdivision city broadcast_area languages categories is_nsfw launched closed replaced_by website logo
2 002RadioTV.do 002 Radio TV DO c/DO spa general FALSE https://www.002radio.com/ https://i.imgur.com/7oNe8xj.png
3 BeijingSatelliteTV.cn Beijing Satellite TV 北京卫视 CN Beijing c/CN zho general FALSE 1979-05-16 https://www.brtn.cn/btv/ https://i.imgur.com/vsktAez.png
4 M5.hu M5 HU c/HU hun auto FALSE TRUE 2001-01-01 https://www.mediaklikk.hu/m5/ https://i.imgur.com/y21wFd0.png

View file

@ -61,7 +61,7 @@ module.exports = [
closed_at: null,
author_association: 'CONTRIBUTOR',
active_lock_reason: null,
body: '### Channel ID (required)\n\nM5.hu\n\n### Channel Name\n\n_No response_\n\n### Alternative Names\n\n_No response_\n\n### Network\n\n_No response_\n\n### Owners\n\nDuna Médiaszolgáltató Nonprofit Zrt.\n\n### Country\n\n_No response_\n\n### Subdivision\n\n_No response_\n\n### City\n\n_No response_\n\n### Broadcast Area\n\n_No response_\n\n### Languages\n\n_No response_\n\n### Categories\n\n_No response_\n\n### NSFW\n\nFALSE\n\n### Launched\n\n_No response_\n\n### Closed\n\n~\n\n### Replaced By\n\n_No response_\n\n### Website\n\n_No response_\n\n### Logo\n\n_No response_\n\n### Notes\n\n_No response_',
body: '### Channel ID (required)\n\nM5.hu\n\n### Channel Name\n\n_No response_\n\n### Alternative Names\n\n_No response_\n\n### Network\n\n_No response_\n\n### Owners\n\nDuna Médiaszolgáltató Nonprofit Zrt.\n\n### Country\n\n_No response_\n\n### Subdivision\n\n_No response_\n\n### City\n\n_No response_\n\n### Broadcast Area\n\n_No response_\n\n### Languages\n\n_No response_\n\n### Categories\n\n~\n\n### NSFW\n\nNone\n\n### Launched\n\n_No response_\n\n### Closed\n\n~\n\n### Replaced By\n\n_No response_\n\n### Website\n\n_No response_\n\n### Logo\n\n_No response_\n\n### Notes\n\n_No response_',
reactions: {
url: 'https://api.github.com/repos/iptv-org/database/issues/5901/reactions',
total_count: 0,

View file

@ -1,2 +1,3 @@
id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo
PeoplesWeather.do,People°s Weather,,,,DO,,,c/DO,spa,,FALSE,,,,,https://i.imgur.com/7oNe8xj.png
KSTVKids.ua,KS TV | Kids,,,,UA,,,c/UA,ukr,,FALSE,,,,,https://i.imgur.com/CmRfj78.png
1 id name alt_names network owners country subdivision city broadcast_area languages categories is_nsfw launched closed replaced_by website logo
2 PeoplesWeather.do People°s Weather DO c/DO spa FALSE https://i.imgur.com/7oNe8xj.png
3 KSTVKids.ua KS TV | Kids UA c/UA ukr FALSE https://i.imgur.com/CmRfj78.png

View file

@ -1,3 +1,4 @@
name,code,languages,flag
Andorra,AD,cat,🇦🇩
Dominican Republic,DO,spa,🇩🇴
Ukraine,UA,ukr,🇺🇦
1 name code languages flag
2 Andorra AD cat 🇦🇩
3 Dominican Republic DO spa 🇩🇴
4 Ukraine UA ukr 🇺🇦

View file

@ -1,3 +1,4 @@
code,name
cat,Catalan
spa,Spanish
ukr,Ukrainian
1 code name
2 cat Catalan
3 spa Spanish
4 ukr Ukrainian

View file

@ -79,8 +79,12 @@ describe('db:validate', () => {
})
it('does not show an error if all data are correct', () => {
execSync('DATA_DIR=tests/__data__/input/validate/valid_data npm run db:validate', {
encoding: 'utf8'
})
try {
execSync('DATA_DIR=tests/__data__/input/validate/valid_data npm run db:validate', {
encoding: 'utf8'
})
} catch (error) {
console.log((error as ExecError).stdout)
}
})
})