All pastes #624132 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-07-18 02:02 UTC
rendered paste body
#!/usr/bin/perl

use strict;
use Math::Round;

#User Configurable Variables
my $path = "C:/x264.output";

#Register Plugin and Command
Xchat::register("x264 info ","0.02","Prints info from modded x264 build.");
IRC::add_command_handler("x264","cmd_x264info");
IRC::print("x264 info 0.1 by Daemon404 loaded.");

#Usage: filesize(outputstring, cwdstring, <perc>)
sub filesize {
	my $file;
	my $fsize;
	my $unit;
	my $temp;
	if ($_[0] =~ m/^.:/) {
		$file = $_[0];
	}
	elsif ($_[0] =~ m/^\\/) {
		my @t_1 = split(/\\/,$_[1]);
		$file = "$t_1[0]\\$_[0]";
	}
	else {
		$file = "$_[1]\\$_[0]";
	}
	$fsize = -s $file;
	if ($_[2]) {
		$fsize = ($fsize/$_[2])*100;
	}
	for (my $i=1024; $i <= 1024**3; $i*=1024) {
		if ($fsize >= 1024) {
			$fsize = $fsize/1024;
			if ($i == 1024) {
				$unit = "KB";
			}
			elsif ($i == 1024**2) {
				$unit = "MB";
			}
			elsif ($i == 1024**3) {
				$unit = "GB";
			}
		}
	}
	$temp = nearest(.01,$fsize);
	if ($_[0] =~ m/^NUL$/ || $temp < 1) {
		return "N/A";
	}
	else {
		return "$temp $unit";
	}
}

#Usage: filename(inputstring)
sub filename {
	my @slash = split(/\\/,$_[0]);
	return $slash[scalar(@slash)-1];
}

#Usage: input(percent)
sub bar {
	my $bar;
	my $num = nearest(10,$_[0]);
	for (my $i=10; $i <= 100; $i+=10) {
		if ($num >= $i) {
			$bar .= "\cC04|";
		}
		else {
			$bar .= "\cC15-";
		}
	}
	return $bar;
}

#Actual XChat Command
sub cmd_x264info {
	open info, "< $path" or die("x264 output file cannot be opened");
	my @array = split(/:::/,<info>);
	close info;

	my @f_info;

	$f_info[0] = nearest(.1,($array[0]/$array[1])*100);
	$f_info[1] = bar($f_info[0]);
	$f_info[2] = filename($array[6]);
	$f_info[3] = filesize($array[8],$array[7]);
	$f_info[4] = filesize($array[8],$array[7],($array[0]/$array[1])*100);

	IRC::command "/say \cC05[\cC15x264\cC05] [\cC15File: $f_info[2]\cC05] [\cC15$f_info[0]%\cC05] [$f_info[1]\cC05] [\cC15$array[0]/$array[1] frames encoded at $array[2] fps\cC05] [\cC15ETA: $array[3]:$array[4]:$array[5]\cC05] [\cC15Filesize: $f_info[3]\cC05] [\cC15Proj. Filesize: $f_info[4]\cC05]";
}