Page 1 of 1

TV Renaming

Posted: February 6th, 2009, 12:40 am
by markus101
Hi,

I have a quick question about how SAB handles TV Renaming, in particular shows that have (US) in them. I am currently running a trunk version of SAB, but the question also applies to 0.4.6. I'm running SAB on Slackware 12.1. My question/issue is when a show downloads that has (US) in it, SAB puts it in a folder like so.

Code: Select all

/mnt/user/tv/Show Name (Us)/Season 01/Show Name (Us) - S01E01 - Example Episode.avi
I'm using the Auto Download script on these forums, http://forums.sabnzbd.org/index.php?topic=1335.135 Which looks to see if I want the show, if I already have that episode, if its in the queue before is starts downloading. With the way the way SAB renames the (US) in the NZB to (Us), it never finds the folder with the show, so it thinks I don't want it, when I really do.

Just wondering if there is a particular reason it has been done this way and if there is any way around it. I'd love to be able to sort it out and thought of writing some sort of shell script to handle it, but I'm not 100% how/where to start with that idea.

Thanks for all the effort on SAB, it really is amazing, and beats the pants off of other solutions I've used.

-Markus

Re: TV Renaming

Posted: February 6th, 2009, 9:28 am
by switch
We run a python string function called title() to clean up the folder name for shows. This is because not every download has a nicely cased show name when downloaded, some may be lower case, some mixed case:

Code: Select all

Show Name - 1x01 - EpName.nzb
show.name.s01e01-RLSGROUP.nzb
This can cause problems on file systems that allow the same folder names in differences cases; as it could mean shows get split into two different folders if one was downloaded in Mixed Case and one just lower case. Titling the show name means downloads should end up in the same folder regardless of their original case, however it does produce the annoyance you describe. If I can get a definitive list of all the country tags that newzbin adds to their shows, I may look into doing some simple string replacing; however this would mean linux/OSX users would have to manually change their show name folders to upper case show names, or risk having new shows being created in a separate folders after upgrading sabnzbd versions.

To solve the exact issue you have, I would recommend changing the string comparisons you use in the Auto Download script in comaring the lower case version of your strings against each other. Such as

Code: Select all

if name1.lower() == name2.lower()
That is the recommended way for string comparison if there is a possibility of one of them being in a different letter case.

If you just don't want that naming at all, you could edit the source of sabnzbd removing all .title() calls in tvsort.py (just search for .title() and remove it).

Re: TV Renaming

Posted: February 6th, 2009, 9:45 am
by shypike
Shouldn't we just drop the "title-re-casing" feature altogether?

Re: TV Renaming

Posted: February 6th, 2009, 9:52 am
by switch
Well we could, but as I mentioned this would likely cause shows to be split up into two different folders on OSX/Linux systems if they mix lower and mixed case nzb's
Such as these two nzb's:

Code: Select all

Show Name - 1x01 - EpName.nzb
show.name.s01e01-RLSGROUP.nzb
would end up being put under two different show folders instead of one:

Code: Select all

\Downloads\TV\Show Name\Season 1\Show Name - 1x01 - EpName.avi
\Downloads\TV\show name\Season 1\show name - 1x01.avi

Re: TV Renaming

Posted: February 6th, 2009, 10:15 am
by markus101
I've seen US, UK, and AU so far on Newzbin. In addition the Auto Download script is also using for os.path.exist instead of comparing strings. I looked at something in Python (I believe it was Python 2.6 though), but it had no effect on UNIX based systems anyways. I looked at the tvsort.py code, it only has one .title() in def getTitles.

In that same definition would adding .replace('Us','US') work? I see that you're replacing roman numbers Iii becomes III and Ii becomes II, although that would cause any show with Us in it to come up as US, although I only found 4 or 5 shows the Us in the episode title (That I already had).

-Markus

Re: TV Renaming

Posted: February 6th, 2009, 10:36 am
by switch
Here is what I believe is the full list (based of tvrage.com's country classifications).

Code: Select all

(US) (UK) (EU) (CA) (YU) (VE) (TR) (CH) (SE) (ES) (KR) (ZA) (SK) (SG) (RU) (RO) (PR) (PT) (PL) (PH) (PK) (NO) (NG) (NZ) (NL) (MX) (MY) (MK) (KZ) (JP) (JM) (IT) (IL) (IE) (IN) (IS) (HU) (HK) (HN) (GR) (GH) (DE) (FR) (FI) (DK) (CZ) (HR) (CR) (CO) (CN) (CL) (BG) (BR) (BE) (AT) (AU) (AW) (AR) (AL) (AF)

Re: TV Renaming

Posted: February 6th, 2009, 11:04 am
by Stokkes
Just to throw in my 0.02$...

I think title re-casing is important for the reasons switch mentioned.

On unix systems, this would cause a lot of duplicate folders. And if you're using any kind of HTPC software (Like XBMC) which auto scans your TV show folders, then it too, will think there are duplicates.

I constantly have the issue markus has with shows such as:

The Office (Us) vs The Office (US)
Er vs. ER

and it does make a difference. I often find duplicate directories in my tv show folder that I have to manually clean up. I know there isn't a perfect system, but I think it would be important to keep what's there.

Re: TV Renaming

Posted: February 6th, 2009, 11:32 am
by markus101
I agree totally, removing it could make it much worse than it is. It wasn't an issue before, but with RSS feeds getting lots of old shows going through them in was a major PITA to wake up and find out that 5 seasons of Family Guy had downloaded (again). Looks like quite a few different Country codes available, my concern would be how would these be handled if they didn't contain brackets... IE a feed from nzbs.org Doesn't wrap US in brackets, but Newzbin does - If I switch feeds and grab sometting from nzbs.org I come across that difference for shows with US in them.

I was thinking of going with a shell script that looked for (Us) in the download path and replaced (Us) with (US) and then moved it to the appropriate directory, one extra step, but not a huge script to run on all TV shows, although I'm very new with how Bash works, I'm trying to learn the ins and outs of find, grep, sed, pretty much anything that could help.

-Markus

Re: TV Renaming

Posted: February 6th, 2009, 11:41 am
by switch
markus101 wrote: I was thinking of going with a shell script that looked for (Us) in the download path and replaced (Us) with (US) and then moved it to the appropriate directory, one extra step, but not a huge script to run on all TV shows, although I'm very new with how Bash works, I'm trying to learn the ins and outs of find, grep, sed, pretty much anything that could help.
You could apply this diff to your current trunk version (untested):

Re: TV Renaming

Posted: February 6th, 2009, 12:15 pm
by markus101
Wow...that works wonders, albeit it was just a single test download, but it worked. Of course Windows crapped itself when I was checking the folders after and it didn't know what to do with Us and US...oh well.

Thanks for fixing that so fast...makes my life much easier. As always, amazing work on this project. Will this eventually make its way into the latest trunk release? (If it hasn't already).

Cheers,

Markus

Re: TV Renaming

Posted: February 6th, 2009, 12:38 pm
by switch
I'm still contemplating whether to commit it or not. It will definitely stop an annoying problem, however will also mean linux/osx users will have to rename their currently downloaded folders for the new naming scheme.

Also might have to expand it to also apply to non newzbin downloads, such as Show.Name.US-RLSGROUP.nzb. However that proves tricky if the nzb is in lower case, as false positives could easily trigger off the string replacing.

Re: TV Renaming

Posted: February 6th, 2009, 12:51 pm
by markus101
Fair enough - It's a pretty easy fix for me to implement if/when I upgrade, which I'd be willing to manually do if required, in either event thank you. Would it be possible to add it as a switch within the SAB WebUI? That way users could pick and choose, similar to Illegal Character Replacement, either its on or off. But Non-Newzbin NZB files would be a pain, as they don't encase it with ()... Would it be possible to replace .US. or .us. and instead of using Us, make it US? That should be able to handle both upper and lower case nzb's, but could(would?) catch files that have Us in the title (but only in cases where is was all in lower case, as it would be impossible to differentiate between us in the series name as a word or as a country code.

Or even easier would to inform people it only works with Newzbin (if it was a switch option within SAB).

Just my two cents as I'd love to see it as a committed feature, but see both the gains and losses of this approach.

-Markus

Re: TV Renaming

Posted: February 6th, 2009, 12:52 pm
by cydine
I just commented out the title() function and added some custom replaces in tvsort.py.

This is the appropriate section, obviously you may have to customise according to your own shows.

Code: Select all

    Returns Title, Season and Episode naming from a REGEX match
    """
    try:
        title = dirname[:match1.start()].replace('.', ' ')
        title = title.strip().strip('_').strip('-').strip().strip('_')
#       title = title.title() # title
        #title applied uppercase to 's Python bug?
#       title = title.replace("'S", "'s")
        title = title.replace("New York", "NY")
        title = title.replace("Nightmares US", "Nightmares")
        title = title.replace(" US", " (US)")
        title = title.replace("Hour", "Hour (US)")
        title = title.replace("Galactica", "Galactica (2003)")

Re: TV Renaming

Posted: February 8th, 2009, 3:32 pm
by phatrabt
cydine wrote: I just commented out the title() function and added some custom replaces in tvsort.py.

This is the appropriate section, obviously you may have to customise according to your own shows.

Code: Select all

    Returns Title, Season and Episode naming from a REGEX match
    """
    try:
        title = dirname[:match1.start()].replace('.', ' ')
        title = title.strip().strip('_').strip('-').strip().strip('_')
#       title = title.title() # title
        #title applied uppercase to 's Python bug?
#       title = title.replace("'S", "'s")
        title = title.replace("New York", "NY")
        title = title.replace("Nightmares US", "Nightmares")
        title = title.replace(" US", " (US)")
        title = title.replace("Hour", "Hour (US)")
        title = title.replace("Galactica", "Galactica (2003)")
Was this on Windows or Linux?  Ideally, in my case I'd just like to get rid of the US (or Us) in the name since I don't need a country code.  How would you suggest going about that?  Thanks!