Skip to content

Commit 9a79294

Browse files
committed
✨ 終了時間未定の番組の更新を確認するように(#42)
Mirakurunが拾えてないことも多くあんまり意味がないが無いよりはマシかも
1 parent ef9a0e1 commit 9a79294

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/main/epgManager.ts

+43
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class EPGManager {
3939
connections = new Map<string, Readable>()
4040
intervals = new Map<string, NodeJS.Timeout>()
4141
programs = new Map<number, Program>()
42+
userAgent: string | null = null
4243

4344
constructor(ipcMain: IpcMain, private onEpgUpdate: () => void) {
4445
ipcMain.handle(EPG_MANAGER.REGISTER, (_, arg) => this.register(arg))
@@ -58,6 +59,47 @@ export class EPGManager {
5859
.filter((b) => b)
5960
console.info(`[epgmanager] 番組情報を削除しました: ${result.length}`)
6061
}, 1000 * 60 * 60)
62+
// 5分毎に終了時間未定の番組の更新を確認
63+
// TODO: ただMirakurunそのものが終了時間未定の番組を拾えない場合が多いのであまり対策にならない
64+
// https://github.com/ci7lus/MirakTest/issues/42
65+
setInterval(async () => {
66+
const userAgent = this.userAgent
67+
if (!userAgent) {
68+
return
69+
}
70+
const tbaPrograms = Array.from(this.programs.values()).filter(
71+
(program) => program.duration === 1
72+
)
73+
const mirakuruns = Array.from(
74+
new Set([...this.connections.keys(), ...this.intervals.keys()])
75+
)
76+
if (mirakuruns.length === 0) {
77+
return
78+
}
79+
const api = new MirakurunAPI({
80+
baseUrl: mirakuruns[0],
81+
userAgent,
82+
})
83+
for (const program of tbaPrograms) {
84+
console.info(
85+
`[epgmanager] 終了時間未定の番組情報の更新を試みます: ${program.id} (${program.name})`
86+
)
87+
const gotProgram = await api.programs.getProgram(program.id, {
88+
validateStatus: () => true,
89+
})
90+
if (gotProgram.status === 200) {
91+
console.info(
92+
`[epgmanager] ${program.id} (${program.name}) の番組情報を更新します`
93+
)
94+
this.programs.set(program.id, gotProgram.data)
95+
} else {
96+
console.info(
97+
`[epgmanager] ${program.id} (${program.name}) は既に終了しています`
98+
)
99+
this.programs.delete(program.id)
100+
}
101+
}
102+
}, 1000 * 60 * 5)
61103
}
62104

63105
async register(_payload: unknown) {
@@ -69,6 +111,7 @@ export class EPGManager {
69111
) {
70112
return
71113
}
114+
this.userAgent = payload.userAgent
72115
this.processing.set(payload.url, true)
73116
const client = new MirakurunAPI({
74117
baseUrl: payload.url,

0 commit comments

Comments
 (0)