This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtf2YoutubeDownloader
executable file
·112 lines (112 loc) · 5.4 KB
/
tf2YoutubeDownloader
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
#!/bin/bash
currDir=$PWD
filename=""
songDuration=""
shouldLoopback="$3"
#if [[ $2 == "[DG] The Alchemist" ]]; then echo "say \"[PikaDJ] Sorry $2, but you have been blocked from requesting songs!\"" >> ../"$modName"/cfg/stdin.cfg; exit 0; fi
#if [[ $2 == "Hun | My Sentry" ]]; then echo "say \"[PikaDJ] Sorry Hun | My Sentry, but you have been blocked from requesting songs!\"" >> ../"$modName"/cfg/stdin.cfg; exit 0; fi
#echo "say \"[PikaDJ] Sorry $2, but I am currently refusing requests, as I have to leave soon!\"" >> ../"$modName"/cfg/stdin.cfg
#exit 0
source ./utils
source ./tf2ConfigFileParser
if $ttsEnabled; then exit 0; fi
if ((maxQueueSize == 0)); then
echo "say \"[PikaDJ] Sorry $2, but I am currently refusing requests!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
elif ((maxQueueSize > 0)); then
lineCount=$(wc -l /tmp/PikaDJ/queue.tmp | cut -f1 -d' ')
if ((lineCount >= maxQueueSize)); then
echo "say \"[PikaDJ] Sorry $2, but I am currently refusing requests until the queue clears up. Try again later!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
fi
fi
#echo "say \"[PikaDJ] I am currently refusing requests, because I have to reload the script after this queue. Sorry!\"" >> ../"$modName"/cfg/stdin.cfg
#echo "say \"[PikaDJ] I am currently refusing requests, because I have to enable autoplay after this queue (so I can go AFK). Sorry!\"" >> ../"$modName"/cfg/stdin.cfg
#echo "say \"[PikaDJ] I am currently refusing requests. Sorry!\"" >> ../"$modName"/cfg/stdin.cfg
#exit 0
#filename=$(youtube-dl -o "%(title)s.%(ext)s" --get-filename "$1")
while read line; do
case $line in
{\"*\":\ *)
#echo "Metadata"
songDuration="$(echo "$line" | sed -e 's/.*"duration": \([0-9]*\).*/\1/')"
songDescription="$(echo "$line" | sed -e 's/\\.//g' -e 's/.*"description": "\([^"]*\)".*/\1/' -e 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')"
uploaderName="$(echo "$line" | sed -e 's/\\.//g' -e 's/.*"uploader": "\([^"]*\)".*/\1/' -e 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')"
uploaderID="$(echo "$line" | sed -e 's/\\.//g' -e 's/.*"uploader_id": "\([^"]*\)".*/\1/' -e 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')"
;;
*)
#echo "Other data"
title="$line"
filename="$line.wav"
;;
esac
done < <(youtube-dl -o "%(title)s" --no-playlist -j --get-filename --no-check-certificate "$1" 2>/dev/null)
if [[ $filename != "" ]]; then
for word in "${bannedWords[@]}"; do
if [[ $songDescription =~ $word ]] || [[ $uploaderName =~ $word ]] || [[ $uploaderID =~ $word ]] || [[ $(echo "$filename" | sed -e 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') =~ $word ]]; then
echo "$title is blocked by the filter $word! I can't play it!"
echo "say \"[PikaDJ] Sorry, but $title is blocked by my filter ($word), so I can't play it!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
fi
done
songDurationPrintable=$(printf %02d:%02d $(( songDuration / 60)) $(( songDuration % 60 )))
minSongLengthPrintable=$(printf %02d:%02d $(( minSongLength / 60)) $(( minSongLength % 60 )))
maxSongLengthPrintable=$(printf %02d:%02d $(( maxSongLength / 60)) $(( maxSongLength % 60 )))
#echo "Song duration: $songDurationPrintable"
if (( songDuration > maxSongLength )); then
echo "$title is more than $maxSongLengthPrintable! It is $songDurationPrintable"
echo "say \"[PikaDJ] $title is too long! Sorry!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
elif (( songDuration < minSongLength )); then
echo "$title is less than $minSongLengthPrintable! It is $songDurationPrintable"
echo "say \"[PikaDJ] $title is too short! Sorry!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
else
echo "$title is an acceptable length! It is $songDurationPrintable"
fi
cd ~/Music/youtubeRequests/
if [[ ! -f "fixedName/$filename" ]]; then
echo "say \"[PikaDJ] Preparing \"$title\"...\"" > "$currDir/../"$modName"/cfg/stdin.cfg"
xdotool type --window "$(xdotool search --class hl2_linux)" =
if [[ ! -f "$filename" ]]; then
youtube-dl -q -f "139/140/17/36/5" -x --audio-format "wav" --no-playlist --no-check-certificate -o "%(title)s.%(ext)s" "$1"
downloadStatus=$?
else
downloadStatus=0
fi
if [[ $downloadStatus == 0 ]]; then
cp -f "$filename" "fixedName/$filename"
cd fixedName
echo "$PWD/$filename" >> /tmp/PikaDJ/queue.tmp
cd "$currDir"
source ./tf2ConfigFileParser
if $autoplay; then
playSong &
fi
#echo "say \"[PikaDJ] $title has downloaded and is ready to play!\"" >> ../"$modName"/cfg/stdin.cfg
echo "$title is now ready to play!"
else
cd "$currDir"
echo "Youtube download failed!"
echo "say \"[PikaDJ] There was an error downloading $title! Try again later!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
fi
else
cd "$currDir"
echo "$title already exists in the playlist!"
echo "say \"[PikaDJ] $title is already in the playlist! Sorry!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
fi
else
echo "say \"[PikaDJ] Sorry $2, but there was an error getting the video info! Try again later!\"" > ../"$modName"/cfg/stdin.cfg
xdotool type --window "$(xdotool search --class hl2_linux)" =
exit 1
fi
exit 0