完成下载

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

View File

@ -1,6 +1,7 @@
const path = require('path') const path = require('path')
const { getListData } = require(path.join(__dirname,'/getList/qq.js')); 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) { // async function getlist (url) {
// let list = await getListData(url) // let list = await getListData(url)
@ -14,7 +15,8 @@ const {dow} = require("./utils.js")
function dowload(info,callback){ function dowload(info,callback){
console.log("开始") mkdirRecursions(info.save)
console.log("开始",JSON.stringify(info))
dow(info,callback) 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){ 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) => { lux.stdout.on('data', (data) => {
console.log(String(data)) console.log(String(data))
callback(String(data),false) 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" /> <link rel="icon" type="image/svg+xml" href="./vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title> <title>Vite + Vue</title>
<script type="module" crossorigin src="./assets/index-54b3342f.js"></script> <script type="module" crossorigin src="./assets/index-ed416134.js"></script>
<link rel="stylesheet" href="./assets/index-711c0355.css"> <link rel="stylesheet" href="./assets/index-6ef103ac.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -28,7 +28,7 @@
</el-table-column> </el-table-column>
<el-table-column label="url" prop="url" /> <el-table-column label="url" prop="url" />
</el-table> </el-table>
<el-dialog :fullscreen="true" v-model="dialogVisible" title="Tips" width="30%" > <el-dialog :fullscreen="true" v-model="dialogVisible" title="Tips" width="30%">
<div style="width: 100%;height: 100%;overflow-y: auto;"> <div style="width: 100%;height: 100%;overflow-y: auto;">
<div v-for="i in msg">{{ i }}</div> <div v-for="i in msg">{{ i }}</div>
</div> </div>
@ -39,13 +39,13 @@
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from 'vue';
import { ElLoading,ElMessage } from 'element-plus' import { ElLoading, ElMessage } from 'element-plus'
import axios from 'axios'; import axios from 'axios';
const dialogVisible = ref(false) const dialogVisible = ref(false)
const form = ref({ const form = ref({
name: "https://v.qq.com/x/cover/mzc002007vp35qj.html", name: "https://v.qq.com/x/cover/mzc002007vp35qj.html",
start: 1, start: 1,
save:"D:/dl" save: localStorage.getItem("save")
}) })
const tableData = ref([]) const tableData = ref([])
const table = ref() const table = ref()
@ -56,9 +56,9 @@ function getlist() {
// tableData.value = res // tableData.value = res
// load.close() // load.close()
// }) // })
axios.get("http://127.0.0.1:3050/getQqList",{ axios.get("http://127.0.0.1:3050/getQqList", {
params: {url:form.value.name} params: { url: form.value.name }
}).then((r)=>{ }).then((r) => {
tableData.value = r.data tableData.value = r.data
}) })
} }
@ -72,11 +72,33 @@ function setlist() {
const msg = ref([]) const msg = ref([])
async function dow() { async function dow() {
dialogVisible.value = true
let list = table.value.getSelectionRows() let list = table.value.getSelectionRows()
for(let i of list){ if (list.length == 0) {
await axios.get("http://127.0.0.1:3050/startDown",{ ElMessage({
params:i 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,
save: form.value.save + "/" + i.title.split(" ")[0]
}
}) })
} }
// dialogVisible.value = false // dialogVisible.value = false
@ -84,15 +106,17 @@ async function dow() {
showClose: true, showClose: true,
message: '添加完成', message: '添加完成',
type: 'success', type: 'success',
duration:0
}) })
} }
const source = new EventSource(`http://127.0.0.1:3050/msg`); const source = new EventSource(`http://127.0.0.1:3050/msg`);
source.onmessage = event => { source.onmessage = event => {
// //
msg.value.unshift(event.data) if (msg.value.length > 200) {
msg.value.splice(200)
}
msg.value.unshift(event.data)
} }
function showmsg(){ function showmsg() {
dialogVisible.value = true dialogVisible.value = true
} }
</script> </script>