赞
踩
今天不知道网怎么了, 哔哩哔哩在电脑上看不了,
在手机上倒是可以看, 手机屏幕又太小,我就打算把视频缓存了,再拉到电脑上看.
Xiaomi-Redmi Note 4X-2019-05-12-11-31-42.png
百度了一下bilibili视频缓存路径, Android/data/tv.danmaku.bili/download
var bilibiliCacheVideoPath=files.join(files.getSdcardPath(),'Android/data/tv.danmaku.bili/download/38379328')
// 先判断这个文件夹存在不存在.
r=files.exists(bilibiliCacheVideoPath)
log(r) // true
读取一下他的子文件夹
var arr = files.listDir(bilibiliCacheVideoPath);
log(arr); // [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
每个子文件夹下面有 一个文件夹+弹幕文件+视频信息
我们先提取3号文件夹的视频路径和视频标题
提取视频标题
视频标题在entry.json的title字段
var OneVideoPath=files.join(bilibiliCacheVideoPath,'3')
var viedeInfoPath=files.join(OneVideoPath,'entry.json')
var videoInfo=files.read(viedeInfoPath)
var videoTitle=JSON.parse(videoInfo).title
log(videoTitle) // Typescript教程_Typescript视频教程 ts入门实战视频教程-2019年5月更新
提取视频路径
我看的视频大概在50M左右,一个文件就能装下
var viedeFilePath=files.join(OneVideoPath,'lua.flv360.bili2api.16','0.blv')
log(viedeFilePath)
var videoInfo={
title:videoTitle,
path:viedeFilePath
}
查看这个视频的大小
var size = new java.io.File(viedeFilePath).length()
log(parseInt(size/1024/1024)+'m') // 34m
标题和视频文件路径都提取出来了,
我们把视频文件移动到/sdcard/bilibiliVideo文件夹,文件名修改为为视频title
var bilibiliVideoSDPath=files.join(files.getSdcardPath(),'bilibiliVideo')
log(bilibiliVideoSDPath) // /storage/emulated/0/bilibiliVideo
// 确保bilibiliVideoSDPath存在
files.ensureDir(bilibiliVideoSDPath+'/')
r=files.exists(bilibiliVideoSDPath)
log(r) // true
videoInfo.targetPath=files.join(bilibiliVideoSDPath,videoInfo.title+'.blv')
// 移动文件
files.move(videoInfo.path, videoInfo.targetPath)
r=files.exists(videoInfo.targetPath)
log(r) // true
这样我们就成功的移动了一个视频
完整代码如下
var bilibiliCacheVideoPath = files.join(files.getSdcardPath(), 'Android/data/tv.danmaku.bili/download/38379328')
r = files.exists(bilibiliCacheVideoPath)
log(r)
var arr = files.listDir(bilibiliCacheVideoPath);
log(arr);
arr.map(
(parentPathName) => {
var videoInfo = extractVideoInfo(parentPathName)
moveVideoFile(videoInfo)
}
)
function moveVideoFile(videoInfo) {
files.move(videoInfo.path, videoInfo.targetPath)
}
function extractVideoInfo(parentPathName) {
var videoTitle = extractTitle(parentPathName) + parentPathName
var viedeFilePath = extractVideoPath(parentPathName)
var videoInfo = {
title: videoTitle,
path: viedeFilePath
}
var bilibiliVideoSDPath = files.join(files.getSdcardPath(), 'bilibiliVideo')
log(bilibiliVideoSDPath)
files.ensureDir(bilibiliVideoSDPath + '/')
videoInfo.targetPath = files.join(bilibiliVideoSDPath, videoInfo.title + '.blv')
return videoInfo
}
function extractTitle(parentPathName) {
var OneVideoPath = files.join(bilibiliCacheVideoPath, parentPathName)
var viedeInfoPath = files.join(OneVideoPath, 'entry.json')
var videoInfo = files.read(viedeInfoPath)
var videoTitle = JSON.parse(videoInfo).title
log(videoTitle)
videoTitle=videoTitle.replace(/\s+/g,'')
return videoTitle
}
function extractVideoPath(parentPathName) {
var OneVideoPath = files.join(bilibiliCacheVideoPath, parentPathName)
var viedeFilePath = files.join(OneVideoPath, 'lua.flv360.bili2api.16', '0.blv')
log(viedeFilePath)
return viedeFilePath
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。