Skip to content

Commit

Permalink
优化视频
Browse files Browse the repository at this point in the history
  • Loading branch information
jooooock committed Sep 26, 2024
1 parent e97df97 commit c6c6502
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pages/dashboard/download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function switchTableData(fakeid: string) {
}
}
function maxLen(text: string, max = 45): string {
function maxLen(text: string, max = 35): string {
if (text.length > max) {
return text.slice(0, max) + '...'
}
Expand Down
4 changes: 4 additions & 0 deletions types/video.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export interface VideoPageInfo {
video_id: string

// 是否为内嵌视频
is_mp_video: number

// 内嵌视频是否删除
is_mp_video_delete: number
cover_url: string
cover_url_1_1: string
Expand Down
28 changes: 19 additions & 9 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import JSZip from "jszip";
import mime from "mime";
import {sleep} from "@antfu/utils";
import {getAssetCache, updateAssetCache} from "~/store/assetes";
import type {DownloadResult} from "~/utils/pool";
import * as pool from '~/utils/pool';
import type {DownloadableArticle} from "~/types/types";
import type {DownloadResult} from "~/utils/pool";
import type {AudioResource, VideoPageInfo} from "~/types/video";


Expand Down Expand Up @@ -295,21 +295,31 @@ export async function packHTMLAssets(html: string, title: string, zip?: JSZip) {
const urls: string[] = []
videoPageInfos.forEach(videoPageInfo => {
urls.push(videoPageInfo.cover_url)
if (videoPageInfo.mp_video_trans_info.length > 0) {
if (videoPageInfo.is_mp_video === 1 && videoPageInfo.mp_video_trans_info.length > 0) {
urls.push(videoPageInfo.mp_video_trans_info[0].url)
}
})
return await pool.downloads<string>(urls, resourceDownloadFn)
})

const videoIframes = $jsArticleContent.querySelectorAll('iframe[data-mpvid]')
const videoIframes = $jsArticleContent.querySelectorAll('iframe.video_iframe')
videoIframes.forEach(videoIframe => {
const vid = videoIframe.getAttribute('data-mpvid')
const videoInfo = videoPageInfos.find(info => info.video_id === vid)
if (videoInfo) {
const div = document.createElement('div')
div.innerHTML = `<video src="${videoURLMap.get(videoInfo.mp_video_trans_info[0].url)}" poster="${videoURLMap.get(videoInfo.cover_url)}" controls style="width: 100%"></video>`
videoIframe.replaceWith(div)
const mpvid = videoIframe.getAttribute('data-mpvid')
if (mpvid) {
const videoInfo = videoPageInfos.find(info => info.video_id === mpvid)
if (videoInfo) {
const div = document.createElement('div')
div.innerHTML = `<video src="${videoURLMap.get(videoInfo.mp_video_trans_info[0].url)}" poster="${videoURLMap.get(videoInfo.cover_url)}" controls style="width: 100%"></video>`
videoIframe.replaceWith(div)
}
} else {
const src = videoIframe.getAttribute('data-src')!
const vidMatchResult = src.match(/v\.qq\.com\/iframe\/preview\.html\?vid=(?<vid>[\da-z]+)/i)
if (vidMatchResult && vidMatchResult.groups && vidMatchResult.groups.vid) {
const vid = vidMatchResult.groups.vid
videoIframe.setAttribute('src', 'https://v.qq.com/txp/iframe/player.html?vid=' + vid)
videoIframe.setAttribute('width', '100%')
}
}
})
}
Expand Down

0 comments on commit c6c6502

Please sign in to comment.