mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add colors
This commit is contained in:
parent
372d637155
commit
9e6b4b983f
@ -8,6 +8,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"clipboardy": "^2.0.0",
|
"clipboardy": "^2.0.0",
|
||||||
|
"colors": "^1.3.3",
|
||||||
"command-line-args": "^5.1.1",
|
"command-line-args": "^5.1.1",
|
||||||
"progress": "^2.0.3",
|
"progress": "^2.0.3",
|
||||||
"request": "^2.88.0"
|
"request": "^2.88.0"
|
||||||
|
|||||||
@ -6,6 +6,7 @@ const clipboardy = require("clipboardy");
|
|||||||
const request = require("request");
|
const request = require("request");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const ProgressBar = require("progress");
|
const ProgressBar = require("progress");
|
||||||
|
require("colors");
|
||||||
const optionDefinitions = [
|
const optionDefinitions = [
|
||||||
{ name: 'info', alias: 'i', defaultOption: true, type: String, defaultValue: undefined },
|
{ name: 'info', alias: 'i', defaultOption: true, type: String, defaultValue: undefined },
|
||||||
{ name: 'parts', alias: 'p', type: Number, defaultValue: 30 },
|
{ name: 'parts', alias: 'p', type: Number, defaultValue: 30 },
|
||||||
@ -13,13 +14,14 @@ const optionDefinitions = [
|
|||||||
];
|
];
|
||||||
const commandLineOptions = commandLineArgs(optionDefinitions);
|
const commandLineOptions = commandLineArgs(optionDefinitions);
|
||||||
let options = commandLineOptions;
|
let options = commandLineOptions;
|
||||||
|
options.parts = Math.round(options.parts);
|
||||||
// if (fs.existsSync("settings.json"))
|
// if (fs.existsSync("settings.json"))
|
||||||
// {
|
// {
|
||||||
// const jsonOptions = JSON.parse(fs.readFileSync("settings.json").toString("utf-8")) as Settings;
|
// const jsonOptions = JSON.parse(fs.readFileSync("settings.json").toString("utf-8")) as Settings;
|
||||||
// options = Object.assign(jsonOptions, options);
|
// options = Object.assign(jsonOptions, options);
|
||||||
// }
|
// }
|
||||||
if (options.parts < 1) {
|
if (options.parts < 1) {
|
||||||
console.error("分段数不能小于1");
|
console.error("分段数不能小于1".red);
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
class Downloader {
|
class Downloader {
|
||||||
@ -44,7 +46,7 @@ class Downloader {
|
|||||||
const files = fs.readdirSync(".");
|
const files = fs.readdirSync(".");
|
||||||
const parts = files.filter(it => it.includes(this.inputData.title));
|
const parts = files.filter(it => it.includes(this.inputData.title));
|
||||||
parts.forEach(file => fs.unlinkSync(file));
|
parts.forEach(file => fs.unlinkSync(file));
|
||||||
console.log("已取消下载");
|
console.log("已取消下载".blue);
|
||||||
}
|
}
|
||||||
async downloadFragment(fragment, index = -1) {
|
async downloadFragment(fragment, index = -1) {
|
||||||
const partialLength = Math.round(fragment.size / options.parts);
|
const partialLength = Math.round(fragment.size / options.parts);
|
||||||
@ -80,7 +82,7 @@ class Downloader {
|
|||||||
this.progressMap.delete(req);
|
this.progressMap.delete(req);
|
||||||
this.progressMap.set(makeRequest(), 0);
|
this.progressMap.set(makeRequest(), 0);
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
console.error(`\n片段下载失败: ${error} 重试中...`);
|
console.error(`\n片段下载失败: ${error} 重试中...`.yellow);
|
||||||
});
|
});
|
||||||
req.pipe(fs.createWriteStream(`${title}.part${part}`));
|
req.pipe(fs.createWriteStream(`${title}.part${part}`));
|
||||||
return req;
|
return req;
|
||||||
@ -96,10 +98,10 @@ class Downloader {
|
|||||||
async mergeFragment(title, index = -1) {
|
async mergeFragment(title, index = -1) {
|
||||||
const dest = title + ".flv";
|
const dest = title + ".flv";
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
console.log("正在合并片段" + index.toString() + "...");
|
console.log("正在合并片段" + index.toString() + "...".green);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("正在合并文件...");
|
console.log("正在合并文件...".green);
|
||||||
}
|
}
|
||||||
if (options.parts === 1) {
|
if (options.parts === 1) {
|
||||||
fs.renameSync(title + ".part0", dest);
|
fs.renameSync(title + ".part0", dest);
|
||||||
@ -124,7 +126,7 @@ class Downloader {
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
async download() {
|
async download() {
|
||||||
console.log(`正在下载: ${this.inputData.title}`);
|
console.log(`正在下载: ${this.inputData.title}`.green);
|
||||||
this.progressBar.render();
|
this.progressBar.render();
|
||||||
let result;
|
let result;
|
||||||
if (this.inputData.fragments.length === 1) {
|
if (this.inputData.fragments.length === 1) {
|
||||||
@ -134,7 +136,7 @@ class Downloader {
|
|||||||
const titles = await Promise.all(this.inputData.fragments.map((f, i) => this.downloadFragment(f, i)));
|
const titles = await Promise.all(this.inputData.fragments.map((f, i) => this.downloadFragment(f, i)));
|
||||||
result = await Promise.all(titles.map((t, i) => this.mergeFragment(t, i)));
|
result = await Promise.all(titles.map((t, i) => this.mergeFragment(t, i)));
|
||||||
}
|
}
|
||||||
console.log(`下载完成: `);
|
console.log(`下载完成: `.green);
|
||||||
if (typeof result === "string") {
|
if (typeof result === "string") {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
}
|
}
|
||||||
@ -145,7 +147,7 @@ class Downloader {
|
|||||||
}
|
}
|
||||||
Downloader.workingDownloader = null;
|
Downloader.workingDownloader = null;
|
||||||
(async () => {
|
(async () => {
|
||||||
// console.log(`分段值: ${options.parts}`);
|
try {
|
||||||
let jsonText = '';
|
let jsonText = '';
|
||||||
if (fs.existsSync(options.info)) {
|
if (fs.existsSync(options.info)) {
|
||||||
jsonText = fs.readFileSync(options.info).toString("utf-8");
|
jsonText = fs.readFileSync(options.info).toString("utf-8");
|
||||||
@ -153,8 +155,17 @@ Downloader.workingDownloader = null;
|
|||||||
else {
|
else {
|
||||||
jsonText = await clipboardy.read();
|
jsonText = await clipboardy.read();
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
const inputData = JSON.parse(jsonText);
|
const inputData = JSON.parse(jsonText);
|
||||||
|
if (!(function (data) {
|
||||||
|
if (Array.isArray(data) && data.length > 0) {
|
||||||
|
return data[0].fragments !== undefined;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return data.fragments !== undefined;
|
||||||
|
}
|
||||||
|
})(inputData)) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
process.chdir(options.output);
|
process.chdir(options.output);
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
@ -174,10 +185,10 @@ Downloader.workingDownloader = null;
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
Downloader.workingDownloader && Downloader.workingDownloader.cancelDownload();
|
Downloader.workingDownloader && Downloader.workingDownloader.cancelDownload();
|
||||||
console.error(`\n错误: ${error}`);
|
console.error(`\n错误: ${error}`.red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(`[无数据] 未在剪贴板检测到有效数据/没有指定输入文件/输入文件的数据无效.`);
|
console.log(`[无数据] 未在剪贴板检测到有效数据/没有指定输入文件/输入文件的数据无效.`.red);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import clipboardy = require("clipboardy");
|
|||||||
import request = require("request");
|
import request = require("request");
|
||||||
import fs = require("fs");
|
import fs = require("fs");
|
||||||
import ProgressBar = require("progress");
|
import ProgressBar = require("progress");
|
||||||
|
import "colors";
|
||||||
|
|
||||||
interface Fragment
|
interface Fragment
|
||||||
{
|
{
|
||||||
@ -32,6 +33,7 @@ const optionDefinitions = [
|
|||||||
];
|
];
|
||||||
const commandLineOptions = commandLineArgs(optionDefinitions) as Settings;
|
const commandLineOptions = commandLineArgs(optionDefinitions) as Settings;
|
||||||
let options = commandLineOptions;
|
let options = commandLineOptions;
|
||||||
|
options.parts = Math.round(options.parts);
|
||||||
// if (fs.existsSync("settings.json"))
|
// if (fs.existsSync("settings.json"))
|
||||||
// {
|
// {
|
||||||
// const jsonOptions = JSON.parse(fs.readFileSync("settings.json").toString("utf-8")) as Settings;
|
// const jsonOptions = JSON.parse(fs.readFileSync("settings.json").toString("utf-8")) as Settings;
|
||||||
@ -40,7 +42,7 @@ let options = commandLineOptions;
|
|||||||
|
|
||||||
if (options.parts < 1)
|
if (options.parts < 1)
|
||||||
{
|
{
|
||||||
console.error("分段数不能小于1");
|
console.error("分段数不能小于1".red);
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ class Downloader
|
|||||||
const files = fs.readdirSync(".");
|
const files = fs.readdirSync(".");
|
||||||
const parts = files.filter(it => it.includes(this.inputData.title));
|
const parts = files.filter(it => it.includes(this.inputData.title));
|
||||||
parts.forEach(file => fs.unlinkSync(file));
|
parts.forEach(file => fs.unlinkSync(file));
|
||||||
console.log("已取消下载");
|
console.log("已取消下载".blue);
|
||||||
}
|
}
|
||||||
private async downloadFragment(fragment: Fragment, index: number = -1)
|
private async downloadFragment(fragment: Fragment, index: number = -1)
|
||||||
{
|
{
|
||||||
@ -118,7 +120,7 @@ class Downloader
|
|||||||
this.progressMap.delete(req);
|
this.progressMap.delete(req);
|
||||||
this.progressMap.set(makeRequest(), 0);
|
this.progressMap.set(makeRequest(), 0);
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
console.error(`\n片段下载失败: ${error} 重试中...`);
|
console.error(`\n片段下载失败: ${error} 重试中...`.yellow);
|
||||||
});
|
});
|
||||||
req.pipe(fs.createWriteStream(`${title}.part${part}`));
|
req.pipe(fs.createWriteStream(`${title}.part${part}`));
|
||||||
return req;
|
return req;
|
||||||
@ -136,11 +138,11 @@ class Downloader
|
|||||||
const dest = title + ".flv";
|
const dest = title + ".flv";
|
||||||
if (index !== -1)
|
if (index !== -1)
|
||||||
{
|
{
|
||||||
console.log("正在合并片段" + index.toString() + "...");
|
console.log("正在合并片段" + index.toString() + "...".green);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log("正在合并文件...");
|
console.log("正在合并文件...".green);
|
||||||
}
|
}
|
||||||
if (options.parts === 1)
|
if (options.parts === 1)
|
||||||
{
|
{
|
||||||
@ -171,7 +173,7 @@ class Downloader
|
|||||||
}
|
}
|
||||||
async download()
|
async download()
|
||||||
{
|
{
|
||||||
console.log(`正在下载: ${this.inputData.title}`);
|
console.log(`正在下载: ${this.inputData.title}`.green);
|
||||||
this.progressBar.render();
|
this.progressBar.render();
|
||||||
let result: string | string[];
|
let result: string | string[];
|
||||||
if (this.inputData.fragments.length === 1)
|
if (this.inputData.fragments.length === 1)
|
||||||
@ -183,7 +185,7 @@ class Downloader
|
|||||||
const titles = await Promise.all(this.inputData.fragments.map((f, i) => this.downloadFragment(f, i)));
|
const titles = await Promise.all(this.inputData.fragments.map((f, i) => this.downloadFragment(f, i)));
|
||||||
result = await Promise.all(titles.map((t, i) => this.mergeFragment(t, i)));
|
result = await Promise.all(titles.map((t, i) => this.mergeFragment(t, i)));
|
||||||
}
|
}
|
||||||
console.log(`下载完成: `);
|
console.log(`下载完成: `.green);
|
||||||
if (typeof result === "string")
|
if (typeof result === "string")
|
||||||
{
|
{
|
||||||
console.log(result);
|
console.log(result);
|
||||||
@ -196,7 +198,8 @@ class Downloader
|
|||||||
}
|
}
|
||||||
(async () =>
|
(async () =>
|
||||||
{
|
{
|
||||||
// console.log(`分段值: ${options.parts}`);
|
try
|
||||||
|
{
|
||||||
let jsonText = '';
|
let jsonText = '';
|
||||||
if (fs.existsSync(options.info))
|
if (fs.existsSync(options.info))
|
||||||
{
|
{
|
||||||
@ -206,9 +209,21 @@ class Downloader
|
|||||||
{
|
{
|
||||||
jsonText = await clipboardy.read();
|
jsonText = await clipboardy.read();
|
||||||
}
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
const inputData = JSON.parse(jsonText) as InputData | InputData[];
|
const inputData = JSON.parse(jsonText) as InputData | InputData[];
|
||||||
|
if (!(function (data: any): data is InputData | InputData[]
|
||||||
|
{
|
||||||
|
if (Array.isArray(data) && data.length > 0)
|
||||||
|
{
|
||||||
|
return data[0].fragments !== undefined;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return data.fragments !== undefined;
|
||||||
|
}
|
||||||
|
})(inputData))
|
||||||
|
{
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process.chdir(options.output);
|
process.chdir(options.output);
|
||||||
@ -234,11 +249,11 @@ class Downloader
|
|||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
Downloader.workingDownloader && Downloader.workingDownloader.cancelDownload();
|
Downloader.workingDownloader && Downloader.workingDownloader.cancelDownload();
|
||||||
console.error(`\n错误: ${error}`);
|
console.error(`\n错误: ${error}`.red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
console.log(`[无数据] 未在剪贴板检测到有效数据/没有指定输入文件/输入文件的数据无效.`);
|
console.log(`[无数据] 未在剪贴板检测到有效数据/没有指定输入文件/输入文件的数据无效.`.red);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@ -10,7 +10,7 @@
|
|||||||
TintColor="#0fff"
|
TintColor="#0fff"
|
||||||
FallbackColor="#0fff"
|
FallbackColor="#0fff"
|
||||||
Foreground="Black"
|
Foreground="Black"
|
||||||
NoiseOpacity="0.01"
|
NoiseOpacity="0.05"
|
||||||
Title="MainWindow"
|
Title="MainWindow"
|
||||||
ShowTitleBar="False"
|
ShowTitleBar="False"
|
||||||
Height="450"
|
Height="450"
|
||||||
|
|||||||
@ -21,23 +21,23 @@ namespace VideoLinkDownloader
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
button.Click += (s,e) =>
|
//button.Click += (s,e) =>
|
||||||
{
|
//{
|
||||||
AcrylicBlur.Apply(this, new Color
|
// AcrylicBlur.Apply(this, new Color
|
||||||
{
|
// {
|
||||||
A = 0,
|
// A = 0,
|
||||||
R = 255,
|
// R = 255,
|
||||||
G = 255,
|
// G = 255,
|
||||||
B = 255,
|
// B = 255,
|
||||||
}, AccentState.Diabled);
|
// }, AccentState.Diabled);
|
||||||
AcrylicBlur.Apply(this, new Color
|
// AcrylicBlur.Apply(this, new Color
|
||||||
{
|
// {
|
||||||
A = 0,
|
// A = 0,
|
||||||
R = 255,
|
// R = 255,
|
||||||
G = 255,
|
// G = 255,
|
||||||
B = 255,
|
// B = 255,
|
||||||
}, AccentState.AcrylicBlurBehind);
|
// }, AccentState.AcrylicBlurBehind);
|
||||||
};
|
//};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user