Last active
August 13, 2019 14:38
-
-
Save kamermans/4750995 to your computer and use it in GitHub Desktop.
Auto-downloader for Linux Journal ebooks. I set my download location to a directory that gets sync'd to my mobile devices (Dropbox, Box, SkyDrive, etc).
This file contains hidden or 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 | |
| // Account number goes here | |
| $account_num = 'LJ123456'; | |
| // Your ZIP code | |
| $zip = '12345'; | |
| // Path to eBooks | |
| $path = 'C:/eBooks/Linux Journal'; | |
| // eBook download format: pdf, epub, mobi | |
| $format = 'pdf'; | |
| $short_account_num = preg_replace('/^LJ/', '', $account_num); | |
| $dlpage = "https://secure2.linuxjournal.com/pdf/dljdownload.php?ucLJFooter_accountnumber=$short_account_num"; | |
| $dlpage_content = file_get_contents($dlpage); | |
| if (!$dlpage_content) { | |
| die("Unable to download Linux Journal issue list"); | |
| } | |
| preg_match_all('#http://download\.linuxjournal\.com/pdf/get-doc\.php\?code=\w*&tcode='.$format.'-(\d*)-\d*#', $dlpage_content, $matches, PREG_SET_ORDER); | |
| foreach ($matches as $match) { | |
| $url = $match[0]."&action=spit"; | |
| $issue = $match[1]; | |
| $file = "$path/lj-$issue.$format"; | |
| if (!file_exists($file)) { | |
| echo "Downloading issue $issue..."; | |
| file_put_contents($file, file_get_contents($url)); | |
| $size = filesize($file); | |
| echo "Done ($size bytes)\n"; | |
| } | |
| } | |
| echo "Done.\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment