-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-webseries
executable file
·157 lines (142 loc) · 3.98 KB
/
get-webseries
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# SPDX-FileCopyrightText: 2020 - 2024 sudorook <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
set -eu
ROOT="$(dirname "${0}")"
source "${ROOT}"/globals
function print_usage {
show_header "Usage: get-webseries"
show_listitem "\
-a|--after only get files from after given date
-b|--before only get files from before given date
-d|--destination location for output directory
-n|--name name of output directory
-r|--resolution video resolution (e.g. 1080p)
-s|--start playlist index number to start downloading
-u|--url playlist URL
-x|--extract_audio extract audio (mp3) from files
-h|--help print (this) help message"
}
YTDL=yt-dlp
VIDEODIR="${videodir:-"$(pwd)"}"
! check_command "${YTDL}" && exit 3
OPTIONS=a:b:d:hn:r:s:u:x
LONGOPTIONS=after:,before:,destination:,help,name:,resolution:,start:,url:,extract_audio
PARSED=$(getopt -o "${OPTIONS}" --long "${LONGOPTIONS}" -n "${0}" -- "${@}")
eval set -- "${PARSED}"
while [ ${#} -ge 1 ]; do
case "${1}" in
-a | --after)
DATEAFTER="${2}"
shift 2
;;
-b | --before)
DATEBEFORE="${2}"
shift 2
;;
-d | --destination)
VIDEODIR="${2}"
shift 2
;;
-h | --help)
print_usage
exit
;;
-n | --name)
NAME="${2}"
shift 2
;;
-r | --resolution)
RESOLUTION="${2/[pi]/}"
shift 2
;;
-s | --start)
START="${2}"
shift 2
;;
-u | --url)
URL="${2}"
shift 2
;;
-x | --extract_audio)
EXTRACTAUDIO=true
shift
;;
--)
shift
break
;;
*)
show_error "ERROR: unknown command line option ${2@Q}."
exit 3
;;
esac
done
# Prompt for inputs if they were not already specified on the command line.
if ! [[ -v URL ]]; then
URL=$(ask_question "What is the URL?")
fi
RESOLUTION="${RESOLUTION:-720}"
case "${RESOLUTION,,}" in
480p | 480i | 480)
HEIGHT=500
WIDTH=900
;;
720p | 720i | 720)
HEIGHT=800
WIDTH=1300
;;
1080p | 1080i | 1080)
HEIGHT=1200
WIDTH=2000
;;
*)
HEIGHT=800
WIDTH=1300
show_warning "WARNING: ${RESOLUTION@Q} not supported. Defaulting to 720p."
;;
esac
mkdir -p "${VIDEODIR}"
cd "${VIDEODIR}"
if [[ "${URL}" =~ playlist ]]; then
TEMPLATESTRING='%(playlist_uploader)s/%(playlist_title)s'
else
TEMPLATESTRING='%(channel)s'
fi
if "${EXTRACTAUDIO:-false}"; then
FORMATSTRING="bestaudio/best"
else
FORMATSTRING="bestvideo[vcodec!~='vp0?9'][ext=mp4][width<${WIDTH}][height<=${HEIGHT}]+bestaudio[ext=m4a]/bestvideo[ext=webm][width<${WIDTH}][height<=${HEIGHT}]+bestaudio[ext=webm]/bestvideo[width<${WIDTH}][height<=${HEIGHT}]+bestaudio/best[width<${WIDTH}][height<=${HEIGHT}]/best"
fi
"${YTDL}" "${URL}" \
--embed-thumbnail \
--embed-subs \
--convert-subs srt \
--sub-langs all,-live_chat \
--embed-metadata \
--embed-chapters \
--prefer-free-formats \
--trim-filenames 200 \
${DATEBEFORE:+--datebefore "${DATEBEFORE}"} \
${DATEAFTER:+--dateafter "${DATEAFTER}"} \
${EXTRACTAUDIO:+--extract-audio} \
${START:+--playlist-start "${START}"} \
--download-archive "${NAME:+${NAME}/}".archive.txt \
-f "${FORMATSTRING}" \
-o "${NAME:-"${TEMPLATESTRING}"}/%(release_date,upload_date)d %(title)s [%(id)s].%(ext)s" \
--ignore-errors \
--ignore-config