-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.sh
executable file
·122 lines (96 loc) · 2.85 KB
/
main.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
#!/usr/bin/env bash
resolution_heights=("1080" "720" "360")
default_resolution_height="1080"
input_dir="$(pwd)/go-vid"
output_dir="$(pwd)"
output_static_dir="videos"
output_content_dir="videos"
create() {
cd "$input_dir"
read -p "Title: " title
pub_date=$(date -Iseconds)
video=$(get_video)
slug=$(slugify "$title")
directory_name=$(get_directory_name "$slug")
mkdir "$directory_name"
cd "$directory_name"
cp "$video" "video.mp4"
echo "---" >> description.md
jq --null-input --arg title "$title" --arg date "$pub_date" '{"title": $title, "date": $date}' | yq -y >> description.md
echo "---" >> description.md
"$EDITOR" description.md
}
get_directory_name() {
discriminator=1
directory_name="${1}"
while [ -d "$directory_name" ];
do
discriminator=$((discriminator + 1))
directory_name="${1}__${discriminator}"
done
echo "$directory_name"
}
get_video() {
lf -selection-path /dev/stdout
}
transcode() {
slug="$1"
cd "$slug"
output_filename_start="$output_dir/static/$output_static_dir/$slug"
title_full=$(cat description.md | head -4 | yq -y .title)
title=$(echo "$title_full" | head -1)
echo "Transcoding \"$title\"."
for resolution_height in "${resolution_heights[@]}";
do
filename="${output_filename_start}_${resolution_height}p.mp4"
if [ -f "$filename" ];
then
echo "${resolution_height}p is already transcoded, skipping."
else
echo "Transcoding to ${resolution_height}."
ffmpeg -i "video.mp4" -filter:v scale=-1:"$resolution_height" -c:v h264_nvenc -c:a copy "$filename"
rm "${filename}.torrent" -f
mktorrent "$filename" -o "${filename}.torrent"
fi
done
cd ..
}
export() {
slug="$1"
cd "$slug"
filename="$output_dir/content/$output_content_dir/$slug.md"
cat description.md | head -n 4 > $filename
echo "<video src=\"/$output_static_dir/${slug}_${default_resolution_height}p.mp4\" style=\"width: 100%;\" controls=\"true\"></video>" >> $filename
echo "<div>" >> $filename
echo "<span> Downloads </span>" >> $filename
echo "<ul>" >> $filename
for resolution_height in "${resolution_heights[@]}";
do
echo "<li><a href=\"/$output_static_dir/${slug}_${resolution_height}p.mp4\" style=\"width: 100%;\" controls=\"true\">${resolution_height}p [Direct]</a></li>" >> $filename
echo "<li><a href=\"/$output_static_dir/${slug}_${resolution_height}p.mp4.torrent\" style=\"width: 100%;\" controls=\"true\">${resolution_height}p [Torrent]</a></li>" >> $filename
done
echo "</ul>" >> $filename
echo "</div>" >> $filename
cat description.md | tail -n +5 >> $filename
cd ..
}
if [ "$1" = "create" ];
then
create
elif [ "$1" = "transcode" ];
then
cd "$input_dir"
for video in *;
do
transcode "$video"
done
elif [ "$1" = "export" ];
then
rm "$output_dir/content/$output_content_dir" -rf
mkdir -p "$output_dir/content/$output_content_dir"
cd "$input_dir"
for video in *;
do
export "$video"
done
fi