完成下载

This commit is contained in:
theluyuan 2023-06-14 22:02:50 +08:00
parent bfde74bb87
commit 3963fd8fad
11 changed files with 160 additions and 133 deletions

View File

@ -15,8 +15,9 @@ router.get("/getQqList",async (ctx)=>{
router.get("/startDown",async (ctx)=>{
let title = ctx.query.title
let url = ctx.query.url
let save = ctx.query.save
dowloadlist.push({
title,url
title,url,save
})
// startDown()
ctx.body={
@ -37,11 +38,11 @@ router.get('/msg', KoaSSEStream(SSE_CONF), ctx => {
})
let start = false
function startDown(){
start = true
dowload(dowloadlist[0],(data,isok)=>{
let name = dowloadlist[0].title
clientList.forEach((i)=>{
i.send(isok ? `${title}下载完成` : data )
i.send(isok ? `${name}下载完成` : data )
if(isok){
dowloadlist.shift()
start = false
@ -51,7 +52,6 @@ function startDown(){
}
setInterval(()=>{
if(dowloadlist.length != 0 && !start){
start = true
startDown()
}else if(dowloadlist.length == 0){
start = false

View File

@ -1,6 +1,7 @@
const path = require('path')
const { getListData } = require(path.join(__dirname,'/getList/qq.js'));
const {dow} = require("./utils.js")
const {dow} = require("./utils.js");
const { mkdirRecursions } = require('./markdir.js');
// async function getlist (url) {
// let list = await getListData(url)
@ -14,7 +15,8 @@ const {dow} = require("./utils.js")
function dowload(info,callback){
console.log("开始")
mkdirRecursions(info.save)
console.log("开始",JSON.stringify(info))
dow(info,callback)
}

52
util/markdir.js Normal file
View File

@ -0,0 +1,52 @@
const fs= require("fs")
const path = require("path")
/**
* 读取路径信息
* @param {string} path 路径
*/
function getStat(dir) {
try {
const stat = fs.statSync(dir);
return stat;
} catch (error) {
return false;
}
}
/**
* 创建路径
* @param {string} dir 路径
*/
function mkdir(dir) {
return fs.mkdirSync(dir)
}
/**
* 路径是否存在不存在则创建
* @param {string} dir 路径
*/
function mkdirRecursions(dir) {
let isExists = getStat(dir);
console.log(isExists)
//如果该路径且不是文件返回true
if (isExists && isExists.isDirectory()) {
return true;
}
else if(isExists){
return false;
}
//如果该路径不存在,拿到上级路径
let tempDir = path.parse(dir).dir;
//递归判断,如果上级目录也不存在,则会代码会在此处继续循环执行,直到目录存在
let status = mkdirRecursions(tempDir);
let mkdirStatus;
if (status) {
mkdirStatus = mkdir(dir);
}
return mkdirStatus;
}
module.exports = {
mkdirRecursions
}

View File

@ -10,7 +10,7 @@ function seep(time){
}
function dow(info,callback){
const lux = spawn("./bin/yt-dlp.exe", ['--cookies-from-browser', 'edge', '-P', 'D:/dl', '-o', info.title + '.mp4', info.url])
const lux = spawn("./bin/yt-dlp.exe", ['--cookies-from-browser', 'edge', '-P', info.save, '-o', info.title + '.mp4', info.url])
lux.stdout.on('data', (data) => {
console.log(String(data))
callback(String(data),false)

3
view/dist/assets/index-07bbb742.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
import{_ as E,r as u,a as i,o as p,c as f,b as t,w as s,d as v,e as g,F as q,f as B,E as D,g as N,t as U}from"./index-54b3342f.js";const F={class:"url"},L={style:{display:"flex",width:"100%"}},R={style:{display:"flex"}},T={style:{width:"100%",height:"100%","overflow-y":"auto"}},j={__name:"index",setup(z){const d=u(!1),n=u({name:"https://v.qq.com/x/cover/mzc002007vp35qj.html",start:1}),c=u([]),r=u();function x(){let l=D.service();window.getlist(n.value.name).then(e=>{console.log(e),c.value=e,l.close()})}function h(){r.value.clearSelection();for(let l=n.value.start-1;l<c.value.length;l++)console.log(l),r.value.toggleRowSelection(c.value[l],void 0)}const y=u([]);function b(l,e,o){console.log(o),o?l():y.value.unshift(e)}function V(l){return new Promise(e=>{const o=b.bind(this,e);window.dowload(l,o)})}async function k(){d.value=!0;let l=r.value.getSelectionRows();for(let e of l)await V(e);d.value=!1,N({showClose:!0,message:"下载完成",type:"success",duration:0})}return(l,e)=>{const o=i("el-input"),_=i("el-button"),w=i("el-form-item"),m=i("el-table-column"),C=i("el-table"),S=i("el-dialog");return p(),f("div",F,[t(w,{label:"视频地址"},{default:s(()=>[v("div",L,[t(o,{style:{width:"100%"},modelValue:n.value.name,"onUpdate:modelValue":e[0]||(e[0]=a=>n.value.name=a)},null,8,["modelValue"]),t(_,{style:{"flex-shrink":"0",margin:"0 10px"},onClick:x,type:"primary"},{default:s(()=>[g("获取")]),_:1})])]),_:1}),t(w,{label:"第几集开始"},{default:s(()=>[v("div",R,[t(o,{modelValue:n.value.start,"onUpdate:modelValue":e[1]||(e[1]=a=>n.value.start=a)},null,8,["modelValue"]),t(_,{style:{"flex-shrink":"0",margin:"0 10px"},onClick:h,type:"primary"},{default:s(()=>[g("设置")]),_:1}),t(_,{style:{"flex-shrink":"0",margin:"0 10px"},onClick:k,type:"primary"},{default:s(()=>[g("下载")]),_:1})])]),_:1}),t(C,{ref_key:"table",ref:r,data:c.value,style:{width:"100%"}},{default:s(()=>[t(m,{type:"selection",width:"55"}),t(m,{label:"title",prop:"title"}),t(m,{label:"url",prop:"url"})]),_:1},8,["data"]),t(S,{fullscreen:!0,"close-on-click-modal":!1,"close-on-press-escape":!1,modelValue:d.value,"onUpdate:modelValue":e[2]||(e[2]=a=>d.value=a),"show-close":!1,title:"Tips",width:"30%"},{default:s(()=>[v("div",T,[(p(!0),f(q,null,B(y.value,a=>(p(),f("div",null,U(a),1))),256))])]),_:1},8,["modelValue"])])}}},M=E(j,[["__scopeId","data-v-550c913f"],["__file","D:/xiangmu/ptSend/view/src/page/index.vue"]]);export{M as default};

54
view/dist/assets/index-ed416134.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
<script type="module" crossorigin src="./assets/index-54b3342f.js"></script>
<link rel="stylesheet" href="./assets/index-711c0355.css">
<script type="module" crossorigin src="./assets/index-ed416134.js"></script>
<link rel="stylesheet" href="./assets/index-6ef103ac.css">
</head>
<body>
<div id="app"></div>

View File

@ -45,7 +45,7 @@ const dialogVisible = ref(false)
const form = ref({
name: "https://v.qq.com/x/cover/mzc002007vp35qj.html",
start: 1,
save:"D:/dl"
save: localStorage.getItem("save")
})
const tableData = ref([])
const table = ref()
@ -72,11 +72,33 @@ function setlist() {
const msg = ref([])
async function dow() {
dialogVisible.value = true
let list = table.value.getSelectionRows()
if (list.length == 0) {
ElMessage({
showClose: true,
message: '请选择要下载的剧集',
type: 'error',
})
return
}
if (!form.value.save) {
ElMessage({
showClose: true,
message: '请填写下载位置',
type: 'error',
})
return
}
dialogVisible.value = true
localStorage.setItem("save",form.value.save)
for (let i of list) {
await axios.get("http://127.0.0.1:3050/startDown", {
params:i
params: {
...i,
save: form.value.save + "/" + i.title.split(" ")[0]
}
})
}
// dialogVisible.value = false
@ -84,12 +106,14 @@ async function dow() {
showClose: true,
message: '添加完成',
type: 'success',
duration:0
})
}
const source = new EventSource(`http://127.0.0.1:3050/msg`);
source.onmessage = event => {
//
if (msg.value.length > 200) {
msg.value.splice(200)
}
msg.value.unshift(event.data)
}
function showmsg() {