Skip to content

Commit

Permalink
Prefer const
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed May 8, 2021
1 parent e071daa commit f2e9a2d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
50 changes: 26 additions & 24 deletions app/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Downloader {
}

getVideoUrl() {
let videoUrl = $("#videoUrl").val();
const videoUrl = $("#videoUrl").val();
this.url = "";
const mapping = {
"BV": "https://www.bilibili.com/video/",
Expand All @@ -30,7 +30,7 @@ class Downloader {
"ep": "https://www.bilibili.com/bangumi/play/",
"ss": "https://www.bilibili.com/bangumi/play/"
};
for (let [key, value] of Object.entries(mapping)) {
for (const [key, value] of Object.entries(mapping)) {
if (videoUrl.includes(key)) {
this.type = key;
this.id = key + videoUrl.split(key)[1];
Expand All @@ -48,7 +48,7 @@ class Downloader {

getAid() {
this.getVideoUrl();
let { type, url } = this;
const { type, url } = this;
if (!url) return;
fetch(url)
.then(response => response.text())
Expand All @@ -75,7 +75,7 @@ class Downloader {
}

getInfo() {
let { id, aid, cid } = this;
const { id, aid, cid } = this;
if (!cid) {
showError("获取视频 cid 出错!");
return;
Expand Down Expand Up @@ -111,14 +111,15 @@ class Downloader {
}

getData(fallback) {
let { cid, type } = this, playUrl;
const { cid, type } = this;
let playUrl;
if (fallback) {
let params = `cid=${cid}&module=movie&player=1&quality=112&ts=1`,
const params = `cid=${cid}&module=movie&player=1&quality=112&ts=1`,
sign = crypto.createHash("md5").update(params + "9b288147e5474dd2aa67085f716c560d").digest("hex");
playUrl = `https://bangumi.bilibili.com/player/web_api/playurl?${params}&sign=${sign}`;
} else {
if (type === "BV" || type === "bv" || type === "av") {
let params = `appkey=iVGUTjsxvpLeuDCf&cid=${cid}&otype=json&qn=112&quality=112&type=`,
const params = `appkey=iVGUTjsxvpLeuDCf&cid=${cid}&otype=json&qn=112&quality=112&type=`,
sign = crypto.createHash("md5").update(params + "aHRmhWMLkdeMuILqORnYZocwMBpMEOdt").digest("hex");
playUrl = `https://interface.bilibili.com/v2/playurl?${params}&sign=${sign}`;
} else {
Expand All @@ -128,11 +129,11 @@ class Downloader {
fetch(playUrl)
.then(response => response.text())
.then(result => {
let data = fallback ? $(result) : JSON.parse(result),
target = fallback ? data.find("durl") : (data.durl || data.result.durl);
const data = fallback ? $(result) : JSON.parse(result);
const target = fallback ? data.find("durl") : (data.durl || data.result.durl);
console.log("PLAY URL", data);
if (target) {
let quality = fallback ? $(data).find("quality").text() : (data.quality || data.result.quality),
const quality = fallback ? $(data).find("quality").text() : (data.quality || data.result.quality),
qualityArray = {
112: "高清 1080P+",
80: "高清 1080P",
Expand Down Expand Up @@ -161,7 +162,7 @@ class Downloader {
this.links = [];
$("tbody").eq(0).html("");
target.each((i, o) => {
let part = $(o);
const part = $(o);
this.links.push(part.find("url").text());
$("tbody").eq(0).append(`<tr>
<td>${part.find("order").text()}</td>
Expand All @@ -179,7 +180,7 @@ class Downloader {
parseData(target) {
this.links = [];
$("tbody").eq(0).html("");
for (let part of target) {
target.forEach(part => {
this.links.push(part.url);
$("tbody").eq(0).append(`<tr>
<td>${part.order}</td>
Expand All @@ -191,11 +192,12 @@ class Downloader {
</div>
</td>
</tr>`);
}
});
}

downloadAll() {
let { cid } = this, flag = true;
const { cid } = this;
let flag = true;
document.querySelectorAll("tbody input[type=checkbox]").forEach((element, part) => {
if (!element.checked || this.downloading.includes(this.links[part])) return;
$("#download").append(`<span>${cid}-${part}</span>
Expand All @@ -216,33 +218,33 @@ class Downloader {
}

downloadLink(part) {
let { name, cid, url } = this;
let downloadPath = $("#downloadPath").val(),
filename = $("#videoName").val() || name || cid,
file = path.join(downloadPath, `${sanitize(filename)}-${part}.flv`);
const { name, cid, url } = this;
const downloadPath = $("#downloadPath").val();
const filename = $("#videoName").val() || name || cid;
const file = path.join(downloadPath, `${sanitize(filename)}-${part}.flv`);
fs.stat(file, (error, state) => {
let options = {
const options = {
url: this.links[part],
headers: {
"Range": `bytes=${state ? state.size : 0}-`, //断点续传
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36",
"Referer": url
}
};
let downloads = fs.createWriteStream(file, state ? { flags: "a" } : {}),
const downloads = fs.createWriteStream(file, state ? { flags: "a" } : {}),
index = this.downloading.indexOf(options.url);
this.download(index, options, downloads);
state && $(".addon").eq(index).html(`从 ${Math.round(state.size / 1e6)}MB 处恢复的下载`);
if (state) $(".addon").eq(index).html(`从 ${Math.round(state.size / 1e6)}MB 处恢复的下载`);
//console.log(this.cid, file, options.url);
});
}

download(index, options, downloads) {
// https://blog.csdn.net/zhu_06/article/details/79772229
let proStream = progress({
// https://www.npmjs.com/package/progress-stream
const proStream = progress({
time: 250 //单位ms
}).on("progress", progress => {
let { speed, eta, percentage } = progress; //显示进度条
const { speed, eta, percentage } = progress; //显示进度条
$(".speed").eq(index).html(Math.round(speed / 1e3) + "KB/s");
$(".eta").eq(index).html(`eta:${eta}s`);
$(".progress-bar").eq(index).css("width", percentage + "%").html(Math.round(percentage) + "%");
Expand Down
14 changes: 7 additions & 7 deletions app/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container g-0">
<div class="container-fluid g-4 mt-3">
<h1>Mimi Downloader</h1>
<p id="help">欢迎使用米米下载器,轻松下载高清视频、弹幕</p>
<div class="mb-3">
Expand Down Expand Up @@ -220,16 +220,16 @@ <h1>Mimi Downloader</h1>
}

function searchDanmaku() {
let text = $("#searchDanmaku").val();
const text = $("#searchDanmaku").val();
if (!$("#filterSwitch").is(":checked")) {
danmakuFilter(text);
return;
}
let T1 = parseFloat($("#T1").val()),
T2 = parseFloat($("#T2").val()),
ST1 = parseFloat($("#T1").val()),
ST2 = parseFloat($("#ST2").val()),
user = $("#user").val();
const T1 = parseFloat($("#T1").val());
const T2 = parseFloat($("#T2").val());
const ST1 = parseFloat($("#ST1").val());
const ST2 = parseFloat($("#ST2").val());
const user = $("#user").val();
danmakuFilter(text, T1, T2, ST1, ST2, user);
}

Expand Down
4 changes: 0 additions & 4 deletions app/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
body {
overflow-x: hidden;
}
.container {
margin: 20px;
max-width: calc(100% - 40px);
}
.tab-pane, #nav {
display: none;
}
Expand Down

0 comments on commit f2e9a2d

Please sign in to comment.