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
cool!
dimana ya cari binary wget untuk mac os x tiger (10.4.11)?
haha keren banget nih idenya…
@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 😉
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
Terimakasih mas Nalendra, saya sudah kontak Anda via email.
Selamat atas terbentuknya AOSI dan mas harry sebagai .. tim formaturnya … 🙂
Semoga Opensource di INdonesia terus berjaya dan menggeser Mi kocok 😀
@tintin – trims mas 🙂
.
Tujuannya sih bukan untuk menggeser Mi kocok lho 😉 sayang kalau inisiatif sebesar ini cuma untuk tujuan sekecil itu, he he.
.
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.
asli keren bgt idenya
coba bisa ga ya datar ke link direktori secara otomatis hehehe….
Keren banget neeh.. Sayang belum mudheng bahasa pemrograman crontab
coba http://dibatam.com mas
web based, ada tambahan info link mp4-nya, durasi, ukuran file flv, ukuran mp4, dan 99% karya dalam negeri
wah, informasinya bagus, nanti mau dicoba. salam kenal.
cool tutorial, thank’s for share
Nice article.The code works fine and is a good starting point for me making a custom module.Thanks for the module…
woooowww,, hebat..
kok ga bisa ya?? youtube-dl permission denied tu kenapa??
wah makasih nieh mas di coba dulu deh ya 🙂
wah sip nieh di coba dulu ya kang 😀
wah keren nieh 😀 coba dulu ah
mantab..
sip bozz tak coba dulu
very nice information and i hope this problem can early finished
Dowloand problem 🙁
Ref… plase.
It was informative to read the latest information
nice share sob..
keep writing
It is so lucky to read your blog,it is full of useful message.I wish we both can do better in the future.It great honour if you can visit our website,and give us some suggession.
artikelnya bagus sekali mas
This site to each di improves more! Congratulations for the site and keep thus!
sebuah jawaban yang tepat ketika saya berfikir dalam hati tentang masalah scrip, puyeng gan mikire, hehehe
The information is very helpful, thank you
pantangan makanan penderita epilepsi
Hello sufehmi.com webmaster, Keep up the good work!
Dear sufehmi.com administrator, You always provide great examples and case studies.
Hi sufehmi.com admin, Your posts are always well-formatted and easy to read.
Hi sufehmi.com owner, Thanks for the great post!
Hello sufehmi.com owner, Your posts are always insightful and valuable.
Dear sufehmi.com webmaster, You always provide great information and insights.
Hi sufehmi.com admin, Great post!
Dear sufehmi.com admin, Great job!
Dear sufehmi.com administrator, Your posts are always well-written and engaging.
To the sufehmi.com webmaster, Your posts are always well written and informative.
Dear sufehmi.com owner, Your posts are always well-timed and relevant.
Hello sufehmi.com owner, Your posts are always well-cited and reliable.
Hello sufehmi.com administrator, You always provide great examples and real-world applications, thank you for your valuable contributions.
Hi sufehmi.com owner, Thanks for the informative and well-written post!
To the sufehmi.com administrator, Excellent work!
Hello sufehmi.com administrator, Thanks for the well-organized and comprehensive post!
Dear sufehmi.com webmaster, Nice post!
Hi sufehmi.com owner, You always provide in-depth analysis and understanding.
Dear sufehmi.com webmaster, Your posts are always well-referenced and credible.
To the sufehmi.com webmaster, Keep sharing your knowledge!
Hi sufehmi.com admin, Your posts are always well-supported by facts and figures.
Dear sufehmi.com administrator, Your posts are always well-referenced and credible.
Hello sufehmi.com admin, Keep it up!