CoinTos Wrote:That exactly what happened and I again apologize for it, I will submit a proper patch today as I am now not running off of few hours of sleep and not seeing the matrix everywhere I look. :-)]
Haha. Ok
CoinTos Wrote:Agreed, I blame lack of sleep.
Oops, will be looked at and corrected.
Update
--------
Here is the patch as it stands now. It contains the code changes for --fetch-show-name and the function for using tvdb id for sub name. I fixed Eclipse so that it will never (ever ever :-)) format the original code auto-magicly. I could not reproduce that log output you posted so I will sum it up as the auto formating of Eclipse which is now fixed.
Patch File
Thanks for the patch. As is fairly typical for open source collaboration, I have reviewed your code and made some comments below. Please make and test the changes and send me another patch, then I will test and if all is well add to the next release. Cheers.
Code:
--- /home/greg/SortTV1.13/sorttv/sorttv.pl 2010-10-27 00:05:18.000000000 -0400
+++ /home/deluge/sorttv/sorttv.pl 2010-10-28 09:02:10.000000000 -0400
@@ -33,7 +33,6 @@
use File::Basename;
use TVDB::API;
use File::Find;
-use Text::Capitalize;
use FileHandle;
use warnings;
use strict;
@@ -48,6 +47,7 @@
my $renameformat = "[SHOW_NAME] - [EP1][EP_NAME1]";
my $treatdir = "RECURSIVELY_SORT_CONTENTS";
my $fetchimages = "NEW_SHOWS";
+my $tvdbrename = "FALSE";
lets start it off as TRUE (add to the line of TRUE variables)
Code:
my $imagesformat = "POSTER";
my @showrenames;
my $scriptpath = dirname(rel2abs($0));
@@ -175,7 +175,9 @@
push @showrenames, $1;
} elsif($arg =~ /^--log-file:(.*)/ || $arg =~ /^-o:(.*)/) {
$logfile = $1;
- } elsif($arg =~ /^--rename-episodes:(.*)/ || $arg =~ /^-rn:(.*)/) {
+ } elsif ( $arg =~ /^--fetch-show-title:(.*)/ || $arg =~ /^-fst:(.*)/ ) {
+ $tvdbrename = $1;
+ } elsif($arg =~ /^--rename-episodes:(.*)/ || $arg =~ /^-rn:(.*)/) {
Tabs rather than spaces please
Code:
$rename = $1;
} elsif($arg =~ /^--lookup-language:(.*)/ || $arg =~ /^-lang:(.*)/) {
$tvdblanguage = $1;
@@ -306,6 +308,11 @@
Secondary config file, overwrites settings loaded so far
If not specified, only the default config file is loaded (sorttv.conf)
+--fetch-show-title:[TRUE|FALSE]
change description to: "Fetch show titles from thetvdb.com (for proper formatting)"
You mean "with or without".
Code:
+ Rename show title to the name stored in thetvdb.com lookup format when moving, can be used with out
+ or without rename-episodes
+ If not specified, FALSE
+
--rename-episodes:[TRUE|FALSE]
Rename episodes to "show name S01E01.ext" format when moving
If not specified, FALSE
@@ -464,11 +471,15 @@
# substitutes show names as configured
sub substitute_name {
- my ($from) = @_;
Looks like you only use this second arg once. Instead, just add a check in here (see my next comment)
Code:
+ my ($from, $filter) = @_;
foreach my $substitute (@showrenames) {
if($substitute =~ /(.*)-->(.*)/) {
my $subsrc = $1, my $subdest = $2;
if($from =~ /^\Q$subsrc\E$/i) {
maybe: if($subdest =~ /^[+]?\d+$/ && $tvdbrename eq "TRUE")
Code:
+ if ( $subdest =~ /^[+]?\d+$/ && !defined($filter) )
+ {
+ $subdest = fetchshowdetails($subdest);
+ }
return $subdest;
}
}
@@ -553,7 +564,7 @@
}
if($needshowexist ne "TRUE") {
# if we are here then we couldn't find a matching show, make DIR
- my $newshowdir = $tvdir .escape_myfilename(substitute_name(capitalize_title(remdot($pureshowname), PRESERVE_ALLCAPS => 1)));
+ my $newshowdir = $tvdir .escape_myfilename(substitute_name(tvdb_title(remdot($pureshowname))));
out("std", "INFO: making show directory: $newshowdir\n");
if(mkdir($newshowdir, 0777)) {
fetchshowimages(substitute_name(remdot($pureshowname)), $newshowdir) if $fetchimages ne "FALSE";
@@ -610,6 +621,38 @@
}
}
I know I haven't commented all my subroutines (sorry), but please write a one or two line comment describing how new subroutines work.
I am inclined to not include this sub since it looks like it pretty much does a different one line thing for each request... Why not just put these one liners where this is being called from?
Code:
+sub fetchshowdetails {
+ my ( $request, $show, $series, $episode ) = @_;
+ my ( $return, $foundname );
+ $request = "" if !defined($request);
+ $show = $request if !defined($show);
+ if ( $request eq "EPISODE" ) {
+ #Get Episode Name in string using either tvdb id or search string
+ $return = $tvdb->getEpisodeName( $show, $series, $episode );
+ }elsif ( $request eq "SERIESFROMNAME" ) {
+ #Get Series info in hashref
+ $return = $tvdb->getSeries($show);
+ }elsif ( $request eq "SERIESALL" ) {
+ #Get the entire show in hashref
+ $return = $tvdb->getSeriesAll($show);
+ }else {
if this sub was staying I would set $request here too, to be consistent
Code:
+ $return = tvdb_title($show);
+ }
+ return $return;
+}
+
+sub tvdb_title {
please rename @
before to something more descriptive
Code:
+ my @before = @_;
+ my $return;
+ if ( $tvdbrename eq "TRUE" || $before[0] =~ /^[+]?\d+$/ ) {
+ $return = fetchshowdetails( "SERIESFROMNAME", $before[0] );
+ if ( defined($return) ) {
+ return $return->{'SeriesName'};
+ }
+ }
+ return $before[0];
+}
+
sub move_an_ep {
my($file, $season, $show, $series, $episode) = @_;
my $newfilename = filename($file);
@@ -623,7 +666,7 @@
}
if($renameformat =~ /\[EP_NAME(\d)]/i) {
out("verbose", "INFO: Fetching episode title for ", substitute_name(remdot($pureshowname)), " Season $series Episode $episode.\n");
- my $name = $tvdb->getEpisodeName(substitute_name(remdot($pureshowname)), $series, $episode);
please remove the 1 (see comment above about removing the argument)
Code:
+ my $name = fetchshowdetails("EPISODE", substitute_name(remdot($pureshowname), 1), $series, $episode);
if($name) {
$eptitle = " - $name" if $1 == 1;
$eptitle = ".$name" if $1 == 2;
@@ -631,7 +674,7 @@
out("warn", "WARN: Could not get episode title for ", substitute_name(remdot($pureshowname)), " Season $series Episode $episode.\n");
}
}
- my $sname = substitute_name(capitalize_title(remdot($pureshowname), PRESERVE_ALLCAPS => 1));
+ my $sname = substitute_name(tvdb_title(remdot($pureshowname)));
my $ep1 = sprintf("S%02dE%02d", $series, $episode);
my $ep2 = sprintf("%dx%d", $series, $episode);
my $ep3 = sprintf("%dx%02d", $series, $episode);
@@ -733,7 +776,7 @@
}
if($needshowexist ne "TRUE") {
# if we are here then we couldn't find a matching show, make DIR
- my $newshowdir = $tvdir .escape_myfilename(substitute_name(capitalize_title(remdot($pureshowname), PRESERVE_ALLCAPS => 1)));
+ my $newshowdir = $tvdir .escape_myfilename(substitute_name(tvdb_title(remdot($pureshowname))));
out("std", "INFO: making show directory: $newshowdir\n");
if(mkdir($newshowdir, 0777)) {
fetchshowimages(substitute_name(remdot($pureshowname)), $newshowdir) if $fetchimages ne "FALSE";
Also please check the spacing for the lines you have changed. They are often formatted differently. Check the spaces between () and also {}