Welcome, Guest
Python Scripts for ComicRack

TOPIC: Import tags from filename with regular expressions

Re: Import tags from filename with regular expressions 5 years 10 months ago #20112

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
I am very sorry gravitypool but I could not figure out a regex to fit your examples :(

@Dragonator
The script can be found when right-clicking on a book->Automation->Tags from filename..

This should pull the series for you as long as there is a v right after the series name:
(?<Series>[^\\]*)(?:v\d*)
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 10 months ago #20124

  • Dragonator
  • Dragonator's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
I think I am experiencing the same, or a very similar, issue as gravitypool. Namely, complex regular expressions result in errors even though they work fine in Expresso or Rad Software Regular Expression Designer 1.4

The cases to be considered are as follows:
1. \Series\Title v01 c01-02
2. \Series\Title c01-02
3. \Series\Title - title continuation

First I made a regular expression for each case. Chapters are ignored and the only information necessary is the series name, the title and the volume number. The regular expressions that parse these instances individually are as follows:
1. \\(?<Series>.+?)\\(?<Title>.+)( (v|V)(?=\d)(?<Volume>\d+)?)
2. \\(?<Series>.+?)\\((?<Title>.+)(?:( (c|C)\d)))
3. \\(?<Series>.+?)\\((?!( - ))(?<Title>.+))

All three work perfectly in CR for the instances they are designed for. I then attempted to combine all three into one big catch-all regular expression using nested conditional expressions. This is the result.
\\(?<Series>.+?)\\(?(.+ (v|V)\d)(?<Title>.+)(?<Title>.+)( (v|V)(?=\d)(?<Volume>\d+)?)|((?(?!(\D c\d))(?<Title>.+)(?:( (c|C)\d)))|(((?!( - ))(?<Title>.+)))))

It works as intended in both Expresso and Rad Software Regular Expression Designer 1.4 but when applied in CR an error occurs in cases 2. and 3. but not in case 1.. When I run the expression on case 1 the information is properly captured and updated without any other warning or message. Both in cases 2. and 3. the same behavior is observed: the information appears to be properly captured and updated in the list but the script stops, not progressing to the next entry in the list, and an error message is displayed with an audible tone. The error message is a pop-up window with the title: "Execution of the script failed!" and the message "Exception has been thrown by the target of an invocation."

Considering this, along with gravitypool's post I concluded that it most likely is an issue of either the script or the CR application itself. I haven't bothered to look into them more deeply yet but I figured "filing a bug report" is the least I can do for now.
Last Edit: 5 years 10 months ago by Dragonator.
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 10 months ago #20132

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
There do appear to be some problems with the script.

Can you try the attached version and tell me if it works correctly? I've changed so it should work exactly the same as Expresso.
Attachments:
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 10 months ago #20133

  • Yellowbox
  • Yellowbox's Avatar
  • Offline
  • Junior Boarder
  • Posts: 25
  • Thank you received: 10
  • Karma: 3
You beat me to the punch, Stonepaw, but thanks. Dragonator gave me Abandonware Guilt, so I was just working on a fix this afternoon.

Bet you looked at all those boolean checks and threw up a little in your mouth. Ditto here. Of course, it's a very old script and my very first Python experience. Also, cheers on using the .NET regex engine. I think a lot of problems got thrown because of the different syntax for named groups:
.NET:
(?<Writer>.*)

Python:
(?P<Writer>.*)
I mean, honestly, there's no need for the P. (That's what she said.)

Anyhoo, brilliant work, Stonepaw. And thanks for taking the initiative on, oh I don't know, everything.
Last Edit: 5 years 10 months ago by Yellowbox.
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 10 months ago #20134

  • Stonepaw
  • Stonepaw's Avatar
  • Offline
  • Moderator
  • Posts: 921
  • Thank you received: 268
  • Karma: 173
Yellowbox wrote:
You beat me to the punch, Stonepaw, but thanks. Dragonator gave me Abandonware Guilt, so I was just working on a fix this afternoon.
I didn't know if you were still around so I figured I would do a quick fix. Feel free to put your own version out.
Bet you looked at all those boolean checks and threw up a little in your mouth. Ditto here.
Yeah a little bit :laugh:
Anyhoo, brilliant work, Stonepaw. And thanks for taking the initiative on, oh I don't know, everything.
You're welcome :)
Last Edit: 5 years 10 months ago by Stonepaw.
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 10 months ago #20136

  • Dragonator
  • Dragonator's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Stonepaw wrote:
There do appear to be some problems with the script.

Can you try the attached version and tell me if it works correctly? I've changed so it should work exactly the same as Expresso.

This version seems to be working fine in all 3 instances with both the individual expressions and the combined expression, indeed behaving the same as Expresso.

Thank you and good work.
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 10 months ago #20145

Wow, thanks for the update Stonepaw. Can't wait to try out when i get home.
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 7 months ago #22080

  • JamesBolivar
  • JamesBolivar's Avatar
  • Offline
  • Junior Boarder
  • Posts: 29
  • Thank you received: 2
  • Karma: 1
Since i really like this script and use it oftenly, i made some minor changes to it

a) added an icon to start it from browser toolbar
b) exit when no book selected
c) preload default pattern

Now i am trying to change the default path for patterns because it would need admin rights to write in the program folder which isn't the way to go. Now i ran into a problem because i can't find a way to address the userpath.

Does anybody know how to do this?
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 7 months ago #22097

  • tcm1998
  • tcm1998's Avatar
  • Offline
  • Expert Boarder
  • Posts: 94
  • Thank you received: 16
  • Karma: 6
JamesBolivar wrote:
Since i really like this script and use it oftenly, i made some minor changes to it

a) added an icon to start it from browser toolbar
b) exit when no book selected
c) preload default pattern

Now i am trying to change the default path for patterns because it would need admin rights to write in the program folder which isn't the way to go. Now i ran into a problem because i can't find a way to address the userpath.

Does anybody know how to do this?

Enviroment.GetFolderPath (Environment.SpecialFolder.Personal) is the dotnet call you need, I think.

Slightly off-topic:

I am working on a successor for this script and it's nearly ready for beta release. In my plugin you see a list of paths extracted from the booklist. As you type the regex, the list shows added columns for any properties in the regex and values in the list are automatically updated when the regex is valid. All of this happens live as you type. Each list entry has a checkmark in front of it, so you can select which of the results you actually want to apply to the books.

I was going to release it yesterday, but I overlooked something in the apply-function. Hopefully i'll be able to launch it somewhere this weekend ( if real life doesn't keep me busy too much). I'll open up a new topic on launch.

I haven't implemented any load/save of regexes yet(can't be hardanyway), but howmany regexes do users have saved?
I'd like to know, because because I want to put all saved regexes in a combobox.
Just madly collecting (dutch) comics
The administrator has disabled public write access.

Re: Import tags from filename with regular expressions 5 years 7 months ago #22104

  • JamesBolivar
  • JamesBolivar's Avatar
  • Offline
  • Junior Boarder
  • Posts: 29
  • Thank you received: 2
  • Karma: 1
tcm1998 wrote:
I haven't implemented any load/save of regexes yet(can't be hardanyway), but howmany regexes do users have saved?
I'd like to know, because because I want to put all saved regexes in a combobox.

I use three different ones. They should be editable, changable and choosable with one default.

Attached is the version Stonepaw made with some changes made by me:

File Attachment:

File Name: TagsFromNa...crplugin
File Size:4 KB


It has an icon in the browser toolbar now, uses it's own folder (Tagpatterns) in User/Documents, that gets created if it doesn't exist, and preloads a default pattern (TagPattern.txt) from this folder if it exists. Path for Load and Save is always this folder. This version exits when no book is chosen.
Last Edit: 5 years 7 months ago by JamesBolivar.
The administrator has disabled public write access.
The following user(s) said Thank You: jeroenwalter
Time to create page: 0.251 seconds

Who's Online

We have 194 guests and 2 members online