Last active
December 27, 2015 23:06
-
-
Save koenhendriks/e981d49901ff2277287a to your computer and use it in GitHub Desktop.
Pirate Bay Movie Fetcher
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 | |
/** | |
* Small little function to read out The Pirate Bay. | |
* This will look make a search on The Pirate Bay | |
* and return the first result it gets from the HD - Movies category | |
* | |
* Example: | |
* $magnetUrl = getMagnet('Fight Club', 'YIFY'); | |
* | |
* @author Koen Hendriks <info@koenhendriks.com> | |
* @date created on 22-03-14 | |
* | |
* @param string $param is the string to search for on The Pirate Bay. | |
* @param string $group is the string from your favorite release group. | |
* @return array $array with the Title of the Pirate Bay item and the Magnet URL | |
*/ | |
function getMagnet($param, $group = ''){ | |
/** | |
* PHP Simple HTML DOM Parser | |
* http://simplehtmldom.sourceforge.net/ | |
*/ | |
include('dom.php'); | |
/** | |
* Pirate bay doesn't like the & sign in their search queries. | |
* Let's remove that bastard. | |
*/ | |
$param = str_replace("&", "", $param); | |
/** | |
* Creating the link and making sure spaces are done the correct way. | |
* I'm adding my favorite distribution group here. | |
* Adding '0/7/207' means sorting descending on Seeders in the group HD - Movies, | |
* this way we always get the best seeded magnet. | |
*/ | |
$link = 'http://thepiratebay.am/search/'.urlencode($param).'+'.$group.'/0/7/207'; | |
$link = str_replace("+", "%20", $link); | |
//Let's get that html that needs parsing | |
$html = file_get_html($link); | |
//Loop trough the search results table on every table row (tr) for table data (td). | |
foreach ($html->find('table[id=searchResult] tr td') as $el) | |
{ | |
//Check if an element has a child with an href attribute (find the link) | |
if(isset($el->children(1)->href) && !is_null($el->children(1)->href)){ | |
//Retrieve the | |
$magnet = $el->children(1)->href; | |
return $magnet; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment