ytdl.sh
· 1.2 KiB · Bash
Raw
#!/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
| 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 |