-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
60 lines (56 loc) · 1.24 KB
/
index.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
#!/usr/bin/env node
const cheerio = require('cheerio')
const axios = require('axios')
const prompts = require('prompts')
const {
isPlayList,
getPlayList,
getSingleVideo,
downloadVideo,
getInfo,
} = require('./lib/aparat')
const page = process.argv[2]
const path = process.argv[3] || './'
if (!page) {
console.error('error: Page url is required!')
return 0
}
console.info('--- Getting page data ---')
axios.get(page).then(
(response) => {
if (response.status === 200) {
console.info('--- Initializing ---')
const html = response.data
const $ = cheerio.load(html)
if (isPlayList($)) {
//playlist
const videosList = getPlayList($)
videosList.map((item, index) => {
getInfo(item).then((res) => {
const highQuality = res.links.length - 1
downloadVideo(
res.links[highQuality].value,
`${index + 1} - ${res.title}`,
path
)
})
})
} else {
// single video
const video = getSingleVideo($)
;(async () => {
const quality = await prompts([
{
type: 'select',
name: 'link',
message: 'Pick a quality:',
choices: video.links,
},
])
downloadVideo(quality.link, video.title, path)
})()
}
}
},
(err) => console.log(err)
)