function addBitloadLink($url)
{
    $content = file_get_contents($url, false, getExplorerContext(getSiteHash()));
    $content = str_replace("\\", "", $content);
    if (preg_match_all("/http\\:\\/\\/www\\.mystream\\.to\\/file-(.*)-(.*)-(.*)\"/U", $content, $parts2, PREG_SET_ORDER)) {
        foreach ($parts2 as $part2) {
            $content = file_get_contents("http://www.bitload.com/f/" . $part2[1] . "/" . $part2[2] . "?m=def&c=free");
            //Get final file link
            preg_match_all("/{\"url\"\\:\"(.*)\"/U", $content, $newLink);
            if ($newLink) {
                $newLink = $newLink[1];
                $newLink = $newLink[0];
                return $newLink;
            }
        }
    } else {
        preg_match_all("/http\\:\\/\\/www\\.bitload\\.com\\/f\\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
        foreach ($parts as $part) {
            $content = file_get_contents("http://www.bitload.com/f/" . $part[1] . "?m=def&c=free");
            //Get final file link
            preg_match_all("/{\"url\"\\:\"(.*)\"/U", $content, $newLink);
            if ($newLink) {
                $newLink = $newLink[1];
                $newLink = $newLink[0];
                return $newLink;
            }
        }
    }
}
/**
 * Get number of pages and retrieve first page content.
 */
function getPages($url, $letter)
{
    $content = file_get_contents(getMovieListLink($url, $letter), false, getExplorerContext(getSiteHash()));
    //Get letter number of entries
    preg_match("/\"iTotalDisplayRecords\":\"(.*)\"/U", $content, $numberEntries);
    if ($numberEntries) {
        $numPages = ceil($numberEntries[1] / 25);
    } else {
        $numPages = 0;
    }
    $content = str_replace(array("\\u00e4", "\\u00eb", "\\u00ef", "\\u00f6", "\\u00fc", "\\u00c4", "\\u00cb", "\\u00cf", "\\u00d6", "\\u00dc", "\\u00df"), array("ä", "ë", "ï", "ö", "ü", "Ä", "Ë", "Ï", "Ö", "Ü", "ß"), $content);
    return array(utf8_decode($content), $numPages);
}
function addBitloadDivxLink($template, $url)
{
    $content = file_get_contents($url, false, getExplorerContext(getSiteHash()));
    $content = str_replace("\\", "", $content);
    if (preg_match_all("/http\\:\\/\\/www\\.mystream\\.to\\/file-(.*)-(.*)-(.*)\"/U", $content, $parts2, PREG_SET_ORDER)) {
        foreach ($parts2 as $part2) {
            $content = getHeadersDivx('http://www.bitload.com/d/' . $part2[1] . "/" . $part2[2] . '?m=def&c=free');
            preg_match("/Set-Cookie: PHPSESSID=(.*); path=\\//", $headers[4], $sessionid);
            $content = file_get_contents("http://www.bitload.com/d/" . $part2[1] . "/" . $part2[2] . "?m=def&c=free&PHPSESSID=" . $sessionid);
            //Get final file link
            preg_match_all("/var url = \\'(.*)\\'/U", $content, $newLink);
            if ($newLink) {
                $newLink = $newLink[1];
                $newLink = $newLink[0];
                $template->addMediaItem(substr($newLink, strrpos($newLink, "/") + 1), "", $newLink, "", VideoUtil::getEnclosureMimetype($newLink));
            }
        }
    } else {
        preg_match_all("/http\\:\\/\\/www\\.bitload\\.com\\/d\\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
        foreach ($parts as $part) {
            $content = getHeadersDivx('http://www.bitload.com/d/' . $part[1] . '?m=def&c=free');
            preg_match("/Set-Cookie: PHPSESSID=(.*); path=\\//", $headers[4], $sessionid);
            $content = file_get_contents("http://www.bitload.com/d/" . $part[1] . "?m=def&c=free&PHPSESSID=" . $sessionid);
            //var_dump($content);
            //Get final file link
            preg_match_all("/var url = \\'(.*)\\'/U", $content, $newLink);
            //var_dump($newLink);
            if ($newLink) {
                $newLink = $newLink[1];
                $newLink = $newLink[0];
                $template->addMediaItem(substr($newLink, strrpos($newLink, "/") + 1), "", $newLink, "", VideoUtil::getEnclosureMimetype($newLink));
            }
        }
    }
}