* @param {Number} _hours -更新小时数
(_hours)
| 14 | * @param {Number} _hours -更新小时数 |
| 15 | */ |
| 16 | async function updateTV(_hours) { |
| 17 | |
| 18 | const date = new Date() |
| 19 | const start = date.getTime() |
| 20 | let interfacePath = "" |
| 21 | let interfaceTXTPath = "" |
| 22 | // 获取数据 |
| 23 | const datas = await dataList() |
| 24 | printGreen("TV数据获取成功!") |
| 25 | |
| 26 | interfacePath = `${process.cwd()}/interface.txt.bak` |
| 27 | // txt |
| 28 | interfaceTXTPath = `${process.cwd()}/interfaceTXT.txt.bak` |
| 29 | // 创建写入空内容 |
| 30 | writeFile(interfacePath, "") |
| 31 | // txt |
| 32 | writeFile(interfaceTXTPath, "") |
| 33 | |
| 34 | appendFile(interfacePath, `#EXTM3U x-tvg-url="\${replace}/playback.xml" catchup="append" catchup-source="?playbackbegin=\${(b)yyyyMMddHHmmss}&playbackend=\${(e)yyyyMMddHHmmss}"\n`) |
| 35 | printYellow("开始更新TV...") |
| 36 | // 回放 |
| 37 | const playbackFile = `${process.cwd()}/playback.xml.bak` |
| 38 | writeFile(playbackFile, |
| 39 | `<?xml version="1.0" encoding="UTF-8"?>\n` + |
| 40 | `<tv generator-info-name="Tak" generator-info-url="${host}">\n`) |
| 41 | |
| 42 | // 分类列表 |
| 43 | for (let i = 0; i < datas.length; i++) { |
| 44 | // 忽略分类 |
| 45 | if (ignoreCategorySet.has(datas[i].name)) { |
| 46 | printYellow(`TV分类###:${datas[i].name} 已屏蔽!`) |
| 47 | continue |
| 48 | } |
| 49 | |
| 50 | const data = datas[i].dataList |
| 51 | // txt |
| 52 | appendFile(interfaceTXTPath, `${datas[i].name},#genre#\n`) |
| 53 | // 写入节目 |
| 54 | for (let j = 0; j < data.length; j++) { |
| 55 | |
| 56 | await updatePlaybackData(data[j], playbackFile) |
| 57 | |
| 58 | // 写入节目 |
| 59 | appendFile(interfacePath, `#EXTINF:-1 tvg-id="${data[j].name}" tvg-name="${data[j].name}" tvg-logo="${data[j].pics.highResolutionH}" group-title="${datas[i].name}",${data[j].name}\n\${replace}/${data[j].pID}\n`) |
| 60 | // txt |
| 61 | appendFile(interfaceTXTPath, `${data[j].name},\${replace}/${data[j].pID}\n`) |
| 62 | // printGreen(` 节目链接更新成功`) |
| 63 | } |
| 64 | printGreen(`分类###:${datas[i].name} 更新完成!`) |
| 65 | } |
| 66 | |
| 67 | appendFileSync(playbackFile, `</tv>\n`) |
| 68 | |
| 69 | // 重命名 |
| 70 | renameFileSync(playbackFile, playbackFile.replace(".bak", "")) |
| 71 | renameFileSync(interfacePath, interfacePath.replace(".bak", "")) |
| 72 | // txt |
| 73 | renameFileSync(interfaceTXTPath, interfaceTXTPath.replace(".bak", "")) |
no test coverage detected