Alyssa Smith revised this gist . Go to revision
1 file changed, 33 insertions
ytdl.sh(file created)
| @@ -0,0 +1,33 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | PUB_URL="https://example.com/" | |
| 4 | + | REMOTE="remote:path/" | |
| 5 | + | ||
| 6 | + | cat >/tmp/cloud.conf <<EOFF | |
| 7 | + | #!/bin/bash | |
| 8 | + | apt-get update | |
| 9 | + | apt-get install python3-pip ffmpeg -y | |
| 10 | + | pip3 install youtube-dl | |
| 11 | + | curl https://rclone.org/install.sh 2>/dev/null | bash | |
| 12 | + | ||
| 13 | + | export ID=\$(curl http://169.254.169.254/metadata/v1/id 2>/dev/null) | |
| 14 | + | export URL="$1" | |
| 15 | + | ||
| 16 | + | mkdir -p /root/.config/rclone | |
| 17 | + | cat > /root/.config/rclone/rclone.conf <<EOF | |
| 18 | + | $(cat ~/.config/rclone/rclone.conf) | |
| 19 | + | EOF | |
| 20 | + | ||
| 21 | + | youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' -o "%(id)s.%(ext)s" "\$URL" | |
| 22 | + | rclone copy *.mp4 $REMOTE | |
| 23 | + | ||
| 24 | + | echo "ALLDONE $PUB_URL"\$(ls *.mp4) | |
| 25 | + | killall tail | |
| 26 | + | curl -X DELETE -H "Authorization: Bearer $(grep access-token ~/.config/doctl/config.yaml | awk '{print $2}')" https://api.digitalocean.com/v2/droplets/\$ID | |
| 27 | + | EOFF | |
| 28 | + | 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) | |
| 29 | + | rm /tmp/cloud.conf | |
| 30 | + | until (ssh -o StrictHostKeyChecking=no root@$IP test -f /var/log/cloud-init-output.log); do | |
| 31 | + | sleep 1 | |
| 32 | + | done | |
| 33 | + | ssh -o StrictHostKeyChecking=no root@$IP tail -f /var/log/cloud-init-output.log | |
Newer
Older