Created
September 3, 2021 08:46
-
-
Save alyssadev/09915aa02711ef2ca8584c1c1781fdea to your computer and use it in GitHub Desktop.
A script to launch a DO droplet in nyc3, download a video, and upload it somewhere with rclone, because geofencing sucks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PUB_URL="https://example.com/" | |
REMOTE="remote:path/" | |
cat >/tmp/cloud.conf <<EOFF | |
#!/bin/bash | |
apt-get update | |
apt-get install python3-pip ffmpeg -y | |
pip3 install youtube-dl | |
curl https://rclone.org/install.sh 2>/dev/null | bash | |
export ID=\$(curl http://169.254.169.254/metadata/v1/id 2>/dev/null) | |
export URL="$1" | |
mkdir -p /root/.config/rclone | |
cat > /root/.config/rclone/rclone.conf <<EOF | |
$(cat ~/.config/rclone/rclone.conf) | |
EOF | |
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -o "%(id)s.%(ext)s" "\$URL" | |
rclone copy *.mp4 $REMOTE | |
echo "ALLDONE $PUB_URL"\$(ls *.mp4) | |
killall tail | |
curl -X DELETE -H "Authorization: Bearer $(grep access-token ~/.config/doctl/config.yaml | awk '{print $2}')" https://api.digitalocean.com/v2/droplets/\$ID | |
EOFF | |
read 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) | |
rm /tmp/cloud.conf | |
until (ssh -o StrictHostKeyChecking=no root@$IP test -f /var/log/cloud-init-output.log); do | |
sleep 1 | |
done | |
ssh -o StrictHostKeyChecking=no root@$IP tail -f /var/log/cloud-init-output.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment