-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilidown.R
53 lines (47 loc) · 2.26 KB
/
bilidown.R
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
# load functions
source("./functions.R")
# accept parameters
options(repos=structure(c(CRAN="http://mirrors.aliyun.com/CRAN/")))
if (!requireNamespace("optparse", quietly = TRUE))
suppressMessages(install.packages("optparse", quiet = T))
suppressWarnings(library("optparse"))
option_list = list(make_option("--url", type = "character", default = NULL, help = "video URL."),
make_option("--list", type = "character", default = NULL, help = "Whether download playlist."),
make_option("--mp3", type = "character", default = NULL, help = "Whether tranfer to mp3."),
make_option("--file", type = "character", default = NULL, help = "Whether get URL(s) from file."),
make_option("--mp3Folder", type = "character", default = NULL, help = "Mp3 output folder."),
make_option("--mp4Folder", type = "character", default = NULL, help = "Mp4 output folder."),
make_option("--name", type = "character", default = NULL, help = "Rename output file."),
make_option("--start", type = "character", default = NULL, help = "Start point of mp3 cut"),
make_option("--end", type = "character", default = NULL, help = "end point of mp3 cut"))
args <- parse_args(OptionParser(option_list=option_list))
# check parameters
if(is.null(args$url) & is.null(args$file)){ # neither exists
getHelp()
stop("One of the variables url and file must be provided!\n")
}
if(!(is.null(args$url) | is.null(args$file))){ # both exist
getHelp()
stop("Only one of the variables url and file needs to be provided!\n")
}
if(is.null(args$mp4Folder)){
getHelp()
stop("Argument mp4Folder must be given!\n")
}
# check whether output folder exists
checKFolderExists(args$mp4Folder)
if(!is.null(args$mp3))
checKFolderExists(args$mp3Folder)
# download video from cmd URL
if(!is.null(args$url))
runWorkflow(args)
# download video from URL file
if(!is.null(args$file)){
text = readLines(args$file, encoding = "UTF-8")
Ns = length(text)
for(i in 1:Ns){
cat("\nProcessing serial number", paste0(i, ","), "Remian", Ns - i, "\n")
args = getDownInfos(text[i])
runWorkflow(args)
}
}