All pastes #2012566 Raw Edit

Anonymous

public php v1 · immutable
#2012566 ·published 2010-12-07 04:19 UTC
rendered paste body
#!/usr/bin/php -q<?php	// SCC PHP RSS Auto-Downloader Script by b3n	// Edit these variables	// $url         = http link to your rss feed (http://sceneaccess.org/getrss.php)	// $watchdir    = directory the script is working in with trailing slash	// $matchesini  = file with regular expressions in	// $logging     = 1 logging is on or 0 its not	// $logfile     = file to write log to (must be writable)		$url = "http://www.sceneaccess.org/rss.php?feed=dl&cat=23,22,7,27,11&passkey=yourpasskeyhere";	$watchdir = "/path/to/watch/dir/";	$matchesini = "matches.ini";	$logging = 1;	$logfile = "log";			// DONT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING		// Load regex matches	$ini_array = parse_ini_file($matchesini, true);		// Loads RSS items	$doc = new DOMDocument();	$doc->load($url);	$arrFeeds = array();	foreach ($doc->getElementsByTagName('item') as $node) {		$itemRSS = array ( 			'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,			'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,			);					array_push($arrFeeds, $itemRSS);	}		// For each item	foreach ($arrFeeds as $item) {			// For each match filter		foreach ($ini_array[regexmatches][matches] as $ex) {			checkmatch($item, $ex);		}				// For each one-time match filter		foreach ($ini_array[regexonetimematches][onetimematches] as $key => $ex) {					if (checkmatch($item, $ex) == true) {							// Remove entry and write matches back to the ini				unset($ini_array[regexonetimematches][onetimematches][$key]);				write_ini_file($ini_array, $watchdir.$matchesini);							}		}		}		// Function to check torrents against filters	function checkmatch($item, $ex) {		global $watchdir;			// If there is a match		if (preg_match($ex, $item['title'])) {			$torrent = $watchdir.end(explode("/", $item['link']));			// If torrent file doesnt already exists			if (!file_exists($torrent)) {				// Download the torrent				$content = file_get_contents($item['link']);				if ($content !== false) {					// Write .torrent to file					if ($fh = fopen($torrent, 'w')) {						fwrite($fh, $content);						fclose($fh);					} else {						write_log_file("Cant write .torrent file! (".$torrent.")");					}										// Write log entry					write_log_file("Downloaded: ".$item['title']);					return true;									} else {										write_log_file("Cant download torrent! (".$item['link'].")");					   				}			}		}	}		// Function to add entry to log	function write_log_file($data) {		global $logging;		global $watchdir;		global $logfile;		if($logging == 1){			$fh = fopen($watchdir.$logfile, 'a');			if($fh != false) {				fwrite($fh, date('d/m')." - ".$data."\n");				fclose($fh);			} else {				echo "Cant write to log file! (".$watchdir.$logfile.")";			}		}	}		// Function to modify matches ini file		function write_ini_file($assoc_arr, $path) {		$content = "";		foreach ($assoc_arr as $key=>$elem) {			$content .= "[".$key."]\n";			foreach ($elem as $key2=>$elem2) {				if(is_array($elem2)) {					for($i=0;$i<count($elem2);$i++) {						if ($elem2[$i] != "") $content .= $key2."[] = \"".$elem2[$i]."\"\n";					}				}				else if($elem2=="") $content .= $key2." = \n";				else $content .= $key2." = \"".$elem2."\"\n";			}		}		if (!$handle = fopen($path, 'w')) {			return false;		}		if (!fwrite($handle, $content)) {			return false;		}		fclose($handle);		return true;	} ?>