Skip to content

Commit

Permalink
fix: 优化保存文件格式 & 修复list链接风控问题
Browse files Browse the repository at this point in the history
  • Loading branch information
gxr404 committed Oct 21, 2024
1 parent 9c69f41 commit 04d4918
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/components/VideoModal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<a-checkbox @change="onAllSelectedChange">
全选
</a-checkbox>
<a-checkbox v-model:checked="saveFilePrefix">
保留[P?]
</a-checkbox>
</div>
</div>
<div v-if="videoInfo.page && videoInfo.page.length > 1" class="fr ac warp mt16">
Expand Down Expand Up @@ -76,6 +79,7 @@ const videoInfo = ref<VideoData>(videoData)
const selected = ref<number[]>([])
const allSelected = ref<boolean>(false)
const router = useRouter()
const saveFilePrefix = ref<boolean>(true)
const cancel = () => {
visible.value = false
Expand All @@ -87,7 +91,7 @@ const cancel = () => {
const handleDownload = async () => {
confirmLoading.value = true
// 获取当前选中视频的下载数据
const list = await getDownloadList(toRaw(videoInfo.value), toRaw(selected.value), quality.value)
const list = await getDownloadList(toRaw(videoInfo.value), toRaw(selected.value), quality.value, undefined, undefined, saveFilePrefix.value)
console.log('list-->', list)
const taskList = addDownload(list)
store.taskStore().setTask(taskList)
Expand All @@ -110,6 +114,7 @@ const handleDownload = async () => {
}
const open = (data: VideoData) => {
saveFilePrefix.value = true
const quality = userQuality[store.baseStore().loginStatus]
// 过滤掉 不合法的清晰度
data.qualityOptions = data.qualityOptions.filter((item: any) => quality.includes(item.value))
Expand Down
22 changes: 11 additions & 11 deletions src/core/bilibili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const nanoid = customAlphabet(alphabet, 16)
* @params videoInfo: 当前下载的视频详情 selected:所选的分p quality:所选的清晰度
* @returns 返回下载数据 Array
*/
const getDownloadList = async (videoInfo: VideoData, selected: number[], quality: number, isReload = false, oldTask?: VideoData) => {
const getDownloadList = async (videoInfo: VideoData, selected: number[], quality: number, isReload = false, oldTask?: VideoData, saveFilePrefix = true) => {
const downloadList: VideoData[] = []
const limit = pLimit(8)
const selectedLen = selected.length
Expand Down Expand Up @@ -72,8 +72,8 @@ const getDownloadList = async (videoInfo: VideoData, selected: number[], quality
cid: currentCid,
bvid: currentBvid,
downloadUrl,
filePathList: handleFilePathList(selectedLen === 1 && !isReload ? 0 : currentPage, currentPageData.title, tempVideoInfo, currentBvid, taskId),
fileDir: handleFileDir(selectedLen === 1 && !isReload ? 0 : currentPage, currentPageData.title, tempVideoInfo, currentBvid, taskId),
filePathList: handleFilePathList(selectedLen === 1 && !isReload ? 0 : currentPage, currentPageData.title, tempVideoInfo, currentBvid, taskId, saveFilePrefix),
fileDir: handleFileDir(selectedLen === 1 && !isReload ? 0 : currentPage, currentPageData.title, tempVideoInfo, currentBvid, taskId, saveFilePrefix),
subtitle
}
downloadList.push(videoData)
Expand Down Expand Up @@ -184,11 +184,12 @@ const checkUrl = (url: string) => {

// 检查url是否有重定向
const checkUrlRedirect = async (videoUrl: string) => {
const ua = randUserAgent()
const params = {
videoUrl,
config: {
headers: {
'User-Agent': randUserAgent(),
'User-Agent': ua,
cookie: `SESSDATA=${store.settingStore(pinia).SESSDATA}`
}
}
Expand Down Expand Up @@ -599,14 +600,14 @@ const getSubtitle = async (cid: number, bvid: string) => {
}

// 处理filePathList
const handleFilePathList = (page: number, title: string, videoInfo: VideoData, bvid: string, id: string): string[] => {
const handleFilePathList = (page: number, title: string, videoInfo: VideoData, bvid: string, id: string, saveFilePrefix = true): string[] => {
const up = videoInfo.up[0].name
const collectionName = (Array.isArray(videoInfo.page) && videoInfo.page.length > 1)
? videoInfo.page[0].collectionName
: ''
const storeDownloadPath = store.settingStore().downloadPath
const downloadPath = collectionName ? `${storeDownloadPath}/${collectionName}${up ? `-${up}` : ''}` : storeDownloadPath
const name = `${!page ? '' : `[P${page}]`}${filterTitle(`${title}${up ? `-${up}` : ''}-${bvid}-${id}`)}`
const downloadPath = collectionName ? `${storeDownloadPath}/${up ? `${up}-` : ''}${collectionName}` : storeDownloadPath
const name = `${(page && saveFilePrefix) ? `[P${page}]` : ''}${filterTitle(`${up ? `${up}-` : ''}${title}-${bvid}-${id}`)}`
const isFolder = store.settingStore().isFolder
let pathList = [
`${downloadPath}/${name}.mp4`,
Expand All @@ -628,15 +629,14 @@ const handleFilePathList = (page: number, title: string, videoInfo: VideoData, b
}

// 处理fileDir
const handleFileDir = (page: number, title: string, videoInfo: VideoData, bvid: string, id: string): string => {
const handleFileDir = (page: number, title: string, videoInfo: VideoData, bvid: string, id: string, saveFilePrefix = true): string => {
const up = videoInfo.up[0].name
const collectionName = (Array.isArray(videoInfo.page) && videoInfo.page.length > 1)
? videoInfo.page[0].collectionName
: ''
const storeDownloadPath = store.settingStore().downloadPath
const downloadPath = collectionName ? `${storeDownloadPath}/${collectionName}${up ? `-${up}` : ''}` : storeDownloadPath

const name = `${!page ? '' : `[P${page}]`}${filterTitle(`${title}${up ? `-${up}` : ''}-${bvid}-${id}`)}`
const downloadPath = collectionName ? `${storeDownloadPath}/${up ? `${up}-` : ''}${collectionName}` : storeDownloadPath
const name = `${(page && saveFilePrefix) ? `[P${page}]` : ''}${filterTitle(`${up ? `${up}-` : ''}${title}-${bvid}-${id}`)}`
const isFolder = store.settingStore().isFolder
return `${downloadPath}${isFolder ? `/${name}/` : ''}`
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/randUA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const userAgent = new UserAgent({
deviceCategory: 'desktop'
})
function randUserAgent () {
return userAgent.random().toString()
return `${userAgent.random().toString()} ${Math.floor(Math.random() * 100000)}`
}

export {
Expand Down

0 comments on commit 04d4918

Please sign in to comment.