feat : (experimental) support txt sources

This commit is contained in:
HerbertHe 2023-12-14 13:12:35 +08:00
parent a1a622eb9b
commit acb4cc48cc
4 changed files with 35 additions and 5 deletions

View File

@ -9,8 +9,8 @@ Sources are from:
- <https://epg.pw/test_channel_page.html>
- [iptv.org](https://github.com/iptv-org/iptv)
| channel | url | list | count |
| ------- | --- | ---- | ----- |
| channel | m3u url | txt url | list | count |
| ------- | ------- | ------- | ---- | ----- |
<!-- channels_here -->
See <https://m3u.ibert.me> to get more.

View File

@ -16,6 +16,33 @@ export const writeM3u = (name: string, m3u: string) => {
fs.writeFileSync(path.join(path.resolve(), "m3u", `${name}.m3u`), m3u)
}
export const writeM3uToTxt = (name: string, f_name: string, m3u: string) => {
const title = `${name},#genre#`
const m3uArray = m3u.split("\n")
const channelRegExp = /\#EXTINF:-1([^,]*),(.*)/
let i = 1
let channels: Array<string>[] = []
while (i < m3uArray.length) {
const reg = channelRegExp.exec(m3uArray[i]) as RegExpExecArray
channels.push([reg[2].trim(), m3uArray[i + 1]])
i += 2
}
const txt = `${title}\n${channels
.map(([name, url]) => `${name},${url}`)
.join("\n")}\n`
if (!fs.existsSync(path.join(path.resolve(), "m3u", "txt"))) {
fs.mkdirSync(path.join(path.resolve(), "m3u", "txt"))
}
fs.writeFileSync(
path.join(path.resolve(), "m3u", "txt", `${f_name}.txt`),
txt
)
}
const cleanDir = (p: string) => {
if (fs.existsSync(p)) {
fs.readdirSync(p).forEach((file) => {

View File

@ -1,4 +1,4 @@
import { cleanFiles, getM3u, writeM3u } from "./file"
import { cleanFiles, getM3u, writeM3u, writeM3uToTxt } from "./file"
import { updateChannelList, updateReadme } from "./readme"
import { sources, filter } from "./sources"
@ -14,6 +14,7 @@ Promise.allSettled(
? sr.filter(text as string)
: filter(text as string)
writeM3u(sr.f_name, m3u)
writeM3uToTxt(sr.name, sr.f_name, m3u)
updateChannelList(sr.name, sr.f_name, m3u)
return count
} else {

View File

@ -30,7 +30,7 @@ export const updateChannelList = (
const after = list
.replace(
"<!-- list_title_here -->",
`# List for **${name}**\n\n> <https://m3u.ibert.me/${f_name}.m3u>`
`# List for **${name}**\n\n> M3U: <https://m3u.ibert.me/${f_name}.m3u>, TXT: <https://m3u.ibert.me/txt/${f_name}.txt>`
)
.replace(
"<!-- channels_here -->",
@ -68,7 +68,9 @@ export const updateReadme = (
(s, idx) =>
`| ${s.name} | <https://m3u.ibert.me/${
s.f_name
}.m3u> | [List for ${s.name}](https://m3u.ibert.me/list/${
}.m3u> | <https://m3u.ibert.me/txt/${
s.f_name
}.txt> | [List for ${s.name}](https://m3u.ibert.me/list/${
s.f_name
}.list) | ${
counts[idx] === undefined