-
Notifications
You must be signed in to change notification settings - Fork 0
/
hfdl.js
83 lines (72 loc) · 3.6 KB
/
hfdl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const fs = require('fs');
const axios = require('axios');
const cheerio = require('cheerio');
const { exec } = require('child_process');
const process = require('process');
const path = require('path');
console.log(`
░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓███████▓▒░░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓████████▓▒░
By Zibri (2024)
`);
(async function() {
if (process.argv.length < 3) {
console.error('Usage: node hfdl.js <HFUser/repo> [directory]');
console.error('Example: node hfdl.js bartowski/dolphin-2.8-mistral-7b-v02-GGUF');
process.exit(1);
}
let url = process.argv[2]; // URL from command line
const directory = process.argv[3]; // Directory from command line
const dryRun = !directory; // Dry run if directory is not specified
if (!dryRun) {
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}
}
// Check if aria2 is installed
exec('aria2c --version', (error, stdout, stderr) => {
if (error) {
console.error('aria2 is not installed. Please install it before running this script.');
process.exit(1);
}
});
if (!url.startsWith('https://huggingface.co/')) {
url = "https://huggingface.co/"+url+"/tree/main/"
}
const response = await axios.get(url);
const $ = cheerio.load(response.data);
const links = Array.from($('a'));
links.forEach(link => {
if (link.attribs.href.toLowerCase().includes('?download=true')) {
// if (!link.attribs.href.toLowerCase().includes('q8_0')) {
const downloadUrl = new URL(link.attribs.href, url).href; // Resolve relative URLs
var filename = path.basename(downloadUrl); // Extract filename from URL
if (dryRun) {
console.log(`File: ${filename.replace('?download=true', '')}`);
console.log(`URL: ${downloadUrl}`);
} else {
filename=filename.replace('?download=true', '');
exec(`aria2c &>${filename}.log -d ${directory} -o ${filename} ${downloadUrl}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error downloading file: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
}
// }
}
});
if (dryRun) {
console.log('\nTo download the files, a directory must be specified.');
}
})();