Last active 1630622817

A script to launch a DO droplet in nyc3, download a video, and upload it somewhere with rclone, because geofencing sucks

ytdl.sh Raw
1#!/bin/bash
2
3PUB_URL="https://example.com/"
4REMOTE="remote:path/"
5
6cat >/tmp/cloud.conf <<EOFF
7#!/bin/bash
8apt-get update
9apt-get install python3-pip ffmpeg -y
10pip3 install youtube-dl
11curl https://rclone.org/install.sh 2>/dev/null | bash
12
13export ID=\$(curl http://169.254.169.254/metadata/v1/id 2>/dev/null)
14export URL="$1"
15
16mkdir -p /root/.config/rclone
17cat > /root/.config/rclone/rclone.conf <<EOF
18$(cat ~/.config/rclone/rclone.conf)
19EOF
20
21youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -o "%(id)s.%(ext)s" "\$URL"
22rclone copy *.mp4 $REMOTE
23
24echo "ALLDONE $PUB_URL"\$(ls *.mp4)
25killall tail
26curl -X DELETE -H "Authorization: Bearer $(grep access-token ~/.config/doctl/config.yaml | awk '{print $2}')" https://api.digitalocean.com/v2/droplets/\$ID
27EOFF
28read IP <<< $(set -x; doctl compute droplet create ytdl-$(date +%Y%m%d-%H%M%S) --region nyc3 --size s-1vcpu-1gb --image ubuntu-20-04-x64 --ssh-keys 31033111 --user-data-file /tmp/cloud.conf --droplet-agent=false --wait --no-header --format PublicIPv4)
29rm /tmp/cloud.conf
30until (ssh -o StrictHostKeyChecking=no root@$IP test -f /var/log/cloud-init-output.log); do
31 sleep 1
32done
33ssh -o StrictHostKeyChecking=no root@$IP tail -f /var/log/cloud-init-output.log