Created
April 26, 2014 11:50
-
-
Save aswinanand/11318158 to your computer and use it in GitHub Desktop.
A simple script to get download URLs for movies from einthusan.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
#!/usr/bin/php | |
<?php | |
require('simple_html_dom.php'); | |
function erexit($msg = "You have entered an invalid choice. Bye.") { | |
echo $msg, "\n"; | |
exit; | |
} | |
function getURL($u) { | |
$c = curl_init($u); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($c, CURLOPT_MAXREDIRS, 5); | |
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042523 Ubuntu/8.10 (intrepid) Firefox/3.1.5"); | |
$text = curl_exec($c); | |
curl_close($c); | |
return $text; | |
} | |
function getMovies($u) { | |
$ret = array(); | |
$text = getURL($u); | |
$dom = str_get_html($text); | |
$lis = $dom->find('.search-category-wrapper-left li a'); | |
$cnt = count($lis) - 1; | |
for ($i=0; $i<$cnt; $i++) { | |
$ret[] = array($lis[$i]->plaintext, str_replace('..', 'http://www.einthusan.com', $lis[$i]->href)); | |
} | |
return $ret; | |
} | |
function getMP4($u) { | |
$text = getURL($u); | |
$dom = str_get_html($text); | |
$scripts = $dom->find('script'); | |
foreach ($scripts as $s) { | |
if (strpos($s->innertext, 'mp4') !== false) { | |
$mp4s = explode("'", $s->innertext); | |
return $mp4s[3]; | |
} | |
} | |
return false; | |
} | |
$lang = 0; $movie = ''; | |
$referer = "http://www.einthusan.com/"; | |
$search_url = "http://www.einthusan.com/search/?search_query=%s&lang=%s"; | |
echo "Choose language:\n 1. Tamil\n 2. Hindi\n 3. Telugu\n 4. Malayalam\nEnter your choice (1-4) : "; | |
fscanf(STDIN, "%d\n", $lang); | |
switch($lang) { | |
case 1: | |
$lang = 'tamil'; | |
break; | |
case 2: | |
$lang = 'hindi'; | |
break; | |
case 3: | |
$lang = 'telugu'; | |
break; | |
case 4: | |
$lang = 'malayalam'; | |
break; | |
default: | |
erexit(); | |
} | |
echo "\n"; | |
echo "Enter 1 or 2 words to search from the list of $lang movies: "; | |
fscanf(STDIN, "%s\n", $movie); | |
$movie = strip_tags($movie); | |
$url = sprintf($search_url, $movie, $lang) ; | |
$movies = getMovies($url); | |
echo "\n"; | |
if (count($movies) == 0) { | |
erexit('No movies are available with that name.'); | |
} | |
for ($i=0; $i<count($movies); $i++) { | |
echo ($i+1), ".\t", $movies[$i][0], "\n"; | |
} | |
echo "Enter your choice (1-", count($movies), ") : "; | |
fscanf(STDIN, "%d\n", $mid); | |
if ( empty($movies[$mid-1]) ) { | |
erexit(); | |
} | |
$mp4 = getMP4($movies[$mid-1][1]); | |
echo "Download {$movies[$mid-1][0]} from here: $mp4", "\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment