2011-02-20, 14:40
Nice suggestions Cliffe, I think I've implemented them properly now I'm still getting the hang of perl, and love some of the conventions you've been using throughout your code!
And for the config file:
Let me know what you think :-)
Regexp is certainly my weakness, I'm not sure that I can implement the multiple episode fix sufficiently. I'll certainly give it a bit of a think and analyze your code further. You may end up working it out long before I do!
Code:
diff -u defaults/sorttv.pl sorttv.pl
--- defaults/sorttv.pl 2011-02-18 11:53:07.918356001 +1100
+++ sorttv.pl 2011-02-20 23:36:20.698356001 +1100
@@ -49,7 +49,7 @@
my ($sortdir, $tvdir, $nonepisodedir, $xbmcwebserver, $matchtype);
my ($showname, $series, $episode, $pureshowname) = "";
my ($newshows, $new, $log);
-my (@showrenames, @showtvdbids, @whitelist, @blacklist);
+my (@showrenames, @showtvdbids, @whitelist, @blacklist, @sizerange);
my $REDO_FILE = my $moveseasons = my $windowsnames = my $tvdbrename = my $lookupseasonep = my $extractrar = "TRUE";
my $usedots = my $rename = my $verbose = my $seasondoubledigit = my $removesymlinks = my $needshowexist = my $flattennonepisodefiles = "FALSE";
my $logfile = 0;
@@ -133,6 +133,10 @@
next FILE;
}
+ if (check_filesize($file) eq "NEXT") {
+ next FILE;
+ }
+
if(-l $file) {
if($removesymlinks eq "TRUE") {
out("std", "DELETE: Removing symlink: $file\n");
@@ -308,6 +312,8 @@
$lookupseasonep = $1;
} elsif($arg =~ /^--verbose:(.*)/ || $arg =~ /^-v:(.*)/) {
$verbose = $1;
+ } elsif($arg =~ /^--filesize-range:(.*-.*)/ || $arg =~ /^-fsrange:(.*-.*)/) {
+ push @sizerange, $1;
} elsif($arg =~ /^--no-network/ || $arg =~ /^-no-net/) {
$xbmcwebserver = "";
$tvdbrename = $fetchimages = $lookupseasonep = "FALSE";
@@ -429,6 +435,10 @@
Uses shell-like simple pattern matches (eg *.avi)
This argument can be repeated to add more rules
+--filesize-range:pattern
+ Only copy files which fall within these filesize ranges.
+ Examples for the pattern include 345MB-355MB or 1.05GB-1.15GB
+
--xbmc-web-server:host:port
host:port for xbmc webserver, to automatically update library when new episodes arrive
Remember to enable the webserver within xbmc, and "set the content" of your TV directory in xbmc.
@@ -759,6 +769,56 @@
return "OK";
}
+sub check_filesize {
+ my ($file) = @_;
+ my $filesize = (-s $file) / 1024 / 1024;
+ my $check_flag = 'FALSE';
+
+
+ # Needed to support recursively filled directories
+ if (-d $file) {
+ return "OK";
+ }
+
+ # Loop through the size ranges passed in via the config file
+ foreach my $size (@sizerange) {
+ if ($size =~ /(.*)-(.*)/) {
+ # Extract the min & max values, can mix and match postfixes
+ my $minfilesize = $1;
+ my $maxfilesize = $2;
+ $minfilesize =~ s/MB//;
+ $maxfilesize =~ s/MB//;
+
+ # Fix filesizes passed in to all MB
+ if ($minfilesize =~ /(.*)GB/) {
+ $minfilesize = $1 * 1024;
+ }
+
+ if ($maxfilesize =~ /(.*)GB/) {
+ $maxfilesize = $1 * 1024;
+ }
+
+ # Check the actual filesize
+ if (-f $file && ($minfilesize < $filesize && $filesize < $maxfilesize)) {
+ return "OK";
+ }
+
+ # Use the flag to say we didn't find any match for the filesize
+ $check_flag = 'TRUE';
+ }
+ }
+
+ if ($check_flag =~ "TRUE") {
+ # Skip the file as it didn't fall within a specified filesize range
+ my $filename = filename($file);
+ out("std", "SKIP: Doesn't fit the filesize requirements: $filename\n");
+ return "NEXT";
+ }
+
+ # Defaults to OK so the filesize options become OPTIONAL.
+ return "OK";
+}
+
sub num_found_in_list {
my ($find, @list) = @_;
foreach (@list) {
And for the config file:
Code:
# OPTIONAL - sort files which fall within these ranges. Filesizes use the MB and GB postfixes, such as
# 170MB-400MB or 1.0GB-1.2GB. If no postfix specified, MB is assumed.
filesize-range:170MB-400MB
filesize-range:1.05GB-1.15GB
filesize-range:697MB-700MB
Let me know what you think :-)
Regexp is certainly my weakness, I'm not sure that I can implement the multiple episode fix sufficiently. I'll certainly give it a bit of a think and analyze your code further. You may end up working it out long before I do!