Skip to content

Commit 228d3f6

Browse files
authored
Added: youtube-dl-downloader-app (#17)
* Added: youtube-dl-downloader-app * delete: node_modules | modify: README.md * add logo
1 parent e4ac54f commit 228d3f6

16 files changed

+1021
-0
lines changed

youtube-dl-downloader-app/.gitignore

Whitespace-only changes.

youtube-dl-downloader-app/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## dependencies file download
2+
3+
```bash
4+
$ npm install
5+
```
6+
7+
## Build
8+
9+
```bash
10+
$ androidjs b
11+
```

youtube-dl-downloader-app/assets/androidjs.js

Lines changed: 306 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

youtube-dl-downloader-app/assets/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

youtube-dl-downloader-app/assets/bootstrap.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading
3.67 KB
Loading

youtube-dl-downloader-app/assets/jquery-3.3.1.slim.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

youtube-dl-downloader-app/assets/popper.min.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
front.send("hello from front");
3+
4+
front.on("hello from back", function(msg){
5+
console.log(msg);
6+
$('#msg').html(msg);
7+
});

youtube-dl-downloader-app/main.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const back = require('androidjs').back;
2+
const fs = require('fs');
3+
const ytdl = require('ytdl-core');
4+
require('magic-globals');
5+
6+
function error_log(msg) {
7+
back.send('error-log', msg);
8+
}
9+
10+
// service define
11+
// download-mp34 : download mp3, mp4 files
12+
// download-mp3 : download mp3 file
13+
// download-mp4 : download mp4 file
14+
15+
// if download result is ok return to service
16+
// back.send('download-return', result);
17+
18+
// download-mp34 : download mp3, mp4 files
19+
back.on('download-mp34', (datag)=>{
20+
let [movie_dir, music_dir, link_mp4, link_mp3] = datag.split("|");
21+
let data;
22+
// download
23+
data = movie_dir + "|" + link_mp4;
24+
download(data, 18, null);
25+
data = music_dir + "|" + link_mp3;
26+
download(data, 21, ()=>{
27+
back.send('download-return', 'success');
28+
});
29+
});
30+
31+
// download-mp3 : download mp3 file
32+
back.on('download-mp3', (data)=>{
33+
// 21, mp3
34+
download(data, 21, ()=>{
35+
back.send('download-return', 'success');
36+
});
37+
});
38+
39+
// download-mp4 : download mp4 file
40+
back.on('download-mp4', (data)=>{
41+
// 18, mp4
42+
download(data, 18, ()=>{
43+
back.send('download-return', 'success');
44+
});
45+
});
46+
47+
function download(data, format_num, callback) {
48+
let [dir, link] = data.split("|");
49+
// for local node test
50+
// if (dir == 'window-test')
51+
// dir = process.cwd();
52+
53+
let format_ext = (format_num == 21) ? 'mp3' : 'mp4';
54+
try {
55+
ytdl.getInfo(link).then((info, err) => {
56+
if (err) error_log(err + "|" + __line);
57+
back.send('download-start', 'msg');
58+
let fname = info.videoDetails.title.replace('/', '').replace('|', '').toString('utf8');
59+
let store = fs.createWriteStream(`${dir}/${fname}.${format_ext}`);
60+
store.once('error', (err) => {
61+
error_log(err + "|" + "__line");
62+
});
63+
ytdl(link, { format: format_ext })
64+
.pipe(store)
65+
.once('finish', () => {
66+
return callback();
67+
});
68+
});
69+
} catch (error) {
70+
error_log(`${error} | ${__line}`);
71+
}
72+
}

0 commit comments

Comments
 (0)