Renaming series

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Renaming series Tue Dec 04, 2007 2:29 am • by Laner
Hi.
I have a lot of series that is named CSI.New.york.404.avi or Heroes.205.HDTV-lol.avi
Can I use Hazel to rename them to Heroes.S02E05.avi? Where S02E05 is the important part.
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Tue Dec 04, 2007 3:45 am • by FOOOD
Yea, that would be very handy.
FOOOD
 
Posts: 49
Joined: Thu May 31, 2007 4:29 pm
Location: UK

Tue Dec 04, 2007 1:31 pm • by Mr_Noodle
It's something being considered but it's tricky. I need to come up with an easy way for users to create patterns to pick apart an existing name and put them back together in new combinations (actually, it's the first part that's the harder part; the second part is mostly there).

For instance, in your example, you want to match the text up to the first dot, then take the first number/digit and prefix an 'S' and a zero, unless it's two digits, then no zero. Then grab the next two digits, then ignore the rest until the extension. Doing a nice, compact and easy-to-decipher interface for that is a challenge.

I am thinking about it and hopefully I'll figure out something that will work and be somewhat easy to use. For now, I think doing a script is the way to do it as you can customize the logic as you see fit.
Mr_Noodle
Site Admin
 
Posts: 8571
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Wed Dec 05, 2007 2:56 am • by Laner
Renamer4Mac har done this with reg exp.
Why not put in reg exp in your program as well? Those who can use it will love it ;)
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Wed Dec 05, 2007 11:33 am • by Mr_Noodle
I think regular expressions would be too complex. I'd rather have something more accessible to normal users. It's an option but I feel I should only use them if I'm unable to work out an easier to use solution.
Mr_Noodle
Site Admin
 
Posts: 8571
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Wed Dec 05, 2007 11:40 am • by Laner
How about a switch for advanced user and a feature that detects . - for the regular user?
The same way that you have done with keywords and dates. That way reg exp would be the foundation and you can add "items" of reg exp that the novice user can rearrange.
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Fri Dec 07, 2007 2:27 pm • by Mr_Noodle
Will consider it.

In the meantime, feel free to post any patterns and examples here so I have a notion of concrete cases to consider when I design the feature. To start, maybe give me the regular expression you would want for your example above.

Thanks.
Mr_Noodle
Site Admin
 
Posts: 8571
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sun Dec 09, 2007 7:32 am • by Laner
Sorry for the delay in my answering.

I use this pattern:

Code: Select all
([0-9])([0-9])([0-9])


It selects the part with 3 numbers in a row and puts them into 3 groups.
Then i output this:

Code: Select all
S0\1E\2\3


Wich inserts S0 plus group 1 and then E and group 2 and three.

This could be more effectiv if I had only 2 groups and did know how to select 3 numbers in a row and not 4. So this pattern will not work on series like "the 4400".

Hope this helps
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Sun Dec 09, 2007 7:35 am • by Laner
Her is a smaller pattern:


Code: Select all
 ([0-9])([0-9][0-9])
S0\1E\2
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Sun Dec 09, 2007 8:09 am • by Laner
and here is the best so far matching Csi.ny.405..HDTV-LoL.avi

Search
Code: Select all
\.([0-9])([0-9][0-9])\.

Replace
Code: Select all
.S0\1E\2.
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Re: Renaming series Mon Jul 28, 2008 7:01 pm • by Gidgidonihah
Just to drag this up again, I'm actually trying to do the same thing. I was kind of disappointed that hazel doesn't have regex built in. I thought for sure that it would. I would have bought it on the spot, but now I have to make sure it does what I want. And then I'll happily pay the 20 bucks :). Good thing I have 2 weeks for testing.

Okay, so first things first, I'm movie all my movies from the downloaded folder to the movies folder. Easy enough. (And I'll be buying hazel for that alone.)

Next step is to rename. I think I've got it figured out. I can run an automator workflow on the files that match.

Now to create the workflow. We need the Automator Regex File Renamer action and we'll set up a workflow using that.

Now all the files I've looked at are in the format
Code: Select all
Name.of.Show.S01E01.HDTV.XviD-LOL.avi

Not pretty. I prefer:
Code: Select all
Name of Show - 1x01 - (title of episode to be added later).avi


So here are the regex that I use to do it:
Code: Select all
This will replace S01E01 with 1x01 and S10E12 with 10x12:

Replace: /(\.S0(\d)E(\d\d))?(?(1)|\.S(\d\d)E(\d\d))/

With: - \2\4x\3\5 -

Code: Select all
This will remove all the release info:

Replace: /(\.HDTV)|(\.PDTV)|(\.WS)|(\.DSRip)|(\.XviD)|(\-LOL)|(\-2HD)|(\-aAF)|(\-0TV)|(\-DOT)|(\-FQM)|(\.\[VTV\])|/

(Leave the replacement blank)

Code: Select all
And this will replace all . with a space (save the file extension space):

Replace: /\.(?!\w\w\w?\w?$)/

With: (a space)


Now with those 3 rename rules, it should be properly renamed.
I can't, however, vouch for this, since I've yet to try it. I figured out the regex on my lunchbreak. Now when I get home, I actually get to test it out. Yay.

I'll post back with the results.
Gidgidonihah
 
Posts: 19
Joined: Mon Jul 28, 2008 6:18 pm

Re: Renaming series Mon Jul 28, 2008 8:01 pm • by Gidgidonihah
Well I got home and gave it a try.

Epic fail.

The regex renamer action doesn't work. I get this:
Bad provides type. Shell scripts can output Text or Data. (452579328)

Guess I'll search elsewhere.
Gidgidonihah
 
Posts: 19
Joined: Mon Jul 28, 2008 6:18 pm

Re: Renaming series Tue Jul 29, 2008 4:17 am • by Laner
Too bad, Gidgidonihah.
It looked very promising. But Mr_Noodel said he would look into it so we might get it :)
Laner
 
Posts: 13
Joined: Tue Mar 06, 2007 3:44 am

Re: Renaming series Tue Jul 29, 2008 11:23 am • by Gidgidonihah
Well actually, I worked out another way. And now that I read back through the posts, it's exactly the way Mr.Noodle said. Go figure.
Simple enough for anyone that has any programming knowledge.
Easier still for anyone that likes my naming style and wants to copy/paste.
And it takes a step (automater) out of the process.

I just created, I don't know what it's called, an action maybe, something that hazel does when the rules match, and chose 'run shell script'. Then leave the second column default and click on edit script.

Change the first line to /usr/bin/perl and put this code in the big box:
Code: Select all
#!/usr/bin/perl

$name = @ARGV[0];
$oldname = $name;

# Change episode numbers
$name =~ s/(\.S0(\d)E(\d\d))?(?(1)|\.S(\d\d)E(\d\d))/ - \2\4x\3\5 -/g;

# Remove release information
$name =~ s/(\.HDTV)|(\.PDTV)|(\.WS)|(\.DSRip)|(\.XviD)|(\-LOL)|(\-2HD)|(\-aAF)|(\-0TV)|(\-DOT)|(\-FQM)|(\.\[VTV\])|//g;

# Replace all periods with a space ignoring the filetype
$name =~ s/\.(?!\w\w\w?\w?$)/ /g;

system("mv", $oldname, $name);


Works like a charm. However, there is still some tinkering to be done with the regular expressions because not everything was caught. Some of the episode numbers were formatted so the regexes didn't catch them. And a few of the episodes actually had spaces in the them so the release information wasn't caught. But it's working enough right now (catches most of them) that I'm happy. When it starts bugging me again or if I just get some time, I'll fix those bugs.

Or if anybody else is good with regex, give it a go.

Disclaimer: I'm not a perl programmer. While this does work, I can't say if it's the best way possible :)
Gidgidonihah
 
Posts: 19
Joined: Mon Jul 28, 2008 6:18 pm

Re: Renaming series Tue Jul 29, 2008 11:27 am • by Mr_Noodle
Um, have you guys checked out the pattern matching stuff I added in 2.2? It's a more simplified version of regular expressions. In the help, search for "match pattern" or even "regular expressions". You access the interface when you select the "matches/does not match" operators. You can even define custom tokens which are the equivalent of regular expression capture groups.

Try it out and let me know if you need any help with it but I think it should do what you want.
Mr_Noodle
Site Admin
 
Posts: 8571
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Tips & Tricks - DO NOT POST QUESTIONS