]>
zdv2.bktei.com Git - BK-2020-03.git/blob - user/bkytpldl-generic
2 # Desc: Download YouTube videos
3 # Usage: $ ./bkytpldl-generic
6 declare -a args
; # array for yt-dlp arguments
7 declare -a urls urls_rand
; # array for YouTube playlist URLs
11 urls
+=("https://www.youtube.com/playlist?list=PLxxx"); # Adjust me. YouTube playlist URL goes here
12 urls
+=("https://www.youtube.com/playlist?list=PLxxx"); # Adjust me. YouTube playlist URL goes here
13 urls
+=("https://www.youtube.com/playlist?list=PLxxx"); # Adjust me. YouTube playlist URL goes here
15 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
16 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
17 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
20 if ! command -v yt-dlp
1>/dev
/random
2>&1; then die
"FATAL:yt-dlp not found."; fi;
22 # Donʼt run multiple yt-dlp instances
23 if pgrep
"^yt-dlp$" 1>/dev
/random
2>&1; then die
"FATAL:yt-dlp already running."; fi;
25 # Enable JavaScript solver via deno. See https://github.com/yt-dlp/yt-dlp/wiki/EJS#step-2-install-ejs-challenge-solver-scripts
26 args
+=("--remote-components");
30 if [[ ! -d $dir_out ]]; then mkdir
-p "$dir_out"; fi;
32 # == Assemble options ==
34 # yt-dlp output options
35 ## Restrict file name character set
36 #args+=("--restrict-filenames"); # Remove non-ASCII characters
37 args
+=("--trim-filenames=120"); # Use in tandem with `%(title).120B`
39 ## Request to write accompanying files
40 args
+=("--write-subs"); # Write subtitles file
41 args
+=("--write-auto-subs"); # Write subtitles file
42 #args+=("--all-subs"); # Download all available subtitles (causes many requests)
43 #subLangs="en.*,ja.*,id.*,es.*,zh-Hans.*,zh-Hant.*,sv.*,el.*,hi.*,ru.*,bn.*,fr.*,ko.*,ar.*,nv.*"; # custom language list
44 subLangs
="en,en-orig,en.*"; # custom language list
45 args
+=("--sub-langs" "$subLangs");
46 args
+=("--write-info-json"); # Write accompanying json file
47 args
+=("--no-overwrites"); # Don't overwrite files
48 args
+=("--write-thumbnail"); # Write thumbnail
50 ## Only download metadata
51 #args+=("--no-download"); # Don't download video file.
54 args
+=("--write-comments"); # Get comments
56 ### comment_sort values:
57 ### top : use YouTube top comment algorithm
58 ### new : get newest comments (default)
59 ### max_comments values:
60 ### max-comments : max number of parent comments or replies
61 ### max-parents : max number of comment threads
62 ### max-replies : max number of replies across all threads
63 ### max-replies-per-thread : max number of replies per thread
64 args
+=("--extractor-args" "youtube:comment_sort=top;max_comments=10000,100,10000,100");
66 ## Randomize order in which playlist items are downloaded
67 args
+=("--playlist-random");
69 ## Delay between downloads
71 maxSleep
="$(( minSleep + (RANDOM + RANDOM + RANDOM) / ( 3 * 400) ))"; # roughly 60 seconds
72 args
+=("--min-sleep-interval" "$minSleep");
73 args
+=("--max-sleep-interval" "$maxSleep");
74 args
+=("--sleep-requests" "2"); # delay on metadata requests
75 args
+=("--sleep-subtitles" "10"); # delay for subtitles
77 ## Remember downloaded videos to avoid redownload attempts
78 pathDA
="$dir_out"/.bkytpldl_history.txt
;
79 args
+=("--download-archive" "$pathDA");
81 ## Use firefox 'default-release' profile cookies
82 ## Example: Linux: from ~/.mozilla/firefox/deadbeef.default-release/
83 #args+=("--cookies-from-browser");
84 #args+=("firefox:deadbeef.default-release"); Default Firefox profile name
86 ## Specify output filename format
87 ## Note: `$(title).120B` shortens title to 120 bytes (useful for
88 ## titles with UTF-8 characters.
90 args
+=("%(playlist)s/%(upload_date)s.%(channel).32B.%(channel_id)s.%(title).120B.%(id)s.%(ext)s");
92 ## Limit download resolution to 1080p
93 args
+=("-S" "res:1080");
95 ## Specify playlist URLs to download
96 ### Shuffle playlist download order
97 mapfile
-t urls_rand
< <(printf "%s\n" "${urls[@]}" | shuf
);
98 for url
in "${urls_rand[@]}"; do
102 # Change working directory to output dir
103 pushd "$dir_out" || die
"FATAL:Failed to change pwd to:dir_out:$dir_out";
105 # == Download videos ==
107 #yell "DEBUG:args:$(declare -p args)"; # debug command
108 timeout
"$((1*24*3600))" yt-dlp
"${args[@]}";
109 popd || die
"FATAL:Failed to return from dir_out:$dir_out";
111 # Author: Steven Baltakatei Sandoval