-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
124 lines (124 loc) · 3.92 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
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
#!/bin/bash
if ! command -v zenity &> /dev/null
then
echo "Zenity isn't installed"
echo Install it now?
select yn in "Yes" "No"; do
case $yn in
Yes )
if [ -x "$(command -v apk)" ]; then sudo apk add --no-cache zenity
elif [ -x "$(command -v apt-get)" ]; then sudo apt-get install zenity
elif [ -x "$(command -v dnf)" ]; then sudo dnf install zenity
elif [ -x "$(command -v zypper)" ]; then sudo zypper install zenity
elif [ -x "$(command -v pacman)" ]; then sudo pacman -S zenity
else echo "Package manager not found. You must manually install zenity."; exit
fi
break;;
No ) exit;;
esac
done
fi
if ! command -v ffmpeg &> /dev/null
then
zenity --error --text="FFmpeg isn't installed"
if zenity --question --text="Install FFmpeg now?"
then
if [ -x "$(command -v apk)" ]; then sudo apk add --no-cache ffmpeg
elif [ -x "$(command -v apt-get)" ]; then sudo apt-get install ffmpeg
elif [ -x "$(command -v dnf)" ]; then sudo dnf install ffmpeg
elif [ -x "$(command -v zypper)" ]; then sudo zypper install ffmpeg
elif [ -x "$(command -v pacman)" ]; then sudo pacman -S ffmpeg
else zenity --error --text="Package manager not found. You must manually install FFmpeg."; exit
fi
else
exit
fi
fi
SOURCE_OPTION=$(zenity --list --title="Select source" --text="Select source" --column="source" --hide-header YouTube \File)
if [ -z "$SOURCE_OPTION" ]; then
exit
fi
case $SOURCE_OPTION in
YouTube )
YTURL=$(zenity --entry --title="YouTube URL" --text="Enter the URL of the YouTube video")
OTHERFILENAME=$(zenity --file-selection --save --title="Save the file as..." --file-filter="*.mp4")
if [[ $OTHERFILENAME != *.mp4 ]]; then
OTHERFILENAME="$OTHERFILENAME.mp4"
fi
if [ -z "$OTHERFILENAME" ]; then
exit
fi
;;
File )
FILENAME=$(zenity --file-selection --title="Select a video file")
if [ -z "$FILENAME" ]; then
exit
fi
OTHERFILENAME=$(zenity --file-selection --save --title="Save the file as..." --file-filter="*.mp4")
if [ -z "$OTHERFILENAME" ]; then
exit
fi
if [[ $OTHERFILENAME != *.mp4 ]]; then
OTHERFILENAME="$OTHERFILENAME.mp4"
fi
;;
esac
ASPECT_OPTION=$(zenity --list --title="Select aspect ratio" --text="Select aspect ratio" --column="Aspect Ratio" --column="Resolution" 16:9 426x240 \4:3 320x240 \5:3 400x240)
if [ -z "$ASPECT_OPTION" ]; then
exit
fi
case $ASPECT_OPTION in
4:3 )
ASPECT_RES=320x240
;;
16:9 )
ASPECT_RES=426x240
;;
5:3 )
ASPECT_RES=400x240
;;
esac
echo Select 3DS type.
DS_TYPE=$(zenity --list --title="Select 3DS type" --text="Select 3DS type" --column="type" --hide-header New \Old)
if [ -z "$DS_TYPE" ]; then
exit
fi
case $DS_TYPE in
Old )
QUALITY=15
;;
New )
QUALITY=1
;;
esac
if [ $SOURCE_OPTION = YouTube ]; then
if [ ! -f yt-dlp ]; then
echo Downloading yt-dlp
wget --progress=bar:force https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp 2>&1 | zenity --title="Downloading yt-dlp" --text="Downloading yt-dlp" --progress --auto-close --auto-kill
chmod a+rx yt-dlp
fi
echo Downloading video
if [ $DS_TYPE = old ]; then
./yt-dlp -o "%(id)s.%(ext)s" $YTURL --progress --newline -f 'bestvideo[height<=240]+bestaudio/best[height<=240]'
else
./yt-dlp -o "%(id)s.%(ext)s" $YTURL
fi
FILENAME=$(./yt-dlp --get-filename -o "%(id)s.%(ext)s" $YTURL)
fi
echo Getting frame rate...
FRAME_RATE=$(ffmpeg -i "$FILENAME" 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p")
if [ $DS_TYPE = Old ]; then
if [[ FRAME_RATE > 30 ]]; then
echo "Framerate will be 30"
FRAME_RATE=30
fi
fi
echo Converting...
ffmpeg -i "$FILENAME" -acodec aac -vcodec mpeg1video -s $ASPECT_RES -r $FRAME_RATE -q:v $QUALITY "$OTHERFILENAME"
if [ $SOURCE_OPTION = YouTube ]; then
rm "$FILENAME"
fi
if command -v notify-send &> /dev/null
then
notify-send "Finished converting video"
fi