• 1
  • 5
  • 6
  • 7(current)
  • 8
  • 9
  • 49
SortTV: Sort TV episodes, movies, and music into directories for xbmc (Linux/Win/Mac)
#91
nicx76 Wrote:hi,

this tool sound great. one question: is it possible to scape episode and season numbers by episode and show name from thetvdb.com? that would be THE toll i am looking for weeks now Wink

nicx...

Sorry SortTV currently does its matching and sorting based on figuring out the season and episode number. Then information such as episode titles is retrieved from the tvdb.

It would be possible to implement the feature you describe, but I don't see many other people needing it. It seems like a rare case to just have the files named after the episode title without any way to watch them in order...

Could you describe or show some examples of the file naming you have.

If you are happy to hack away at some Perl programming to add the feature I would be happy to point you in the right direction.
Reply
#92
Hi Cliffe
I'm getting a new error. The tvdb error is gone. Now i'm getting

Can't locate Text/Capitalize.pm in @INC (@INC contains: C:/Users/Runar/Downloads
/perl/site/lib C:/Users/Runar/Downloads/perl/vendor/lib C:/Users/Runar/Downloads
/perl/lib .) at sorttv.pl line 36.
BEGIN failed--compilation aborted at sorttv.pl line 36.

I've installed Capitalize, but i got alot of errors when installing it.
For example it only passes 4 of the 76 test while trying to install it.
Any idea why it won't install corectly? I've got the latest strawberry perl installed.
Reply
#93
Hi Cliffe

I got the same error as lompelurt, but I simply commented out:
Quote:use Text::Capitalize;
(line 36)

I also found a problem with this line, regardless of what I put in the config file this IF passes, which means I always encounter the permission denied error.
Quote:if($renameformat =~ /\[EP_NAME\d]/i || $fetchimages ne "FALSE")
(line 67)

So I commented out the entire 'if statement' and it works for all that I need (file moving).

Unfortunately I don't know enough about perl to fix the problems myself, but as I don't need that functionality I can live with it all commented out.
Reply
#94
lompelurt Wrote:Hi Cliffe
I'm getting a new error. The tvdb error is gone. Now i'm getting

Can't locate Text/Capitalize.pm in @INC (@INC contains: C:/Users/Runar/Downloads
/perl/site/lib C:/Users/Runar/Downloads/perl/vendor/lib C:/Users/Runar/Downloads
/perl/lib .) at sorttv.pl line 36.
BEGIN failed--compilation aborted at sorttv.pl line 36.

I've installed Capitalize, but i got alot of errors when installing it.
For example it only passes 4 of the 76 test while trying to install it.
Any idea why it won't install corectly? I've got the latest strawberry perl installed.

Well, apparently that will be a linux only feature since the package it fails on cannot be built on windows in mingw. It requires PerlIO::locale and it itself won't build on windows due to lack of nl_langinfo support.
Code:
CPAN.pm: Going to build R/RG/RGARCIA/PerlIO-locale-0.06.tar.gz

Set up gcc environment - 3.4.5 (mingw-vista special r3)
This module doesn't support yet platforms that don't have nl_langinfo(3).

------------
Cliffe,

Here is a patch to make PRESERVE_ALLCAPS switchable in the config, as I don't use it and figure there will be times when people don't want it on. But now with my above answer I am not sure if it is even worth while since Text::Capitalize appears windows unfriendly due to dependancies unless you know of another more friendly function, I guess it can always be a linux (or mac?) only feature till an alternative is found or coded.

Code:
--preserve-allcaps:[TRUE|FALSE]
        Keeps all caps in a filename uppercase when capitalizing the title of the show.
        eg. CSI crime scene investigator becomes CSI Crime Scene Investigator
        Note: show-name-substitue overrides this so if you specify all uppercase shows using it you don't need this enabled.
        Set to FALSE if you have problems with shows being all caps.
        eg. WITHOUT A TRACE becomes Without a Trace
        If not specified, TRUE
Patch Here
Reply
#95
CoinTos Wrote:Well, apparently that will be a linux only feature since the package it fails on cannot be built on windows in mingw. It requires PerlIO::locale and it itself won't build on windows due to lack of nl_langinfo support.
Code:
CPAN.pm: Going to build R/RG/RGARCIA/PerlIO-locale-0.06.tar.gz

Set up gcc environment - 3.4.5 (mingw-vista special r3)
This module doesn't support yet platforms that don't have nl_langinfo(3).

------------
Cliffe,

Here is a patch to make PRESERVE_ALLCAPS switchable in the config, as I don't use it and figure there will be times when people don't want it on. But now with my above answer I am not sure if it is even worth while since Text::Capitalize appears windows unfriendly due to dependancies unless you know of another more friendly function, I guess it can always be a linux (or mac?) only feature till an alternative is found or coded.

Code:
--preserve-allcaps:[TRUE|FALSE]
        Keeps all caps in a filename uppercase when capitalizing the title of the show.
        eg. CSI crime scene investigator becomes CSI Crime Scene Investigator
        Note: show-name-substitue overrides this so if you specify all uppercase shows using it you don't need this enabled.
        Set to FALSE if you have problems with shows being all caps.
        eg. WITHOUT A TRACE becomes Without a Trace
        If not specified, TRUE
Patch Here

Thanks. Since there are already Windows and Linux users, SortTV will, as far as possible, stay platform independent. I'll probably write a replacement capitalise function when I get a chance.

An alternative solution to the title capitalisation would be to do a lookup on thetvdb and see what capitalisation that uses...
Reply
#96
Targettio Wrote:Hi Cliffe

I got the same error as lompelurt, but I simply commented out:

(line 36)

I also found a problem with this line, regardless of what I put in the config file this IF passes, which means I always encounter the permission denied error.

(line 67)

So I commented out the entire 'if statement' and it works for all that I need (file moving).

Unfortunately I don't know enough about perl to fix the problems myself, but as I don't need that functionality I can live with it all commented out.

Hi Targettio
This might be a stupid question, but what do you mean by you commented out those line. Do you mean you deleted them? I'm new to this so I have no idea what i am doing.
Reply
#97
If you are using Windows then please use v1.11 until v1.14 is released.

If you get the
Code:
DBM: Deep : Cannot sysopen file '/.tvdb' : Permission denied
error, then try changing the line
Code:
my $tvdb = TVDB::API::new($TVDBAPIKEY);
to
Code:
my $tvdb;
And disable the tvdb features in the config, as previously explained.

lompelurt Wrote:Hi Targettio
This might be a stupid question, but what do you mean by you commented out those line. Do you mean you deleted them? I'm new to this so I have no idea what i am doing.

Just add a hash (#) at the start of the line. This tells perl to ignore the line.
Reply
#98
lompelurt Wrote:Hi Targettio
This might be a stupid question, but what do you mean by you commented out those line. Do you mean you deleted them? I'm new to this so I have no idea what i am doing.

cliffe Wrote:Just add a hash (#) at the start of the line. This tells perl to ignore the line.

Yeah I just put hashes in front of lines that were causing errors and it all worked fine. (line 36 and the whole IF that starts on line 67)
Reply
#99
Finally Big Grin
Thanks guys! Appreciate it.
Reply
cliffe Wrote:Sorry SortTV currently does its matching and sorting based on figuring out the season and episode number. Then information such as episode titles is retrieved from the tvdb.

It would be possible to implement the feature you describe, but I don't see many other people needing it. It seems like a rare case to just have the files named after the episode title without any way to watch them in order...

Could you describe or show some examples of the file naming you have.

If you are happy to hack away at some Perl programming to add the feature I would be happy to point you in the right direction.

ok just a simple example:

this is what i have: "Two and a Half Men - Give Me Your Thumb.ts"
this is what i want: "Two and a Half Men - S7E6 - Give Me Your Thumb.ts"

is this that complicated? Wink

nicx...
Reply
Cliffe,

Took some time after work to remove my Capitalization 'bug' then add a more platform independant solution and fix my $#*! lookup issue. Meet version 1.14rc, due to me working on windows for this and so I can test it there, Eclipse formated the file differently with my new code so a patch file was all but impossible. I mostly likely made it worst when I tried to fix the formating but anyhoo...

New features (if accepted):
> --show-title-rename - uses tvdb lookup for proper title format. (replaces Text::Capitalize)
> added tvdb id support for shows that the ep lookup gets confused on, now you can use the tvdb id # for the sub name. ie. $#*! My Dad Says ep lookup now works with tvdb id.

Once again, sorry about the lack of patch file, tomorrow when I am rested again I can copy additions into a basic editor that won't mess with it's formating so I can make a useable patch file.

Here is my release candidate if you wish to look at it and implement.
Sorttv 1.14rc
Reply
CoinTos Wrote:Cliffe,

Took some time after work to remove my Capitalization 'bug' then add a more platform independant solution and fix my $#*! lookup issue. Meet version 1.14rc, due to me working on windows for this and so I can test it there, Eclipse formated the file differently with my new code so a patch file was all but impossible. I mostly likely made it worst when I tried to fix the formating but anyhoo...

New features (if accepted):
> --show-title-rename - uses tvdb lookup for proper title format. (replaces Text::Capitalize)
> added tvdb id support for shows that the ep lookup gets confused on, now you can use the tvdb id # for the sub name. ie. $#*! My Dad Says ep lookup now works with tvdb id.

Once again, sorry about the lack of patch file, tomorrow when I am rested again I can copy additions into a basic editor that won't mess with it's formating so I can make a useable patch file.

Here is my release candidate if you wish to look at it and implement.
Sorttv 1.14rc

First of all thanks for taking the time to do this. It is fantastic to get the code contribution. I look forward to incorporating these features into SortTV.

A few constructive comments: Please stick to the code style and layout used. I realise that spacing is a matter of preference, but as with contributing to any open source projects, it is polite to use the established style, or discuss changes. I agree with reformatting the eval lines (and maybe some other changes), but when submitting patches please try to stick with the current coding style. It also makes it hard to review feature changes, when you have made lots of unrelated changes.

Example of style (no need for blank lines in if statements these are the product of the forum):
Code:
if(condition1) {
[INDENT]statement;[/INDENT]
} elsif(condition2) {
[INDENT]statement;[/INDENT]
} else {
[INDENT]statement;
# one line if statements like the following could be turned into multi-line ones if the condition gets too long.
statement if condition3;[/INDENT]}

I can review changes to style separately, but please send your patch without style changes.

Update: I notice you mention your editor made some changes, so perhaps these are all the result of your text editor Smile

Regarding the actual feature changes:

Please call the argument "--fetch-show-title" or something that can not imply that it forces a file rename.

Your version included this strange output:
Code:
DOWNLOAD: downloading images for CSI: Crime Scene Investigation
/Season 1ing season directory: /home/cliffe/Files/Media/TV/CSI- Crime Scene Investigation
DOWNLOAD: downloading season image for CSI: Crime Scene Investigation
Season 1 Episode 4.episode title for CSI: Crime Scene Investigation
- S01E04.avi- Crime Scene Investigationds/Unsorted/CSI s1e4.avi to /home/cliffe/Files/Media/TV/CSI- Crime Scene Investigation
Season 1 Episode 5.episode title for CSI: Crime Scene Investigation
- S01E05.avi- Crime Scene Investigationds/Unsorted/csi s1e5.avi to /home/cliffe/Files/Media/TV/CSI- Crime Scene Investigation

I look forward to the patch. Please create the patch using:
Code:
diff -u /path/to/sorttv.pl /path/to/your-new-version-of-sorttv.pl > sorttv.patch
You can use directories if you have made changes to all the files.
(or you can use git and pull the latest SortTV version from sourceforge)
Please only include feature changes. (i.e. don't include your own config file settings changes)

As you are probably aware, the command dos2unix can convert the Windows formatted file into a Linux formatted file.

Anyway, thanks again, I look forward to receiving a patch.
Reply
Quote:Update: I notice you mention your editor made some changes, so perhaps these are all the result of your text editor

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. :-)

Quote:Please call the argument "--fetch-show-title" or something that can not imply that it forces a file rename.
Agreed, I blame lack of sleep.

Quote:Your version included this strange output:
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
Reply
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 Smile


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. Smile

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 {}
Reply
Quote:As is fairly typical for open source collaboration, I have reviewed your code and made some comments below.
I sure hope you do cause I am as proficient in programming as I am with flying without having wings. :-)

Quote:Tabs rather than spaces please
D'oh though I got all them.

Quote:Looks like you only use this second arg once. Instead, just add a check in here (see my next comment)
You caught me I cheated, I kept running into a problem with it suppling the name not the ID on episode lookup.

Quote: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?
It's soon to be gone, I had this crazy idea for the look up with only Show Title and Ep Title known to make one big tvdb sub but it didn't work out like I hoped.

Quote:Also please check the spacing for the lines you have changed. They are often formatted differently. Check the spaces between () and also {}

I'll work on that.

Update
--------
Cliffe,

This more of a take a look up date I did what you said above but I am still stuck on that used one variable. I cheated with it cause I wanted the actual name sub'ed for everything but episode lookup where I want the tvdb id to be used. I also include a sub that will take a show title and episode title and find the season number and episode number, sadly, I can't figure out how make it work in the reg detection of sort_directory.

Anyways, here the patch so you can take a look if you like.
patch
Reply
  • 1
  • 5
  • 6
  • 7(current)
  • 8
  • 9
  • 49

Logout Mark Read Team Forum Stats Members Help
SortTV: Sort TV episodes, movies, and music into directories for xbmc (Linux/Win/Mac)8