-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·60 lines (47 loc) · 1.49 KB
/
script.sh
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
#!/bin/bash
# Download video from Wistia
# Usage: bash script.sh <quality> <topic>
# Example: bash script.sh 1080p "Data Structures and Algorithms"
# Check if the user has provided the quality and topic
if [ $# -ne 2 ]; then
echo "Usage: bash script.sh <quality> <topic>"
exit 1
fi
# Check if topic contains spaces, if contains spaces, replace it with underscore
if echo "$2" | grep -q ' '; then
topic=$(echo $2 | tr ' ' '_')
else
topic=$2
fi
quality=$1
target_dir="$HOME/Downloads/$topic"
if [ ! -d "$target_dir" ]; then
mkdir -p "$target_dir"
fi
# Get the video ID from target.txt
video_ids=$(cat target.txt)
count=1
for video_id in $video_ids
do
json=$(curl -s "https://fast.wistia.net/embed/medias/$video_id.json")
# Get title of the video
title=$(echo $json | jq '.media.name' | cut -d "/" -f 4 | tr -d '"' | cut -d "_" -f 2- | sed -E 's/(\.mp4|\.mov)//g')
echo "Downloading video: $title"
file_name="${count}_${title}.mp4"
if [ -f "$target_dir/$file_name" ]; then
echo -e "\e[33mVideo already exists\e[0m\n"
count=$((count+1))
continue
fi
# Download the video
echo $json \
| jq '[.media.assets[] | select(.display_name == "'$quality'").url] | first' \
| sed 's/bin/mp4/' \
| xargs curl -s --output "$target_dir/$file_name"
if [ $? -eq 0 ]; then
echo -e "\e[32mVideo downloaded successfully\e[0m\n"
else
echo -e "\e[31mFailed to download the video\e[0m\n"
fi
count=$((count+1))
done