diff --git a/package.json b/package.json index 635df80..f1c2301 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "express": "^4.17.1", "fast-xml-parser": "^3.17.4", "html2canvas": "^1.0.0-rc.5", + "m3u8": "0.0.10", "modern-normalize": "^0.6.0", "mousetrap": "^1.6.5", "qrcode.vue": "^1.7.0", diff --git a/src/components/IPTV.vue b/src/components/IPTV.vue index 9c7d285..5a478ea 100644 --- a/src/components/IPTV.vue +++ b/src/components/IPTV.vue @@ -183,8 +183,7 @@ export default { const options = { filters: [ { name: 'JSON file', extensions: ['json'] }, - { name: 'Normal text file', extensions: ['txt'] }, - { name: 'All types', extensions: ['*'] } + { name: 'm3u file', extensions: ['m3u'] } ], properties: ['openFile'] } @@ -192,14 +191,29 @@ export default { if (!result.canceled) { iptv.clear() result.filePaths.forEach(file => { - var str = fs.readFileSync(file) - const json = JSON.parse(str) - iptv.bulkAdd(json).then(e => { - this.getAllSites() - }) - this.$message.success('导入成功') - }).catch(err => { - this.$message.error(err) + if (file.endsWith('json')) { + var str = fs.readFileSync(file) + const json = JSON.parse(str) + iptv.bulkAdd(json).then(e => { + this.getAllSites() + }) + this.$message.success('导入成功') + } else if (file.endsWith('m3u')) { + var m3u8 = require('m3u8') + var parser = m3u8.createStream() + var m3ufile = fs.createReadStream(file) + m3ufile.pipe(parser) + parser.on('item', function (item) { + var prop = item.properties + if (prop.title && prop.uri && prop.uri.endsWith('m3u8')) { + var doc = { + name: prop.title, + url: prop.uri + } + iptv.add(doc) + } + }) + } }) } }) diff --git a/src/components/Play.vue b/src/components/Play.vue index aee19f0..d597c27 100644 --- a/src/components/Play.vue +++ b/src/components/Play.vue @@ -298,6 +298,7 @@ export default { } if (this.video.info.url) { + // 如果info里含有有url,是直播源,直接播放 this.playUrl(this.video.info.url) } else { const index = this.video.info.index | 0 @@ -313,7 +314,6 @@ export default { } }, playUrl (url) { - this.$message.success(url) this.xg.src = url this.xg.play() },