Author Topic: Rename unrar'd file to match NZB / release name  (Read 9576 times)

Offline nwpsys

  • Contributor
  • ***
  • Posts: 33
Rename unrar'd file to match NZB / release name
« on: March 25, 2009, 01:18:37 pm »
Would it be possible to get an option to rename the UNRAR'd file to match that of the NZB / release ?

EG The NZB/release is Nice.TV.Show.S01E01, the unrar'd file is nice.tv.show.s01e01.avi, it would be great if it could be auto-renamed to Nice.TV.Show.S01E01.avi.

Thanks,

nwpsys

Offline Ascathon

  • Contributor
  • ***
  • Posts: 608
    • vandenekker.com
Re: Rename unrar'd file to match NZB / release name
« Reply #1 on: March 25, 2009, 10:40:30 pm »
Does WinRar support renaming extracted files. I mean: is it normal to change the files which are extracted? As far as I know AltBinz uses an external program to unrar the files and I don't if you are able to change that process.
Save the Whales - Harpoon a Honda

Offline nwpsys

  • Contributor
  • ***
  • Posts: 33
Re: Rename unrar'd file to match NZB / release name
« Reply #2 on: March 26, 2009, 12:02:15 am »
I see what you are saying, but if control was returned to altbinz after the external unrar, then it could be free to do whatever it wanted with the extracted filename.

nwpsys

Offline EyeBaller

  • Contributor
  • ***
  • Posts: 66
Re: Rename unrar'd file to match NZB / release name
« Reply #3 on: March 26, 2009, 02:40:16 am »
+1 this would be really nice for dvdrips etc, since the files are usually named something like "grp-movieinitials.avi."

Offline davidq666

  • Contributor
  • ***
  • Posts: 1302
  • Watashi Wa Ero Desu!
Re: Rename unrar'd file to match NZB / release name
« Reply #4 on: March 26, 2009, 08:27:37 am »
Renaming after the collection name would make more sence coz' you'd have complete control how the file is renamed. An elaborate renaming pattern like the TV-Sorting in sabnzbd would be awesome but with the newly introduce "$col" variable i guess you should be able to do the renaming after the collection with a bat-file...

Offline Ascathon

  • Contributor
  • ***
  • Posts: 608
    • vandenekker.com
Re: Rename unrar'd file to match NZB / release name
« Reply #5 on: March 26, 2009, 08:41:56 am »
I see what you are saying, but if control was returned to altbinz after the external unrar, then it could be free to do whatever it wanted with the extracted filename.

nwpsys
file name...but the rar-file could contain tens of files with different file names and extensions. Which to rename?
Save the Whales - Harpoon a Honda

Offline davidq666

  • Contributor
  • ***
  • Posts: 1302
  • Watashi Wa Ero Desu!
Re: Rename unrar'd file to match NZB / release name
« Reply #6 on: March 26, 2009, 09:00:47 am »
that's true renaming multiple unrar'd files from the same rar-set would be a bit more tricky... maybe have the bat-file delete possible nfo's beforehand or exclude them from renaming. If there are still multiple files left after that they might be named "collection-name","collection-name"-1, "collection-name"-2 ect.

Offline nwpsys

  • Contributor
  • ***
  • Posts: 33
Re: Rename unrar'd file to match NZB / release name
« Reply #7 on: March 26, 2009, 09:26:21 am »
file name...but the rar-file could contain tens of files with different file names and extensions. Which to rename?
Ah ha - I understand. My usage of altbinz is downloading RAR sets that only ever contain one file.

So I suppose the logic could be "if only one file has been unrar'd then rename it to match the release if the option has been selected, otherwise do nothing".

nwpsys

Offline DM8Mydog

  • Contributor
  • ***
  • Posts: 48
Re: Rename unrar'd file to match NZB / release name
« Reply #8 on: March 27, 2009, 07:29:09 pm »
my 2 bits:

renaming files is evil !!!!!!!

 ;D

Offline moepmoep

  • Contributor
  • ***
  • Posts: 4
Re: Rename unrar'd file to match NZB / release name
« Reply #9 on: March 27, 2009, 10:00:52 pm »
I wrote a small python script which should only act if the collection is either named Show.Name.S01E13.Episode.Title.HDTV.XviD-LOL or Show_Name.1x13.Episode_Title.HDTV_XviD-FoV
Then the script will only rename the avi-file if it matches the file with the season number and episode number from the collection name.
And in addition files in the format "Show_Name.1x13.Episode_Title.HDTV_XviD-FoV" will be replaced with "Show.Name.S01E13.Episode.Title.HDTV.XviD-FoV" to get a more consistent naming system :) .

Create subfolders based on NZB name should be activated with this script.


Code: [Select]
"C:\Users\...\AppData\Local\Alt.Binz\rename.pyw" $u $col
Code: [Select]
import os,sys,re

if len(sys.argv) != 3:
    sys.exit()

unrardir = sys.argv[1]
collection = sys.argv[2]

regexp1 = re.compile(".*\.s(\d+)e(\d+)\..*",re.IGNORECASE)
regexp2 = re.compile(".*\.(\d+)x(\d+)\..*",re.IGNORECASE)

result = regexp1.match(collection)
if result == None:
    result = regexp2.match(collection)
    if result == None:
        sys.exit()
    season = result.group(1)
    episode = result.group(2)
    collection = re.sub("_",".",collection)
    pattern = "\.%sx%s\."%(season,episode)
    replacement = ".S%02iE%s."%(int(season),episode)
    collection = re.sub(pattern,replacement,collection)
    season = season.lstrip("0")
else:
    season = result.group(1).lstrip("0")
    episode = result.group(2)

matchexp = ".*s?0?%sx?e?%s.*\.avi"%(season,episode)

regexp3 = re.compile(matchexp,re.IGNORECASE)

files = os.listdir(unrardir)

for file in files:
    result = regexp3.match(file)
    if result != None:
        os.rename(os.path.join(unrardir, file),os.path.join(unrardir, "%s.avi"%collection))
        sys.exit()

Offline DM8Mydog

  • Contributor
  • ***
  • Posts: 48
Re: Rename unrar'd file to match NZB / release name
« Reply #10 on: March 27, 2009, 10:15:42 pm »

And in addition files in the format "Show_Name.1x13.Episode_Title.HDTV_XviD-FoV" will be replaced with "Show.Name.S01E13.Episode.Title.HDTV.XviD-FoV" to get a more consistent naming system :) .


...and I am forced to repeat: Renaming files is evil!

P2P is filled with renamed files (and several non abmm/altbin posts too). Why do it?

Keep the filenames as they are. That's ''consistent''. Renaming them isn't ''consistent''.

Offline davidq666

  • Contributor
  • ***
  • Posts: 1302
  • Watashi Wa Ero Desu!
Re: Rename unrar'd file to match NZB / release name
« Reply #11 on: March 27, 2009, 11:11:15 pm »
renaming makes perfect sense for archiving if 1x01 s01e02 and 103 names are mixed the correct order gets lost

Offline DM8Mydog

  • Contributor
  • ***
  • Posts: 48
Re: Rename unrar'd file to match NZB / release name
« Reply #12 on: March 28, 2009, 01:20:11 pm »
sorting order is a minor inconvenience.


EDIT: just so I don't come in as too 'mean' or 'cruel'....
Renaming files is evil (Yes, I insist!)

But if the renamed files never get 'shared' _EVER_ and you're the only one that will ever see those renamed files, it's fine.

If there's any future sharing of those files (either over the internet, or locally via snickernet*) then they should have never been renamed in the first place; sorting order be damned.



*snickernet: involves wearing snickers, then 'walking' to your buddy's house with your portable HDD at hand and leeching the hell out of their archive.
« Last Edit: March 29, 2009, 06:12:36 pm by DM8Mydog »

Offline davidq666

  • Contributor
  • ***
  • Posts: 1302
  • Watashi Wa Ero Desu!
Re: Rename unrar'd file to match NZB / release name
« Reply #13 on: March 28, 2009, 01:32:37 pm »
sorting order is a minor inconvenience.


yeah it is minor, but if your using a mobile player that determins the playlist by alphabetical order it's pretty annoying if the episode 7 suddenly appears between 2 and 3...

Offline nwpsys

  • Contributor
  • ***
  • Posts: 33
Re: Rename unrar'd file to match NZB / release name
« Reply #14 on: March 28, 2009, 09:32:11 pm »
I wrote a small python script which should only act if the collection is either named Show.Name.S01E13.Episode.Title.HDTV.XviD-LOL or Show_Name.1x13.Episode_Title.HDTV_XviD-FoV

Thanks, moepmoep, I will give that a try.

As for renaming files, it is personal choice. If I am collecting 720p TV shows from DIMENSION and CTU, then I get a mix of cases when unrar'd, which I choose to modify.

nwpsys