-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatchTranslateYouTubePlaylistWithTTS.sh
executable file
·123 lines (107 loc) · 4.2 KB
/
BatchTranslateYouTubePlaylistWithTTS.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
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
#!/bin/zsh
#================================================================================
# AUTHOR
# Clint Box
# https://www.youtube.com/bearcatjamboree
#
# FUNCTION
# Translate an entire YouTube video playlist
#
# DETAILS
# This script will download a playlist and use the id and title to construct
# calls to BatchTranslateYouTubeVideo.sh in order to facilitate migrating an entire
# playlist from one language to several other languages.
#
# USAGE
# ${SCRIPT_NAME} "<playlist URL>" "<output folder>"
#
# NOTE
# Spleeter is required for removing the vocals from the video. On M1, the
# following command is required to activate that environment:
#
# conda activate spleeter
#
# Also, its worth noting that there is currently an issue with the TTS breaking
# when this environment is activate, so it might be necessary to download
# and then remove the audio before doing other processing.
#
# More research is being done to try to get this fully functional
#================================================================================
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
echo "${machine}"
playlist_url="$1"
output_folder="$2"
##############################################################################
# Prompt for URL
###############################################################################
if [[ "$playlist_url" == "" ]]; then
if [[ "$machine" == "Mac" ]]; then
playlist_url=$(osascript -e 'set T to text returned of (display dialog "Enter video or playlist URL" buttons {"Cancel", "OK"} default button "OK" default answer "")')
elif [[ "$machine" == "Linux" ]]; then
playlist_url=$(dialog --title "Enter playlist location" --inputbox "URL:" 8 60)
elif [[ "$machine" == "Cygwin" ]]; then
playlist_url=$(dialog --title "Enter playlist location" --inputbox "URL:" 8 60)
else
echo "Usage: $0 playlist_url output_folder"
exit 1
fi
fi
if [[ "$playlist_url" == "" ]]; then
echo "Usage: $0 playlist_url output_folder"
exit 1
fi
##############################################################################
# Prompt for _output folder
###############################################################################
if ! [ -d "$output_folder" ]; then
if [[ "$machine" == "Mac" ]]; then
output_folder=$(osascript -e 'tell application (path to frontmost application as text)
set output_folder to choose folder with prompt "Please select _output folder:"
POSIX path of output_folder
end')
elif [[ "$machine" == "Linux" ]]; then
output_folder=$(dialog --title "Choose a folder" --stdout --title "Please select output folder:" --fselect ~/ 14 48)
elif [[ "$machine" == "Cygwin" ]]; then
output_folder=$(dialog --title "Choose a folder" --stdout --title "Please select output folder:" --fselect ~/ 14 48)
else
echo "Usage: $0 language playlist_url output_folder"
exit 1
fi
fi
if ! [ -d "$output_folder" ]; then
echo "Usage: $0 language playlist_url output_folder"
exit 1
fi
output_folder=${output_folder%/}
# download playlist info
youtube_data=$(yt-dlp --dump-json "$playlist_url" | jq -r '[.title,.id]|@csv')
# Read playlist info to array (lines)
i=0; lines=()
while IFS='' read -r value; do
lines+=("$value")
done <<< "$youtube_data"
for line in "${lines[@]}"
do
IFS="," read -r title id <<< "$line"
title=$(echo $title | sed 's/\"//g')
title=$(echo $title | sed 's/\#/\_/g')
title=$(echo $title | sed 's/\!//g')
id=$(echo $id | sed 's/\"//g')
url="https://www.youtube.com/watch?v=$id"
new_output_folder="$output_folder/$title"
new_output_folder=$(echo $new_output_folder | sed 's/ /\ /g')
if ! [ -d "$new_output_folder" ]; then
mkdir $new_output_folder
echo /bin/zsh ~/PycharmProjects/Video-Tools/BatchTranslateYouTubeVideoWithTTS.sh "$url" "$new_output_folder/"
/bin/zsh ~/PycharmProjects/Video-Tools/BatchTranslateYouTubeVideoWithTTS.sh "$url" "$new_output_folder/"
else
echo "Skipping $new_output_folder"
fi
done