Welcome, Guest
Python Scripts for ComicRack

TOPIC: Import tags from filename with regular expressions

Import tags from filename with regular expressions 9 years 6 months ago #1134

  • Yellowbox
  • Yellowbox's Avatar
  • Offline
  • Junior Boarder
  • Posts: 25
  • Thank you received: 10
  • Karma: 3
UPDATED (1/25/2011): Thanks to pcvii for fixing the directory problems!

ComicRack does a pretty good job of guessing the tags from the file name when you scan your comic folders, but sometimes I find some pretty funky naming conventions over massive amounts of comics. And often, I'd like to bring along some of that extra info.

This script will import tags from the existing file names. It will parse the path and file name, but not the extension (i.e. K:\DC\Flash\50th Anniversary Flash Special (1990) #01).

Knowledge of regular expressions is required and will not be supported here, but check out this great regex site for a tutorial or a refresher.

Use named groups to import into tags, i.e., (?<Series>.*?)

The script supports the following tags:

Textual:
Writer, Publisher, Penciller, Inker, Series, Number, AlternateSeries, AlternateNumber, Title, Summary, Notes, Genre, Colorist, Editor, Letterer, CoverArtist, Web, Imprint, Tags

Numeric:
Count, Year, Month, Volume, AlternateCount, Rating

The script also support opening and saving your RegEx patterns as single-line text files, saving by default to ComicRack\Scripts\TagPatterns.

If the script encounters an error in matching one of your comic files, it will prompt you to skip the file. In addition, the prompt offers you the option of entering a different RegEx pattern for that unmatched file, and will then continue matching the rest of the files with the original RegEx pattern.

I may make a couple of updates as I refine it for my own use, but if y'all have any non-crazy, non-inane, non-non-non-bogus suggestions, lemme hear 'em.

(And please keep in mind that this was written in about 6 hours with absolutely no previous python programming experience, so if any of you genuine pythoners out there see any inefficiencies in the script, you let me know as well.)

I've included my own TagPatterns folder as examples. Hope this helps!



File Attachment:

File Name: TagsFromName.zip
File Size:4 KB
Last Edit: 6 years 9 months ago by Yellowbox. Reason: Updated script from pcvii
The administrator has disabled public write access.
The following user(s) said Thank You: freMea, jeroenwalter

Re:Import tags from filename with regular expressions 9 years 6 months ago #1175

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
So many thanks... I have spent countless hours renaming my comics with info such as release date, arc stories, authors, condition, c2c info... beautiful, thanks, I can't wait to try it during the weekend!!!!
The administrator has disabled public write access.

Re:Import tags from filename with regular expressions 9 years 4 months ago #1793

  • perezmu
  • perezmu's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 1114
  • Thank you received: 64
  • Karma: 51
Sorry for the delay... I finally got to try it, and I can tell you, I AM LOVING IT!!!!! Thanks...!!!!!!!!!!!!!!!

:woohoo: :woohoo: :woohoo: :woohoo: :woohoo: :woohoo: :woohoo:

It's made my day! :)
Last Edit: 9 years 4 months ago by perezmu.
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 9 months ago #3024

  • the_roggy
  • the_roggy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 2
  • Karma: 0
Great tool!

Just one suggestion... it would be great if there was a 'test' functionality showing the tags+data he found before you try to apply it.

Because I'm not realy familiar with regular expressions it is a bit hard like this to 'debug' the regular expression...

Thanks!
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 9 months ago #3038

  • Yellowbox
  • Yellowbox's Avatar
  • Offline
  • Junior Boarder
  • Posts: 25
  • Thank you received: 10
  • Karma: 3
I recommend the amazingly useful program, Expresso. (Link to website.)

It's a great regex tester, as well as a regex constructor for those new to regular expressions. Put in a filename to test and it will immediately show you the results.

And don't call me a "great tool". Thanks.

Happy hunting!
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 9 months ago #3039

  • the_roggy
  • the_roggy's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 2
  • Karma: 0
Thanks Yellowbox :-).

With the help of an Expresso you get a long way apparently ;)
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 6 months ago #3543

  • AltairJr
  • AltairJr's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Karma: 0
I seem to be a little slow when it comes to this so a little help (or a pointer in the right direction) would be much appreciated.

I'm trying to write a regex (my first one that involves an actual expression instead of a basic search =]) and I'm already stumped. I have expresso dled and I can't get it seem to return the first value i'm even trying to figure out how to get.

Filename i'm working with: [HZ] Veritas 25

Values I'm trying to get returned:
Tags: [HZ]
Series: Veritas
Chapter: 25

I think i can figure out the series and chapter stuff on my own, haven't tried yet, but the brackets i think are throwing off my attempt at the Tags return . . . lil help?
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 6 months ago #3546

  • Yellowbox
  • Yellowbox's Avatar
  • Offline
  • Junior Boarder
  • Posts: 25
  • Thank you received: 10
  • Karma: 3
Square brackets have special meaning in regular expressions (to designate a character class if you care about such things) and so they are reserved characters and cannot be thrown around willy-nilly. I suspect you may not be "escaping" the reserved character, i.e. putting a forward slash (\\) in front of each bracket to tell the Regex engine: "Hey, I really mean these symbols as part of the string, not as what you usually think they mean."

So try this:
(?<Tags>\\[.+?\\]) (?<Series>.+?) (?<Chapter>\\d+)

That should do ya fine.
Last Edit: 8 years 6 months ago by Yellowbox. Reason: Escaping the escape characters for bbCode!
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 6 months ago #3547

  • AltairJr
  • AltairJr's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 9
  • Karma: 0
thanks for responding so quickly, I'll give that a try. I think the pattern of what I needed to do just finally clicked after that post and actually makes sense to me now :laugh:
The administrator has disabled public write access.

Re:Import tags from filename with regular expressi 8 years 2 months ago #4417

  • PaganWolf
  • PaganWolf's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 2
  • Karma: 0
This script will save me a lot of time! I was more than rusty with RegEx so it took me a while to figure...expresso helped a lot tho.

For simple European type comic book (BD) filename patterns using ex:


Filename: Astérix - 01 - Asterix le gaulois.cbz
(?<Series>[^\\]*?) - (?<Number>.+?) - (?<Title>.*)

Filename: Asterix - T01 - Asterix le gaulois.cbz
(?<Series>[^\\]*?) - T(?<Number>.+?) - (?<Title>.*)
The administrator has disabled public write access.
Time to create page: 0.483 seconds

Who's Online

We have 227 guests and 3 members online