-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyt-dlp-auto.sh
More file actions
187 lines (172 loc) · 9.09 KB
/
Copy pathyt-dlp-auto.sh
File metadata and controls
187 lines (172 loc) · 9.09 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# YouTube Download Script
# Purpose: This script facilitates downloading YouTube videos using yt-dlp, a powerful command-line program.
# Author: ComplexOrganizations
# Repository: https://github.com/complexorganizations/youtube-download-script
# Usage Instructions:
# 1. System Requirements: Ensure you have "curl" and "brew" installed on your system. This script is compatible with most Linux distributions, and MacOS.
# 2. Downloading the Script:
# - Use the following command to download the script:
# curl https://raw.githubusercontent.com/complexorganizations/youtube-download-script/main/yt-dlp-auto.sh -o yt-dlp-auto.sh
# 3. Making the Script Executable:
# - Grant execution permissions to the script:
# chmod +x yt-dlp-auto.sh
# 4. Running the Script:
# - Prepare a file with YouTube video URLs, one URL per line.
# - Execute the script and provide the file path as an argument:
# sudo bash yt-dlp-auto.sh
# 5. Follow the on-screen instructions to complete the download process for each video in the list.
# Troubleshooting:
# - If you encounter issues, ensure your system is up-to-date and retry the operation.
# - For specific errors, refer to the "Troubleshooting" section in the repository's documentation.
# Contributing:
# - Contributions to the script are welcome. Please follow the contributing guidelines in the repository.
# Contact Information:
# - For support, feature requests, or bug reports, please open an issue on the GitHub repository.
# License: MIT License
# Note: This script is provided "as is", without warranty of any kind. The user is responsible for understanding the operations and risks involved.
# Check if the script is running as root
function check_root() {
if [ "$(id -u)" -ne 0 ]; then
echo "Error: This script requires root privileges to execute. Please run it with administrative permissions in order to proceed."
exit
fi
}
# Call the function to check root privileges
check_root
# Check the current running OS.
function check-current-operatingsystem() {
# Check if your running OS is Linux or macOS
if [ -f /etc/os-release ]; then
# If /etc/os-release file is present, source it to obtain system details
# shellcheck source=/dev/null
source /etc/os-release
CURRENT_DISTRO=${ID} # CURRENT_DISTRO holds the system's ID
fi
}
# Check the current running OS
check-current-operatingsystem
# Define a function to check system requirements
function installing-system-requirements() {
# Check if the current Linux distribution is supported
if { [ "${CURRENT_DISTRO}" == "ubuntu" ] || [ "${CURRENT_DISTRO}" == "debian" ] || [ "${CURRENT_DISTRO}" == "raspbian" ] || [ "${CURRENT_DISTRO}" == "pop" ] || [ "${CURRENT_DISTRO}" == "kali" ] || [ "${CURRENT_DISTRO}" == "linuxmint" ] || [ "${CURRENT_DISTRO}" == "neon" ] || [ "${CURRENT_DISTRO}" == "fedora" ] || [ "${CURRENT_DISTRO}" == "centos" ] || [ "${CURRENT_DISTRO}" == "rhel" ] || [ "${CURRENT_DISTRO}" == "almalinux" ] || [ "${CURRENT_DISTRO}" == "rocky" ] || [ "${CURRENT_DISTRO}" == "arch" ] || [ "${CURRENT_DISTRO}" == "archarm" ] || [ "${CURRENT_DISTRO}" == "manjaro" ] || [ "${CURRENT_DISTRO}" == "alpine" ] || [ "${CURRENT_DISTRO}" == "freebsd" ] || [ "${CURRENT_DISTRO}" == "ol" ] || [ "$(uname -s)" == "Darwin" ]; }; then
# Check if required packages are already installed
if { [ ! -x "$(command -v curl)" ] || [ ! -x "$(command -v brew)" ] || [ ! -x "$(command -v yt-dlp)" ] || [ ! -x "$(command -v ffmpeg)" ] || [ ! -x "$(command -v ffprobe)" ] || [ ! -x "$(command -v date)" ] || [ ! -x "$(command -v fdupes)" ]; }; then
# Install required packages depending on the Linux distribution
if { [ "${CURRENT_DISTRO}" == "ubuntu" ] || [ "${CURRENT_DISTRO}" == "debian" ] || [ "${CURRENT_DISTRO}" == "raspbian" ] || [ "${CURRENT_DISTRO}" == "pop" ] || [ "${CURRENT_DISTRO}" == "kali" ] || [ "${CURRENT_DISTRO}" == "linuxmint" ] || [ "${CURRENT_DISTRO}" == "neon" ]; }; then
apt-get update
apt-get install build-essential procps curl file git gcc -y
elif { [ "${CURRENT_DISTRO}" == "fedora" ] || [ "${CURRENT_DISTRO}" == "centos" ] || [ "${CURRENT_DISTRO}" == "rhel" ] || [ "${CURRENT_DISTRO}" == "almalinux" ] || [ "${CURRENT_DISTRO}" == "rocky" ]; }; then
yum check-update
yum groupinstall "Development Tools" -y
yum install procps-ng curl file git gcc -y
elif { [ "${CURRENT_DISTRO}" == "arch" ] || [ "${CURRENT_DISTRO}" == "archarm" ] || [ "${CURRENT_DISTRO}" == "manjaro" ]; }; then
pacman -Sy --noconfirm base-devel procps-ng curl file git gcc
elif [ "${CURRENT_DISTRO}" == "alpine" ]; then
apk update
apk add curl coreutils procps file git gcc
elif [ "${CURRENT_DISTRO}" == "freebsd" ]; then
pkg update
pkg install curl coreutils procps file git gcc -y
elif [ "${CURRENT_DISTRO}" == "ol" ]; then
yum check-update
yum install curl coreutils procps-ng file git gcc -y
fi
fi
if [ ! -x "$(command -v brew)" ]; then
# Install Homebrew on macOS
/usr/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add Homebrew to the PATH
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /root/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
if [ ! -x "$(command -v yt-dlp)" ]; then
brew install yt-dlp
fi
if [ ! -x "$(command -v ffmpeg)" ]; then
brew install ffmpeg
fi
if [ ! -x "$(command -v fprobe)" ]; then
brew install fprobe
fi
if [ ! -x "$(command -v date)" ]; then
brew install coreutils
fi
if [ ! -x "$(command -v fdupes)" ]; then
brew install fdupes
fi
else
echo "Error: Your current distribution ${CURRENT_DISTRO} is not supported by this script. Please consider updating your distribution or using a supported one."
exit
fi
}
# Call the function to check for system requirements and install necessary packages if needed
installing-system-requirements
# Scrape and download
function scrape-download() {
# Function to generate current timestamp
function generate_timestamp() {
date +"%Y-%m-%d_%H-%M-%S"
}
# Create a temporary directory to store downloaded content
mkdir -p "video-$(generate_timestamp)"
# mkdir -p "audio-$(generate_timestamp)"
# Create a variable to store the temporary directory path
local video_dir="video-$(generate_timestamp)"
local audio_dir="audio-$(generate_timestamp)"
# List of YouTube video URLs
local YouTubeURL=(
"https://www.youtube.com/watch?v=FUKmyRLOlAA"
"https://www.youtube.com/watch?v=yXkIHyBfns8"
"https://www.youtube.com/watch?v=bj1JRuyYeco"
)
# Remove duplicates from the list
YouTubeURL=($(echo "${YouTubeURL[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
# Download videos concurrently
for url in "${YouTubeURL[@]}"; do
# Extract the title from the youtube video and save that into a variable.
YouTubeTitle=$(yt-dlp --get-title "$url" | sed 's/[\/:*?"<>|]/_/g; s/^[[:space:]]*//; s/[[:space:]]*$//; s/[[:space:]]/_/g; s/[^a-zA-Z0-9_]/_/g; s/__/_/g; s/_\{2,\}/_/g; s/^_//; s/_$//')
# Extract video and audio concurrently
yt-dlp -f "bestvideo[height=720]+bestaudio/best[height=720]" --output "$video_dir/${YouTubeTitle}.%(ext)s" "$url" >>"$video_dir/$YouTubeTitle.log" 2>&1 &
# Alternatively, download audio only (uncomment if needed)
# yt-dlp -f "bestvideo[height=720]+bestaudio/best[height=720]" --extract-audio --audio-format mp3 --output "$audio_dir/${YouTubeTitle}.%(ext)s" "$url" & >> "$audio_dir/$YouTubeTitle.log" 2>&1 &
done
# Wait for all downloads to complete
wait
# Remove the empty temporary directory, if no files are present
if [ -d "$video_dir" ]; then
if [ -z "$(ls -A $video_dir)" ]; then
rm -rf "$video_dir"
fi
fi
if [ -d "$audio_dir" ]; then
if [ -z "$(ls -A $audio_dir)" ]; then
rm -rf "$audio_dir"
fi
fi
# Fix the permission for the downloaded files
if [ -d "$video_dir" ]; then
chmod -R 777 "$video_dir"
fi
if [ -d "$audio_dir" ]; then
chmod -R 777 "$audio_dir"
fi
# Go though the downloaded content and remove duplicates
if [ -d "$video_dir" ]; then
fdupes -rNdS "$video_dir"
fi
if [ -d "$audio_dir" ]; then
fdupes -rNdS "$audio_dir"
fi
# Go though the logs and remove it since, everything went well.
if [ -d "$video_dir" ]; then
find "$video_dir" -type f -name "*.log" -delete
fi
if [ -d "$audio_dir" ]; then
find "$audio_dir" -type f -name "*.log" -delete
fi
# Print message when all videos are downloaded
echo "Successful: All the content has been saved locally after downloading it from the internet."
}
# Scrape and download
scrape-download