Created
October 3, 2011 15:02
-
-
Save and1truong/1259302 to your computer and use it in GitHub Desktop.
Download Vietnamese Audio Bible from VietChristian.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP script to download Vietnamese audio Bible from VietChristian.com website. | |
* | |
* Make bible directory, change to that new one, save this script as download-vietnamese-audio-bible.php | |
* to that directory as | |
* Run the script: | |
* php ./download-vietnamese-audio-bible.php | |
* | |
* by Andy Truong at <xeko.vn> | |
*/ | |
# Download index file | |
$cmd = 'wget "http://www.vietchristian.com/kinhthanh/gospelm.asp?bk1=0&no1=1&bk2=65&no2=22" -O index'; | |
exec($cmd); | |
# Read url and download | |
$urls = file('./index'); | |
$b = 0; | |
$last_book = ''; | |
foreach ($urls as $url) { | |
$url = trim($url, "\n\r\s\t"); | |
# get book-number, chapter number | |
$name = basename($url); | |
$c = preg_replace('/.+[a-zA-Z]([0-9]+)\.mp3$/', '$1', $name); | |
$book = str_replace("$c.mp3", '', $name); | |
if ($last_book !== $book) { | |
$last_book = $book; | |
$b++; | |
} | |
$output = '%s__%s.mp3'; | |
$output = sprintf($output, str_pad($b, 3, '0', STR_PAD_LEFT), str_pad($c, 3, '0', STR_PAD_LEFT)); | |
if (!is_file($output)) { | |
exec("wget $url -O $output \n"); | |
} | |
} | |
# remove index file | |
exec('rm ./index'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment