Skip to content

Instantly share code, notes, and snippets.

@Gargaj
Last active August 31, 2015 12:32
Show Gist options
  • Save Gargaj/e07eee794a56d074dec1 to your computer and use it in GitHub Desktop.
Save Gargaj/e07eee794a56d074dec1 to your computer and use it in GitHub Desktop.
Automatic downloading and sorting script for Partymeister 2 download pages
<?php
include_once("simple_html_dom.php"); // http://simplehtmldom.sourceforge.net
set_time_limit(0);
$rootURL = "http://chaosconstructions.ru/";
$mainURL = $rootURL . "en/results";
$html = file_get_html($mainURL);
function sanitize($compoName)
{
$compoName = strtolower($compoName);
$compoName = preg_replace("/[^0-9a-z\.\-]+/","_",$compoName);
return $compoName;
}
// Find all images
foreach($html->find('.sidebar ul.nav a') as $element)
{
$compoURL = $element->href;
if (strstr($compoURL,"://")===false)
$compoURL = $rootURL . $compoURL;
echo "\n".$compoURL."\n";
$compoHTML = file_get_html($compoURL);
$compoName = $compoHTML->find(".releases h2",0)->plaintext;
$compoName = sanitize($compoName);
echo $compoName."\n";
foreach($compoHTML->find('.releases .row .caption a') as $link)
{
$fileURL = $link->href;
if (strstr($fileURL,"://")===false)
$fileURL = $rootURL . $fileURL;
echo $fileURL;
$data = file_get_contents($fileURL);
$filename = "dummy.txt";
foreach($http_response_header as $v)
if(preg_match('/Content-Disposition:.*filename=([^\r\n]+)/', $v, $matches))
$filename = trim($matches[1],"'\"");
$final = $compoName . "/" . sanitize($filename);
echo " - " . $final . " (".strlen($data).")\n";
@mkdir($compoName);
file_put_contents( $final, $data );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment