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

June 28th, 2008 10:54
cool!
dimana ya cari binary wget untuk mac os x tiger (10.4.11)?
June 30th, 2008 10:15
haha keren banget nih idenya…
June 30th, 2008 13:51
@azmee - bisa coba install fink.

.
Setelah fink terpasang, buka terminal, lalu ketik apt-get install wget
.
Enak banget dengan fink, he he
.
@alva - thanks, maklum saya orangnya rada pemalas, he he.
Maunya serba otomatis saja
June 30th, 2008 22:42
Mas Harry,
Aku ga nemuin dimana harusnya aku properly contact anda (maksud saya, saya ga temukan email anda). Jadinya nyasar lewat sini. Siapa tahu sampai ke anda juga.
Ok nama saya Nalendra Wibowo, aku baru start new bisnis, namanya DCDA-Consulting Services (Data Center Design and Assessment Services), jadi purely lebih di physical infrastructure sidenya, bukan s/w atau aplikasi, who knows, suatu kali ur current or prospect client need my services.
Saya di bintaro juga, bintaro ngelit… anyway, please do response to me at nalendra.wibowo@gmail.com
Salam
July 1st, 2008 07:41
Terimakasih mas Nalendra, saya sudah kontak Anda via email.
July 1st, 2008 09:35
Selamat atas terbentuknya AOSI dan mas harry sebagai .. tim formaturnya …
Semoga Opensource di INdonesia terus berjaya dan menggeser Mi kocok
July 1st, 2008 11:58
@tintin - trims mas
sayang kalau inisiatif sebesar ini cuma untuk tujuan sekecil itu, he he.
.
Tujuannya sih bukan untuk menggeser Mi kocok lho
.
Harapan kita adalah kita bisa menjadikan Indonesia sebagai negara maju di bidang IT dengan memanfaatkan berbagai teknologi open source.
Maju secara teknologi dan dengan dampak ke bidang ekonominya juga (contoh: jadi pemasukan devisa dari luar negeri).
.
Mohon doa restunya. Terimakasih.
July 1st, 2008 16:13
asli keren bgt idenya
coba bisa ga ya datar ke link direktori secara otomatis hehehe….
August 17th, 2008 22:50
Keren banget neeh.. Sayang belum mudheng bahasa pemrograman crontab
September 30th, 2008 14:40
coba http://dibatam.com mas
web based, ada tambahan info link mp4-nya, durasi, ukuran file flv, ukuran mp4, dan 99% karya dalam negeri