video.sh 1.14 KB
Newer Older
1
2
3
4
5
6
7
8
#!/bin/sh

######
## Generate video thumbnails
## Rubenerd Industries

SERVER="rubenerd.com"

9
THUMB="video.jpg"
10
11
12
13
14
PLAY1X="../metadata/play@1x.png"
PLAY2X="../metadata/play@2x.png"

## Download video thumbnail
VIDEO=`youtube-dl --get-thumb --no-warnings $1 | tail -1`
15
curl -Lo "$THUMB" "$VIDEO"
16
17
18
19
20
21
22
23
24
25
26
27
28

## Get video title
TITLE=`youtube-dl --get-title --no-warnings $1 | tail -1`

## Get video ID
ID=`echo $1 | awk -F= '{ print $2 }'`

## Get year for archive
YEAR=`date '+%Y'`

## Generate image URLs
## TODO: Make clipboard copy work on FreeBSD, not just macOS
FILE="https://rubenerd.com/files/$YEAR/yt-$ID"
29
HTML="<p><a href=\"$1\" title=\"Play $TITLE\"><img src=\"$FILE@1x.jpg\" srcset=\"$FILE@1x.jpg 1x, $FILE@2x.jpg 2x\" alt=\"Play $TITLE\" style=\"width:500px;height:281px;\" /></a></p>"
30
31
32
33
34
35
36
37
echo $HTML | pbcopy

## Create thumbnails
convert -resize 1000x563 "video.jpg" -quality 97 -crop 1000x562+0+0 +repage \
    +page "$PLAY2X" -flatten "yt-$ID@2x.jpg"
convert -resize 500x281 "video.jpg" -quality 97 "yt-$ID@1x.jpg" \
    +page "$PLAY1X" -flatten "yt-$ID@1x.jpg"

Ruben Schade's avatar
Ruben Schade committed
38
## Upload files and delete on success
39
scp yt-$ID@*jpg $SERVER:$YEAR/ && rm -rf yt-$ID@*jpg && rm -rf "$THUMB"
40