-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremotemediaresize.sh
203 lines (182 loc) · 4.65 KB
/
remotemediaresize.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# Remote Multimedia playback script for users with low bandwidth internet.
# Written by Minki in 2023. Feel free to share and modify.
# Client Dependencies: ffmpeg (with ffplay), ssh, dialog
# Server Dependencies: sshd, ffmpeg, yt-dlp
# PROCESSING SETTINGS:
# Video stream parameters
vStream="-vf scale=320:240 -r 8 -f matroska -c:v wmv1 -acodec libmp3lame -ac 1 -ar 44100"
# Audio stream parameters
aStream="-f mp3 -acodec libmp3lame -ac 1 -ar 44100"
# SSH Server login details (user@server.top)
sshLogin="mueller@muellers-software.org"
# Youtube-dl installation path
ytDlCmd="yt-dlp"
# Initial Values:
searchTerm=""
inputUrl=""
vBit="24"
aBit="24"
# FUNCTIONS:
setInputType () {
inputType=$(dialog --backtitle "Remote Media Resize Service" --menu "Input type?" 14 45 25 \
1 "URL" \
2 "YouTube URL" \
3 "YouTube Search" \
4 "Exit" \
3>&1 1>&2 2>&3
)
}
setMode () {
mode=$(dialog --backtitle "Remote Media Resize Service" --menu "Playback type?" 14 45 25 \
1 "Play Audio" \
2 "Play Video" \
3 "Download Audio" \
4 "Download Video" \
5 "Exit" \
3>&1 1>&2 2>&3
)
}
setAudioBitrate () {
aBit=$(dialog --backtitle "Remote Media Resize Service" \
--inputbox "Enter Audio Bitrate (in kbps) " 8 60 $aBit \
3>&1 1>&2 2>&3
)k
}
setVideoBitrate () {
vBit=$(dialog --backtitle "Remote Media Resize Service" \
--inputbox "Enter Video Bitrate (in kbps) " 8 60 $vBit \
3>&1 1>&2 2>&3
)k
}
setInputUrl () {
inputUrl=$(dialog --backtitle "Remote Media Resize Service" \
--inputbox "Enter URL " 8 60 \
3>&1 1>&2 2>&3
)
}
setSearchTerm () {
searchTerm=$(dialog --backtitle "Remote Media Resize Service" \
--inputbox "Enter search term " 8 60 \
3>&1 1>&2 2>&3
)
}
setSaveName () {
saveName=$(dialog --backtitle "Remote Media Resize Service" \
--inputbox "Save file as? " 8 60 \
3>&1 1>&2 2>&3
)
}
setQuery () {
query=$(dialog --backtitle "Remote Media Resize Service" \
--inputbox "Enter a search term " 8 60 \
3>&1 1>&2 2>&3
)
}
setFfArguments () {
case $mode in
1)
setAudioBitrate
ffArguments="$aStream -b:a $aBit "
;;
2)
setAudioBitrate
setVideoBitrate
ffArguments="$vStream -b:a $aBit -b:v $vBit"
;;
3)
setAudioBitrate
ffArguments="$aStream -b:a $aBit "
;;
4)
setAudioBitrate
setVideoBitrate
ffArguments="$vStream -b:a $aBit -b:v $vBit"
;;
5)
normalExit
;;
*)
abnormalExit
;;
esac
}
normalExit () {
echo "Interrupted by user."
exit 0
}
abnormalExit () {
echo "Exiting abnormally..."
exit 127
}
# MAIN LOOP:
# Intro screen:
echo ' ___ _ __ __ _ _ ___ _
| _ \___ _ __ ___| |_ ___| \/ |___ __| (_)__ _| _ \___ __(_)______
| / -_) " \/ _ \ _/ -_) |\/| / -_) _` | / _` | / -_|_-< |_ / -_)
|_|_\___|_|_|_\___/\__\___|_| |_\___\__,_|_\__,_|_|_\___/__/_/__\___|
Written by mueller_minki in 2023. Feel free to share and modify!'
sleep 1
clear
echo 'IMPORTANT! If you do not have SSH keys set up, you will have to enter your password on every rempote operation. If you are using the search feature, this might get annoying.'
sleep 1
setInputType # Query the user for what type of input they want to provide
case $inputType in
1) # URL
setInputUrl
urlInputType="URL"
setMode
setFfArguments
;;
2) # YouTube URL
setInputUrl
urlInputType="YT"
setMode
setFfArguments
;;
3) # YouTube Search
setSearchTerm
urlInputType="YT"
setMode
setFfArguments
;;
4)
normalExit
;;
*)
abnormalExit
;;
esac
if [ $mode -gt 2 ]
then # Mode 3 or 4 aka Download
setSaveName
if [ $urlInputType == "URL" ]
then
ssh $sshLogin "ffmpeg -re -i \"$inputUrl\" $ffArguments pipe:1" > $saveName
elif [ $urlInputType == "YT" ]
then
if [ $inputType == "3" ]
then
ssh $sshLogin "ffmpeg -re -i \$($ytDlCmd -q -f b -g \"ytsearch1:$inputUrl\" ) $ffArguments pipe:1" > $saveName
else
ssh $sshLogin "ffmpeg -re -i \$($ytDlCmd -q -f b -g \"$inputUrl\" ) $ffArguments pipe:1" > $saveName
fi
else
abnormalExit
fi
else # Mode 1 or 2 aka Play
if [ $urlInputType == "URL" ]
then
ssh $sshLogin "ffmpeg -re -i \"$inputUrl\" $ffArguments pipe:1" | ffplay -hide_banner -loglevel error -stats -
elif [ $urlInputType == "YT" ]
then
if [ $inputType == "3" ]
then
ssh $sshLogin "ffmpeg -re -i \$($ytDlCmd -q -f b -g ytsearch1:\"$searchTerm\" ) $ffArguments pipe:1" | ffplay -hide_banner -loglevel error -stats -
else
ssh $sshLogin "ffmpeg -re -i \$($ytDlCmd -q -f b -g \"$inputUrl\" ) $ffArguments pipe:1" | ffplay -hide_banner -loglevel error -stats -
fi
else
abnormalExit
fi
fi