View Single Post
Old 04-05-2009, 12:54 PM   #78
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,110
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
erayd! Yay! You're back!

By the way, flag.erayd.net seems to be down the past few weeks.

FanFiction.Net changed their pages quite a bit (added graphics, changed handling of crossover fics, etc). Below are the changes I made to get FF.Net working again, albeit there's probably a few changes in there for additional information (I was working on an already modified version ).

Code:
function ffnet_get_meta($page) {
	$matches = array();

	//category and title
	if (preg_match('/<td>.*<a href.+>.+Crossover<\/a> »/Ui', $page, $matches)) {
		preg_match('/<td>.*<a href.+>(.+) Crossover<\/a> » <b>(.+)<\/b><\/td>/Ui', $page, $matches);
		$matches[1] = str_ireplace(',', '', $matches[1]);
		$tag = str_ireplace(' and ', ',', $matches[1]);
	}
	else preg_match('/<td>.+ » <a href=.+>(.+)<\/a> » <b>(.+)<\/b><\/td>/Ui', $page, $matches);

	//author
	preg_match("/<td>Author: <a href='\/u\/[0-9]+\/.+'>(.+)<\/a><\/td>/Ui", $page, $author);
	$meta['title'] = $matches[2];
	$meta['author'] = $author[1];
	$meta['category'] = $matches[1];
	$meta['crosscat'] = $tag;

	//rating, lang, category
	preg_match("/<TR><TD><a href='http:\/\/www.fictionratings.com\/guide.php' target='rating'>Fiction Rated: (.+)<\/a> - (.+) - +(.+) - Reviews: <a href='.+'>[0-9]+<\/a> - Published: ([0-9-]+) - Updated: ([0-9-]+) (- (Complete)+ )?- id:([0-9]+) <\/td><\/TD><\/TR>/Ui", $page, $matches);
	$meta['rating'] = $matches[1];
	$meta['language'] = $matches[2];
	$meta['genre'] = $matches[3];
	$meta['date_pub'] = $matches[4];
	$meta['date_update'] = $matches[5];
	$meta['complete'] = $matches[7] == 'Complete' ? true : false;
	$meta['ficstatus'] = $matches[7] == 'Complete' ? 'Complete' : 'In-Progress';
	$meta['id'] = $matches[8];

	//description
	preg_match('/<meta name="description" content="(.+), (.+),  (.+)">/Ui', $page, $matches);
	$meta['summary'] = $matches[3];
	$meta['summary'] = iconv('UTF-8', 'ISO-8859-15//TRANSLIT//IGNORE', $meta['summary']);

	//chapters
	if(preg_match("/<SELECT title='chapter navigation' Name=chapter onChange=\".+\">(<option.+)<\/select>/Ui", $page, $matches)) {
		preg_match_all("/<option  value=[0-9]+ (selected)?>([0-9]+). (.+)(?=<option|$)/Ui", $matches[1], $matches);
		foreach($matches[2] as $key => $chapnum) $chaparr = $chapnum;
		$meta['chapters'] = $chaparr;
	}

	return $meta;
}
Here are some changes I made to epub.codec.php so it will display additional meta information in Calibre. This works with the Windows CLI utilities. I think it should be the same for Linux. As far as I'm aware, the only changes rgibbo made in the Windows port is changing the handling of temp folder and removal of posix functions.
Code:
	//Fix summary
	$story['meta']['summary'] = str_replace('"', '\"', $story['meta']['summary']);

	//XPath for chapter detection
	$cli_chapter = "";
	$cli_chapter .= " --chapter-mark \"pagebreak\"";

	//metadata
	$cli_metadata = "";
	$cli_metadata .= " -t \"{$story['meta']['title']}\"";
	$cli_metadata .= " -a \"{$story['meta']['author']}\"";
	if(!($story['meta']['crosscat'] == '')) $cli_metadata .= " --subjects \"{$story['meta']['crosscat']}\"";
	else if(!($story['meta']['category'] == '')) $cli_metadata .= " --subjects \"{$story['meta']['category']}\"";
	if(!($story['source'] == '')) $cli_metadata .= " --publisher \"{$story['source']}\"";
	$cli_metadata .= " --comment \"<b>Story id:</b> {$config['storyid']}";
	if(!($story['meta']['category'] == '')) $cli_metadata .= "<br><b>Category:</b> {$story['meta']['category']}";
	if(!($story['meta']['genre'] == '')) $cli_metadata .= "<br><b>Genre:</b> {$story['meta']['genre']}";
	if(!($story['meta']['rating'] == '')) $cli_metadata .= "<br><b>Rating:</b> {$story['meta']['rating']}";
	if(!($story['meta']['ficstatus'] == '')) $cli_metadata .= "<br><b>Status:</b> {$story['meta']['ficstatus']}";
	if(!($story['meta']['summary'] == '')) $cli_metadata .= "<br><b>Summary:</b> {$story['meta']['summary']}";
	$cli_metadata .= '"';

	//Create the epub content and store it in a temp file
	exec("html2epub $cli_chapter $cli_metadata \"$temp_fname.html\"");
	$result = file_get_contents("$temp_fname.epub");
Anyway, it's good to have you back!
ilovejedd is offline   Reply With Quote