feat : from info

This commit is contained in:
HerbertHe 2024-01-17 17:44:47 +08:00
parent 5ffbbff726
commit 8e7f4af834
4 changed files with 34 additions and 5 deletions

View File

@ -1,5 +1,5 @@
<!-- list_title_here -->
| No. | Channel Name | Source |
| --- | ------------ | --- |
| No. | Channel Name | From | Source |
| --- | ------------ | ---- | ------ |
<!-- channels_here -->

View File

@ -3,6 +3,7 @@ import path from "path"
import { handle_m3u } from "./sources"
import type { TEPGSource } from "./epgs/utils"
import { get_from_info } from "./utils"
export interface IREADMESource {
name: string
@ -28,7 +29,11 @@ export const updateChannelList = (
let channels: Array<string>[] = []
while (i < m3uArray.length) {
const reg = channelRegExp.exec(m3uArray[i]) as RegExpExecArray
channels.push([reg[2].replace(/\|/g, "").trim(), m3uArray[i + 1]])
channels.push([
reg[2].replace(/\|/g, "").trim(),
get_from_info(m3uArray[i + 1]),
m3uArray[i + 1],
])
i += 2
}
@ -44,7 +49,9 @@ export const updateChannelList = (
`${channels
?.map(
(c, idx) =>
`| ${idx + 1} | ${c[0].replace("|", "")} | <${c[1]}> |`
`| ${idx + 1} | ${c[0].replace("|", "")} | ${c[1]} | <${
c[2]
}> |`
)
.join("\n")}\n\nUpdated at **${new Date()}**`
)

21
src/utils/from.ts Normal file
View File

@ -0,0 +1,21 @@
const from_infos = new Map([
["sn.chinamobile.com", "中国移动陕西"],
["sh.chinamobile.com", "中国移动上海"],
["hl.chinamobile.com", "中国移动黑龙江"],
["cztv.com", "浙江广播电视集团"],
["mobaibox.com", "中国移动江苏"],
["cgtn.com", "CGTN"],
["cctv.com", "CCTV"],
])
export const get_from_info = (url: string) => {
for (const [k, v] of from_infos) {
if (url.includes(k)) {
return v
}
}
const hostRegExp = /([^:]+):\/\/([^/]+)/
return hostRegExp.exec(url)![2]
}

View File

@ -1,3 +1,4 @@
export * from "./handlers"
export * from "./const"
export * from "./logo"
export * from "./from"