-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,86 @@ | ||
import { Rule } from '@any-reader/rule-utils'; | ||
|
||
interface M3UITtem { | ||
'group-title': string; | ||
'tvg-id': string; | ||
'tvg-logo': string; | ||
url: string; | ||
} | ||
|
||
function m3uParse(text: string): M3UITtem[] { | ||
return text | ||
.split('#EXTINF:') | ||
.map((s: string) => { | ||
return Array.from(s.matchAll(/ (.*?)="(.*?)"/g)).reduce((p: any, v: string[]) => { | ||
p[v[1]] = v[2]; | ||
const urls = s.split('\n').filter((e) => /^https?:\/\//.test(e)); | ||
if (urls.length === 1) { | ||
p.url = urls[0]; | ||
} | ||
return p; | ||
}, {}); | ||
}) | ||
.filter((e) => e.url); | ||
} | ||
|
||
export default class IPTV { | ||
private rule: Rule; | ||
private _m3u: M3UITtem[] = []; | ||
|
||
constructor(rule: Rule) { | ||
this.rule = rule; | ||
} | ||
|
||
async _getM3UList() { | ||
if (this._m3u.length) return; | ||
const res = await fetch(this.rule.host).then((e) => e.text()); | ||
this._m3u = m3uParse(res); | ||
} | ||
|
||
async search() { | ||
return []; | ||
} | ||
async getChapter() { | ||
return []; | ||
async getChapter(result: string) { | ||
return [ | ||
{ | ||
url: result, | ||
name: '正文' | ||
} | ||
]; | ||
} | ||
async getContent() { | ||
return []; | ||
async getContent(result: string) { | ||
return [result]; | ||
} | ||
|
||
// 获取分类 | ||
async discoverMap() { | ||
return []; | ||
await this._getM3UList(); | ||
return this._m3u.reduce((p: any[], v) => { | ||
const row = p.find((e: any) => e.name === v['group-title']); | ||
if (!row) { | ||
p.push({ | ||
name: v['group-title'], | ||
pairs: [ | ||
{ | ||
name: '全部', | ||
value: v['group-title'] | ||
} | ||
] | ||
}); | ||
} | ||
return p; | ||
}, []); | ||
} | ||
async discover() { | ||
return []; | ||
|
||
// 分类下列表 | ||
async discover(result: string) { | ||
await this._getM3UList(); | ||
return this._m3u | ||
.filter((e) => e['group-title'] === result) | ||
.map((e) => ({ | ||
url: e.url, | ||
name: e['tvg-id'], | ||
cover: e['tvg-logo'] | ||
})); | ||
} | ||
} |