add 视频下载与重命名
This commit is contained in:
parent
be48d26d8c
commit
539131dcec
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "启动程序",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}\\index.js"
|
||||
}
|
||||
]
|
||||
}
|
BIN
bin/yt-dlp.exe
BIN
bin/yt-dlp.exe
Binary file not shown.
BIN
db/database.db
BIN
db/database.db
Binary file not shown.
100
util/Download/index.js
Normal file
100
util/Download/index.js
Normal file
@ -0,0 +1,100 @@
|
||||
const path = require('path')
|
||||
const {dow, fileIsExist,getMediaInfo} = require("../utils.js");
|
||||
const { mkdirRecursions } = require('../markdir.js');
|
||||
const schedule = require('node-schedule');
|
||||
const { setDownState, getDownList } = require('../sql/download.js');
|
||||
const { getVideoInfo } = require('../sql/video.js');
|
||||
const fs = require("fs")
|
||||
|
||||
// 小于10添加0
|
||||
function addZeor(num){
|
||||
if(num < 10){
|
||||
return "0" + num
|
||||
}else{
|
||||
return num
|
||||
}
|
||||
}
|
||||
|
||||
// 重命名
|
||||
async function reName(dinfo){
|
||||
let vinfo = await getVideoInfo(dinfo.vid)
|
||||
console.log(vinfo)
|
||||
if(vinfo){
|
||||
let info = await getMediaInfo(dinfo.save + "/" + dinfo.title + ".mp4")
|
||||
console.log(info,dinfo.save + "/" + dinfo.title + ".mp4")
|
||||
info = info.media.track
|
||||
let Video;
|
||||
let Audio;
|
||||
for(let i of info){
|
||||
if(i["@type"] == "Video"){
|
||||
Video = i
|
||||
}
|
||||
if(i["@type"] == "Audio"){
|
||||
Audio = i
|
||||
break
|
||||
}
|
||||
}
|
||||
// 判断时长 0 为下载 1 下载完成 2 做种 3 没有下载完成或没有会员
|
||||
if(Video.Duration < 4 * 60){
|
||||
return 3
|
||||
}
|
||||
let fbl = 0
|
||||
if(Video.Height > 3000){
|
||||
fbl = 4320
|
||||
}else if(Video.Height > 1440){
|
||||
fbl = 2160
|
||||
}else if(Video.Height > 1080){
|
||||
fbl = 1440
|
||||
}else if(Video.Height > 720){
|
||||
fbl = 1080
|
||||
}else if(Video.Height > 480){
|
||||
fbl = 720
|
||||
}else {
|
||||
fbl = 480
|
||||
}
|
||||
let rname = `[${vinfo.name}].${vinfo.rename}.${vinfo.year}.S${addZeor(vinfo.season)}E${addZeor(dinfo.title)}.WEB-DL.${fbl}p.${Video.Format}.${Audio.Format}.mp4`
|
||||
let state = fs.renameSync(dinfo.save + "/" + dinfo.title + ".mp4",dinfo.save + "/" + rname)
|
||||
|
||||
}else{
|
||||
console.log("未找到当前剧集信息")
|
||||
}
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
// 当前下载状态
|
||||
let state = false
|
||||
async function CheckDown(){
|
||||
if(state){
|
||||
return
|
||||
}
|
||||
let list = await getDownList()
|
||||
if(list.length > 0){
|
||||
state = true
|
||||
let dinfo = list[0]
|
||||
mkdirRecursions(dinfo.save)
|
||||
dow(dinfo,async (msg,s)=>{
|
||||
console.log(String(msg))
|
||||
if(s){
|
||||
let exist = fileIsExist(dinfo.save + "/" + dinfo.title + ".mp4")
|
||||
if(exist){
|
||||
// 设置状态
|
||||
let s = await reName(dinfo)
|
||||
await setDownState(dinfo.id,1)
|
||||
state = false
|
||||
|
||||
}else{
|
||||
// 重新下载
|
||||
console.log("下载失败重新下载")
|
||||
state = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
console.log("定时检测下载")
|
||||
// 设置定时器 每分钟检测更新
|
||||
let job = schedule.scheduleJob('* * * * * *', () => {
|
||||
CheckDown()
|
||||
});
|
@ -1,25 +0,0 @@
|
||||
const path = require('path')
|
||||
const { getListData } = require(path.join(__dirname,'/getList/qq.js'));
|
||||
const {dow} = require("./utils.js");
|
||||
const { mkdirRecursions } = require('./markdir.js');
|
||||
|
||||
// async function getlist (url) {
|
||||
// let list = await getListData(url)
|
||||
// return list
|
||||
// // console.log('electron收到远端的传参', a);
|
||||
// // callback('config result'); // 回调给远端的请求数据,如 config
|
||||
// // ipcRenderer.send('close', 'args bbb'); // 比如收到请求关闭窗口
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
function dowload(info,callback){
|
||||
mkdirRecursions(info.save)
|
||||
console.log("开始",JSON.stringify(info))
|
||||
dow(info,callback)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
dowload
|
||||
}
|
@ -7,7 +7,7 @@ function addDownList(title,url,save,downDate,state,vid){
|
||||
}
|
||||
|
||||
async function getDownList(){
|
||||
let sql = `select * from download where isOk == 0`
|
||||
let sql = `select * from download where state == 0`
|
||||
try{
|
||||
let list = await getAll(sql)
|
||||
return list
|
||||
@ -18,7 +18,7 @@ async function getDownList(){
|
||||
}
|
||||
|
||||
async function setDownState(id,state){
|
||||
let sql = `update download set isOk = ? where id = ?`
|
||||
let sql = `update download set state = ? where id = ?`
|
||||
await run(sql,state,id)
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,21 @@ async function updateSkip(num,id){
|
||||
await run(sql)
|
||||
}
|
||||
|
||||
// 通过sid获取媒体信息
|
||||
async function getVideoInfo(sid){
|
||||
let sql = `select * from VideoInfo where sid=?`
|
||||
let info = await getAll(sql,sid)
|
||||
if(info.length > 0){
|
||||
return info[0]
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addSub,
|
||||
getSub,
|
||||
delSub,
|
||||
updateSkip
|
||||
updateSkip,
|
||||
getVideoInfo
|
||||
}
|
@ -4,15 +4,15 @@ const { cwd } = require('process');
|
||||
const { readFile, createReadStream } = require("fs");
|
||||
const { post } = require("axios");
|
||||
const https = require('https')
|
||||
const fs = require('fs');
|
||||
|
||||
// 设置环境变量为自带的bin
|
||||
function spawn(exe, arg, config) {
|
||||
if (!config) {
|
||||
config = {}
|
||||
}
|
||||
config.env = {
|
||||
path: [path.join(cwd(), '/bin'), path.join(cwd(), '/bin/MediaInfoCLI'), path.join(cwd(), '/bin/Transmission')].join(";")
|
||||
}
|
||||
config.env = {...process.env}
|
||||
config.env.Path = [path.join(cwd(), '/bin'), path.join(cwd(), '/bin/MediaInfoCLI'), path.join(cwd(), '/bin/Transmission')].join(";")
|
||||
|
||||
return spawn2(exe, arg, config)
|
||||
}
|
||||
@ -101,10 +101,17 @@ function getVideoSpecifyTimeImage(filePath, seconds, save) {
|
||||
*/
|
||||
function getMediaInfo(filePath) {
|
||||
return new Promise((resolve) => {
|
||||
let all = ""
|
||||
const lux = spawn("MediaInfo.exe", ['--output=JSON', filePath])
|
||||
lux.stdout.on('data', (data) => {
|
||||
resolve(JSON.parse(data))
|
||||
all += String(data)
|
||||
});
|
||||
lux.stdout.on('close', () => {
|
||||
console.log(all)
|
||||
resolve(JSON.parse(all))
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -129,6 +136,7 @@ function createTorrent(filePath, save) {
|
||||
|
||||
|
||||
function dow(info, callback) {
|
||||
console.log( ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url].join(" "))
|
||||
const lux = spawn("yt-dlp", ['--cookies-from-browser', 'chrome', '-P', info.save, '-o', info.title + '.mp4', info.url], {
|
||||
env: {
|
||||
path: path.join(cwd(), './bin/')
|
||||
@ -181,6 +189,19 @@ function formatSeconds(value) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件是否存在
|
||||
* @param {string} filePath 文件路径
|
||||
* @returns {boolean} true存在,false不存在
|
||||
*/
|
||||
function fileIsExist(filePath){
|
||||
if (fs.existsSync(filePath)) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
seep,
|
||||
dow,
|
||||
@ -189,5 +210,6 @@ module.exports = {
|
||||
createTorrent,
|
||||
getTencentVideoPlayList,
|
||||
uploadImg,
|
||||
spawn
|
||||
spawn,
|
||||
fileIsExist
|
||||
}
|
Loading…
Reference in New Issue
Block a user