From 536f6dad7d9d2b7ccf441a85a7f3d601f99f8712 Mon Sep 17 00:00:00 2001 From: hectorqin Date: Tue, 28 Jul 2020 22:53:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=87=BA=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD,=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dmini=E5=90=8C=E6=AD=A5=E8=BF=9B=E5=BA=A6,=E4=BC=98?= =?UTF-8?q?=E5=8C=96mini=E8=A7=86=E9=A2=91=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Play.vue | 79 ++++++++++++++++++++++++--- src/mini/Mini.vue | 116 +++++++++++++++++++++++++++++++--------- 2 files changed, 164 insertions(+), 31 deletions(-) diff --git a/src/components/Play.vue b/src/components/Play.vue index a1d4fff..5fe27dc 100644 --- a/src/components/Play.vue +++ b/src/components/Play.vue @@ -85,6 +85,7 @@
@@ -111,7 +112,6 @@ const VIDEO_DETAIL_CACHE = {} const addPlayerBtn = function (event, svg, attrs) { const player = this - console.log(player) const util = Player.util const controlEl = player.controls const btnConfig = player.config[event] @@ -261,7 +261,15 @@ export default { deep: true }, name () { - document.querySelector('.xg-view-videoTitle span').innerText = `『第 ${this.video.info.index + 1} 集』${this.name}` + const span = document.querySelector('.xg-view-videoTitle span') + if (!span) { + return + } + if (this.right.list.length > 1) { + span.innerText = `『第 ${this.video.info.index + 1} 集』${this.name}` + } else { + span.innerText = `${this.name}` + } } }, methods: { @@ -580,6 +588,47 @@ export default { this.right.show = false this.right.type = '' }, + exportM3u8 () { + const m3u8Arr = [] + for (const i of this.right.list) { + const j = i.split('$') + let link, name + if (j.length > 1) { + for (let m = 0; m < j.length; m++) { + if (j[m].indexOf('m3u8') >= 0) { + link = j[m] + } + } + name = j[0] + } else { + name = `第${m3u8Arr.length + 1}集` + link = j[0] + } + m3u8Arr.push({ + name: name, + link: link + }) + } + + console.log(m3u8Arr) + + let m3u8Content = `#EXTM3U +` + for (const item of m3u8Arr) { + m3u8Content += `#EXTINF:-1, ${item.name} +${item.link} +` + } + const blob = new Blob([m3u8Content], { type: 'application/vnd.apple.mpegurl' }) + const downloadElement = document.createElement('a') // 创建下载的链接 + const href = window.URL.createObjectURL(blob) + downloadElement.href = href + downloadElement.download = `${this.name}.m3u8` // 下载后的文件名 + document.body.appendChild(downloadElement) + downloadElement.click() // 下载 + document.body.removeChild(downloadElement) // 下载完成 移除 a + window.URL.revokeObjectURL(href) // 释放blob对象 + }, clearAllHistory () { history.clear().then(res => { this.right.history = [] @@ -911,15 +960,30 @@ export default { }) const that = this Player.install('videoTitle', function () { - addPlayerView.bind(this, 'videoTitle', `『第 ${that.video.info.index + 1} 集』${that.name}`, {})() + let title + if (that.right.list.length > 1) { + title = `『第 ${that.video.info.index + 1} 集』${that.name}` + } else { + title = `${that.name}` + } + addPlayerView.bind(this, 'videoTitle', `${title}`, {})() }) this.xg = new Hls(this.config) ipcRenderer.on('miniClosed', () => { - this.xg.destroy() - this.xg = new Hls(this.config) - this.bindEvent() - this.getUrls() + // this.xg.destroy() + // this.xg = new Hls(this.config) + // this.bindEvent() + // 同步进度 + history.find({ site: this.video.key, ids: this.video.info.id }).then(res => { + if (res) { + if (this.video.info.index !== res.index) { + this.video.info.index = res.index + } else { + this.getUrls() + } + } + }) }) this.bindEvent() }, @@ -1049,6 +1113,7 @@ export default { left: 0; right: 0; height: 40px; + padding-left: 10px; background-image: linear-gradient(180deg,rgba(0,0,0,.75),rgba(0,0,0,.75),rgba(0,0,0,.37),transparent); z-index: 10; } diff --git a/src/mini/Mini.vue b/src/mini/Mini.vue index 89c92fd..565c271 100644 --- a/src/mini/Mini.vue +++ b/src/mini/Mini.vue @@ -45,6 +45,7 @@ import mt from 'mousetrap' import 'xgplayer' import Hls from 'xgplayer-hls.js' const { remote, ipcRenderer } = require('electron') +const VIDEO_DETAIL_CACHE = {} export default { name: 'mini', data () { @@ -103,10 +104,88 @@ export default { getUrls () { mini.find().then(res => { this.video = res - zy.detail(res.site, res.ids).then(e => { - this.name = e.name - this.detail = e - const dd = e.dl.dd + this.fetchM3u8List(res).then(m3u8Arr => { + this.m3u8Arr = m3u8Arr + this.xg.src = m3u8Arr[res.index] + if (res.time !== 0 || res.time !== '') { + this.xg.play() + this.xg.once('playing', () => { + this.xg.currentTime = res.time + }) + } else { + this.xg.play() + } + this.videoPlaying() + this.xg.once('ended', () => { + if (m3u8Arr.length > 1 && (m3u8Arr.length - 1 > res.index)) { + this.video.time = 0 + this.video.index++ + this.xg.src = m3u8Arr[this.video.index] + this.xg.play() + } + }) + }) + // zy.detail(res.site, res.ids).then(e => { + // this.name = e.name + // this.detail = e + // const dd = e.dl.dd + // const type = Object.prototype.toString.call(dd) + // let m3u8Txt = [] + // if (type === '[object Array]') { + // for (const i of dd) { + // if (i._t.indexOf('m3u8') >= 0) { + // m3u8Txt = i._t.split('#') + // } + // } + // } else { + // m3u8Txt = dd._t.split('#') + // } + // const m3u8Arr = [] + // for (const i of m3u8Txt) { + // const j = i.split('$') + // if (j.length > 1) { + // for (let m = 0; m < j.length; m++) { + // if (j[m].indexOf('m3u8') >= 0) { + // m3u8Arr.push(j[m]) + // } + // } + // } else { + // m3u8Arr.push(j[0]) + // } + // } + // this.m3u8Arr = m3u8Arr + // this.xg.src = m3u8Arr[res.index] + // if (res.time !== 0 || res.time !== '') { + // this.xg.play() + // this.xg.once('playing', () => { + // this.xg.currentTime = res.time + // }) + // } else { + // this.xg.play() + // } + // this.videoPlaying() + // this.xg.once('ended', () => { + // if (m3u8Arr.length > 1 && (m3u8Arr.length - 1 > res.index)) { + // this.video.time = 0 + // this.video.index++ + // this.xg.src = m3u8Arr[this.video.index] + // this.xg.play() + // } + // }) + // }) + }) + }, + fetchM3u8List (info) { + return new Promise((resolve) => { + const cacheKey = info.site + '@' + info.ids + if (VIDEO_DETAIL_CACHE[cacheKey]) { + this.name = VIDEO_DETAIL_CACHE[cacheKey].name + resolve(VIDEO_DETAIL_CACHE[cacheKey].list) + return + } + zy.detail(info.site, info.ids).then(res => { + this.name = res.name + const dd = res.dl.dd const type = Object.prototype.toString.call(dd) let m3u8Txt = [] if (type === '[object Array]') { @@ -131,25 +210,12 @@ export default { m3u8Arr.push(j[0]) } } - this.m3u8Arr = m3u8Arr - this.xg.src = m3u8Arr[res.index] - if (res.time !== 0 || res.time !== '') { - this.xg.play() - this.xg.once('playing', () => { - this.xg.currentTime = res.time - }) - } else { - this.xg.play() + + VIDEO_DETAIL_CACHE[cacheKey] = { + list: m3u8Arr, + name: res.name } - this.videoPlaying() - this.xg.once('ended', () => { - if (m3u8Arr.length > 1 && (m3u8Arr.length - 1 > res.index)) { - this.video.time = 0 - this.video.index++ - this.xg.src = m3u8Arr[this.video.index] - this.xg.play() - } - }) + resolve(m3u8Arr) }) }) }, @@ -300,8 +366,10 @@ export default { return false } if (e === 'escape') { - this.xg.exitFullscreen() - this.xg.exitCssFullscreen() + if (this.xg.fullscreen) { + this.xg.exitFullscreen() + this.xg.exitCssFullscreen() + } return false } if (e === 'next') {