Translate this page :

Youtube Auto Download Script

My daughter is tracking some movie episodes in Youtube, but download speed is rather slow on peak hours.

So I made the following script, which, when scheduled with crontab in Linux, will automatically download the episodes automatically in off peak hours. It’s much faster this way, and she’s happy now 🙂

The script is also heavily commented, it covers most of the basic features in shell / Unix / bash scripting. I figure those still new in Unix scripting will find it useful, so I’m sharing it here.

Back to the script — It’s very easy in her part – (1) she just need to paste the Youtube URLs into /home/myuser/Desktop/download-list.txt
(2) And every morning she need to delete the URLs, which have been downloaded, from it — unfortunately, this is necessary since Youtube doesn’t allow us to resume downloads.
But basically that’s all that she needs to do.

Here’s how the crontab looks like :

58 23 * * * /master/scripts/download-otomatis.sh
1 6 * * * pkill -f download-otomatis
3 6 * * * killall wget

The script will be executed every day at 23:58.
Then to kill the script, we’ll need the next 2 lines, which will be executed at 06:01 and 06:03 respectively.

Voila – a happier daughter 🙂

Here’s the script :

#!/bin/bash

### Youtube Auto Download
### v1.03

### Requires : youtube-dl script
### http://www.arrakis.es/~rggi3/youtube-dl/

### -------------------------- Global variables
### change as necessary
YOUTUBE_SCRIPT=/master/scripts/youtube-dl
DL_FILE=/home/myuser/Desktop/download-list.txt
DL_LOC=/master/NewDownloads/
### ------------------------- stop changing here

## ganti direktori
cd $DL_LOC

## cari tahu jumlah baris
JML_BARIS=`cat $DL_FILE | wc -l`

CTR=1

## jika belum akhir file, proses setiap baris pada $DL_FILE
while [ $JML_BARIS -ge $CTR ]
do

### ambil satu baris dari file
URL_YOUTUBE=`cat $DL_FILE | sed $CTR'q;d'`
echo $URL_YOUTUBE


### dapatkan link untuk download
URL_DL2=`$YOUTUBE_SCRIPT -g2 "$URL_YOUTUBE"`

### baris pertama adalah nama file (lalu tambahkan extension FLV)
NAMA_FILE=`echo "$URL_DL2" | sed 1'q;d'`
NAMA_FILE=$DL_LOC${NAMA_FILE}.FLV
### baris kedua adalah URL_DL
URL_DL=`echo "$URL_DL2" | sed 2'q;d'`

### cek apakah $URL_DL kosong?
## jika ya, maka berarti ada error (url download tidak berhasil didapatkan)
if [ -z "$URL_DL" ]; then
echo ==== ada error ! ====
else

## OK !! download videonya sekarang !
wget -O "$NAMA_FILE" -c "$URL_DL"

fi

CTR=$((CTR+1))

done

exit 0

29 Responses to “Youtube Auto Download Script

Leave a Reply

 

Subscribe without commenting

            








SEObox: Web Hosting Murah Unlimited Komik Indonesia Homeschooling Indonesia