#1 2015-09-21 15:49

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Capture possible text at the end of string then insert it in...

Hi deb4b and company!!

Time ago I find a solution for an specific problem with your help, I hope this time I'm in the right place again! thanks for support.

Let's go...

I have some files with filenames like this one:

  • 03 - AIN'T ABOUT TO STOP (feat. Rita Ora)

  • 04 - LIKE A MACK (feat. Curly Fryz)

  • 09 - MR. NELSON (feat. Lianna La Havas)

Notice the 'featuring artist' part inside the parenthesis, well, basically I would like to extract that part of the string, and I know how to do it ...its easy with RegEx, the problem is about how to insert again the extracted text in an specific position, because I'm using a custom preset to change the '0n - ' part of the start of string, and I would like to append the extracted "feat..." at the end of that replacement.

My english is bad, I'll show examples:

Having this filename:
03 - AIN'T ABOUT TO STOP (feat. Rita Ora)

My current preset renames it like this:
Artist - Ain't About To Stop
(where "Artist" Is a value that I should set in the preset before renaming)

And I would like to rename it like this:
Artist feat. Rita Ora - Ain't About To Stop

What workarounds I have to accomplish this?

Maybe this other recent question could help for something?
www.den4b.com/forum/edit.php?id=9067

--------------------------------------------------------------------------------

This below is my current preset.

Mention that the rule nº1 replaces the first part of the string "nn -" for "|", the rule nº2 modifies "|" to "Artist" name, and the rule nº8 is where I work the "feat..." part, well, by the moment I just remove the "feat..." string because I can't do nothing better, but I will improve my script to extract and re-insert instead of fully removing that important info of the tracks.

EDIT: In the rule nº6 I format the "feat." to "featuring" for those "feat..." strings that are out of parenthesis, which commonly always are positioned at the start of the string appended to the artist name, just where I want to extract and insert that info.

Music - Albums (Untitled).rnp

[Rule0]
ID=RegEx
Config=EXPRESSION:%28%5E%28%5Cs%2B%29%3F%5Cd%2B%28%5Cs%2B%29%3F%5B%2D%5C%2E%5D%29%7B1%7D%7C%28%5E%28%5Cs%2B%29%3F%5Cd%2B%5B%2D%5F%5Cs%5D%2B%29%7B1%7D%7C%28%5E%28%5Cs%2B%29%3F%5BA%2DD%5D%7B1%7D%28%5B0%2D9%5D%7B1%7D%29%5Cs%2B%3F%29%7B1%7D;REPLACE:%7C+%2D+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule1]
ID=Replace
Config=TEXTWHAT:%7C;TEXTWITH:Artist;WHICH:1;SKIPEXTENSION:1;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule2]
ID=CleanUp
Config=BRACKETSROUND:0;BRACKETSSQUARE:1;BRACKETSCURVY:0;SPACESDOT:0;SPACESCOMMA:0;SPACESUNDERSCORE:1;SPACESPLUS:0;SPACESHYPHEN:0;SPACESWEB:0;SPACESSKIPVERSIONS:0;SPACESFIX:1;SKIPEXTENSION:1;PREPAREFORSHAREPOINT:0;INSERTSPACEBEFORECAPITALS:0;NORMALIZESPACES:1
Marked=1

[Rule3]
ID=Translit
Config=ALPHABET:+%2D+Web+%2D+2014%3D%0D%0A+%40+%3D+at+%0D%0A+aint+%3D+Ain%27t+%0D%0A+and+%3D+%26+%0D%0A+can+t+%3D+Can%27t+%0D%0A+cant+%3D+Can%27t+%0D%0A+comin+%3D+Comin%27+%0D%0A+Corazon+%3D+Coraz%C3%B3n+%0D%0A+dancin+%3D+Dancin%27+%0D%0A+didnt+%3D+Didn%27t+%0D%0A+djs+%3D+Dj%27s+%0D%0A+don+t+%3D+Don%27t+%0D%0A+dont+%3D+Don%27t+%0D%0A+Dr+%3D+Dr%2E+%0D%0A+flyin+%3D+Flyin%27+%0D%0A+i+ll+%3D+I%27ll+%0D%0A+ill+%3D+I%27ll+%0D%0A+im+%3D+I%27m+%0D%0A+it+s+%3D+It%27s+%0D%0A+its+%3D+It%27s+%0D%0A+ive+%3D+I%27ve+%0D%0A+lets+%3D+Let%27s+%0D%0A+meets+%3D+%26+%0D%0A+thats+%3D+That%27s+%0D%0A+versus+%3D+Vs%2E+%0D%0A+vs+%3D+Vs%2E+%0D%0A+walkin+%3D+Walkin%27+%0D%0A+wont+%3D+Won%27t+%0D%0A+youll+%3D+You%27ll+%0D%0A+youre+%3D+You%27re+%0D%0A%22%3D%27%0D%0A%27remix%3DRemix%0D%0A%27rmx%3DRemix%0D%0A%28%28%3D%28%0D%0A%28Demo+Mix%29%3D%28Demo+Version%29%0D%0A%28Demo%29%3D%28Demo+Version%29%0D%0A%28Dub%29+%3D+%28Dub+Mix%29%0D%0A%28Extended%29%3D%28Extended+Mix%29%0D%0A%28Instrumental%29%3D%28Instrumental+Mix%29%0D%0A%28Radio%29%3D%28Radio+Mix%29%0D%0A%28Vocal%29%3D%28Vocal+Mix%29%0D%0A%29%29%3D%29%0D%0A%2B%C2%A1%3D%C3%AD%0D%0AD%2EJ%2E%3DDj%0D%0AD%2EJ%3DDj%0D%0ADJ%2E%3DDj%0D%0AMash+%2D+up%3DMashup%0D%0AMash+up%3DMashup%0D%0AMash%2Dup%3DMashup%0D%0ARemix+Version%3DRemix%0D%0ARmx%3DRemix%0D%0Au%CC%88%3Du%0D%0A%7B%3D%28%0D%0A%7D%3D%29%0D%0A%7E%3D%0D%0A%C2%A1%3D%0D%0A%C2%BF%3D%0D%0A%C3%AA%3De%0D%0A%C3%94%C3%87%C2%AA%3D%2E%2E%2E%0D%0A%C3%94%C3%87%C3%B4%3D%2D%0D%0A%C3%94%C3%87%C3%96%3D%27%0D%0A%C3%96%3Do%0D%0A%D0%A1%3Dc%0D%0A%E2%80%93%3D%2D%0D%0A%E2%80%99%3D%27%0D%0A%2B%C2%A6%3D%C3%B1%0D%0A%2B%C3%AD%3D%C3%A1%0D%0A%E2%94%9C%C2%A1%3D%C3%AD%0D%0A%E2%94%9C%C2%AE%3D%C3%A9%0D%0A%E2%94%9C%C2%BD%3De%0D%0A%E2%94%9C%C2%BF%3D%C3%A8%0D%0A%E2%94%9C%E2%94%82%3D%C3%B3%0D%0A%E2%94%9C%E2%95%91%3D%C3%BA%0D%0A%C3%B0%C2%A2%3D%C3%AD%0D%0A%E2%94%9C%E2%96%92%3D%C3%B1;DIRECTION:1;SKIPEXTENSION:1
Marked=1

[Rule4]
ID=RegEx
Config=EXPRESSION:%5C%28Original+%28Mix%7CVersion%29%5C%29;REPLACE:;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule5]
ID=RegEx
Config=EXPRESSION:%5C%28%28Bonus%7CHidden%29+Track%5C%29;REPLACE:;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule6]
ID=RegEx
Config=EXPRESSION:+ft%5C%2E%3F+%7C+feat%5C%2E%3F+%7C+featuring+;REPLACE:+Feat%2E+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule7]
ID=RegEx
Config=EXPRESSION:%5C%28featuring+%2E%2B%5C%29%7C+%5C%28feat%28%5C%2E%29%3F+%2E%2B%5C%29%7C%5C%28ft%28%5C%2E%29%3F+%2E%2B%5C%29%7C;REPLACE:;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule8]
ID=CleanUp
Config=BRACKETSROUND:0;BRACKETSSQUARE:0;BRACKETSCURVY:0;SPACESDOT:0;SPACESCOMMA:0;SPACESUNDERSCORE:0;SPACESPLUS:0;SPACESHYPHEN:0;SPACESWEB:0;SPACESSKIPVERSIONS:0;SPACESFIX:1;SKIPEXTENSION:1;PREPAREFORSHAREPOINT:0;INSERTSPACEBEFORECAPITALS:0;NORMALIZESPACES:0
Marked=1

[Rule9]
ID=Case
Config=WHAT:3;SKIPEXTENSION:1;EXTENSIONALWAYSLOWERCASE:1;EXTENSIONALWAYSUPPERCASE:0;FORCECASE:0;FRAGMENTSTEXT:
Marked=1

[Filters]
AddFilesFromFolders=1
AddFoldersAsFiles=0
IncludeSubfolders=1
IncludeHidden=0
IncludeSystem=0
SkipRootFoldersAsFiles=0
MasksOnFileName=1
Masks=

Last edited by Elektro (2015-09-21 16:14)

Offline

#2 2015-09-21 21:23

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Capture possible text at the end of string then insert it in...

RegEx expression:

\A([^\-]*?)\s*\-\s*(.*?)\s*\((feat[^\)]*)\)\Z

replace with:

$1 $3 - $2

Input file names:

Artist - AIN'T ABOUT TO STOP (feat. Rita Ora).mp3
Artist - LIKE A MACK (feat. Curly Fryz).mp3
Artist - MR. NELSON (feat. Lianna La Havas).mp3

Output file names:

Artist feat. Rita Ora - AIN'T ABOUT TO STOP.mp3
Artist feat. Curly Fryz - LIKE A MACK.mp3
Artist feat. Lianna La Havas - MR. NELSON.mp3

Offline

#3 2015-09-22 23:50

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Re: Capture possible text at the end of string then insert it in...

Thanks a lot @den4b.

I made a little improvement to the expression (I mean for my needs):

\A([^\-]*?)\s*\-\s*(.*?)\s*[\(\[]((ft[\.\s]|feat[\.\s]|featuring\s)[^\)]*)[\)\]](.+)?\Z

Replace with:

$1 $3$4 - $2 $5

That way avoid similar words like "feather", also matches a "[ft|feat|featuring...]" enclosed in brackets and is able to match possible noise after the "(feat...)" string, just any additional text it could exist like codec info or spam of music scene names, otherwise the expression will not work.

Really thankyou, your expression design (with that little modification added) seems very safe applied to all filename scenarios, much more safer than the RegEx that I could build from scratch, but I also did a good job adding the improvement hehe!.

Last edited by Elektro (2015-09-23 02:02)

Offline

#4 2015-09-23 02:29

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Re: Capture possible text at the end of string then insert it in...

I have a problem in this scenario sad

Filename:

kill the noise - all in my head feat. awolnation (batou mix)

Current RegEx:

\A([^\-]*?)\s*\-\s*(.*?)\s*[\(\[]((ft[\.\s]|feat[\.\s]|featuring\s)[^\)]*)[\)\]](.+)?\Z

Current Replace For:

$1 $3 - $2$5

Could you help me with this?


The logic I desire is:

1st condition:
  Match 'ft|feat|featuring' full string even if it is not enclosed in parentheses/brackets.

2nd condition:
  Stop the match capture when an special character of these is found after the first condition: ()[]{}, and only those chars, not special unicode chars because an artist name can have a japanese or other special chars for example:
feat. Mister 漢字仮--名交じり文 [usa remix].


Illustrative Match and Replacement Examples:

From:
kill the noise - all in my head feat. awolnation (batou mix)

To:
kill the noise feat. awolnation - all in my head (batou mix)


From:
artist - track name feat. Mister 漢字仮--名交じり文 [usa remix]

To:
artists feat. Mister 漢字仮--名交じり文 - track name [usa remix]

------------------------------------------------------------------

Edit:

I'm close, this expression seems to solve the conditions above:

RegEx:

\A([^\-]*?)\s*\-\s*(.*?)\s*([\(\[])?((ft[\.\s]|feat[\.\s]|featuring[\.\s])[^\(\)\{\}\[\]]*)([\)\]])?(.+)?\Z

Replace For:

$1 $4 - $2$7

However, it fails when a "-" char is found before the "feat", like in this filename:

kill th-e noise - all in my head (feat awolnation)

It renames it as:

Kill Th Feat. Awolnation - E Noise - All In My Head

Very close...! sad

Help!.

thanks!

Last edited by Elektro (2015-09-23 06:03)

Offline

#5 2015-09-23 11:32

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Capture possible text at the end of string then insert it in...

Elektro wrote:

However, it fails when a "-" char is found before the "feat", like in this filename

You can enforce existence of spaces on both sides of "-" by changing:

\s*\-\s*

to:

\s+\-\s+

("*" is 0 or more, "+" is 1 or more)

But then you also need to change the begining:

\A([^\-]*?)

possibly to:

\A(.*?)

Offline

#6 2015-09-23 13:31

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Re: Capture possible text at the end of string then insert it in...

Thanks den4b but that modification you specified didn't worked with the last example I mentioned:

kill th-e noise - all in my head (feat awolnation)

I'm trying to figure why.

sad

Last edited by Elektro (2015-09-23 13:32)

Offline

#7 2015-09-23 14:42

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Re: Capture possible text at the end of string then insert it in...

den4b, finally I deducted it will be impossible to predict when the artists name should be separated from the track name because the "-", its impossible to predict when to stop capturing like in a filename like this:

Dj E-nergy C-21 - My Super-hero track! (feat Dj Ass-hole)

Impossible to separate Dj E-nergy C-21 from My Super-hero track! unless I know the exact amount of "-".

So, I'll ask you for help with a simpler idea, sorry for the task I'm giving you.

I would like to "limit" this expression:

\A([^\-]*?)\s*\-\s*(.*?)\s*([\(\[])?((ft[\.\s]|feat[\.\s]|featuring[\.\s])[^\(\)\{\}\[\]]*)([\)\]])?(.+)?\Z

To work ONLY when filename has ONE "-" char BEFORE the "feat...", like this:

Artist - Track (possible feat. Artist)
Artist - Track (possible feat. composed-name)

Then AVOID modifying the string when it has more than 1 "-" char BEFORE the "feat...", like this:

Artist composed-name - Track (possible feat. Artist)

I imagine this will be easier to design, and a safer solution. Just an exclusion for filenames that has more than "-" char BEFORE the "feat...".

I know that to limit the matches of "-" to 1, I could use a grouping with {1}, but I'm not sure how to implement it in your expression.

Thanks!

Last edited by Elektro (2015-09-23 19:53)

Offline

#8 2015-09-27 13:06

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Re: Capture possible text at the end of string then insert it in...

I really need help with this, den4b, if you could please look at the question I made on StackOverflow, there I explain perfectly my needs:

-> RegEx pattern to limit dashes in these circunstances

Thanks

Last edited by Elektro (2015-09-27 13:06)

Offline

#9 2015-10-04 18:57

Elektro
Senior Member
Registered: 2014-05-28
Posts: 76

Re: Capture possible text at the end of string then insert it in...

Well... I solved it...

// Formats an audio filename that has the "...featuring artist" part at the end of filename.
//------------------------------------------------------------------------------------------


// Pseudo-Example:
//
// From: [0]ARTIST_NAME  [1]DASH  [2]TRACK_TITLE  [3]FEAT_ARTIST  [4]POSSIBLE_ADDITIONAL_INFO_INSIDE:()[]{}
// To:   [0]ARTIST_NAME  [3]FEAT_ARTIST  [1]DASH  [2]TRACK_TITLE  [4]POSSIBLE_ADDITIONAL_INFO_INSIDE:()[]{}

// Real-Example:
//
// From: Carbin & Sirmark - Sorry Feat. Sevener.mp3
// To:   Carbin & Sirmark Feat. Sevener - Sorry.mp3

// Known limitations:
//
// • If [0]ARTIST_NAME or [2]TRACK_TITLE parts contains any " - " the script will not work properlly.
//   By default the script prevents any replacement on that kind of filenames, so don't worry.


var
  rgxPattern: string;
  rgxReplace: string;
  dashCount: integer;
  baseName: string;
  extension: WideString;

begin

  baseName  := WideExtractBaseName(FileName)
  extension := WideExtractFileExt(FileName);

  // The regular expression that matches the filename parts.
  // http://stackoverflow.com/questions/32807698/regex-pattern-to-limit-dashes-in-these-circumstances
  rgxPattern := '^(.+)\s+-\s+(.+?)\s+[fF](t|eat(uring)?)?\.?([^([\])\n]+)(.+)?$'
  rgxReplace := '$1 Feat.$5 - $2$6'

  // The amount of " - " that contains the filename.
  dashCount := high(MatchesRegEx(baseName, '\s-\s' , false));

  // If only one " - " is found then...
  If (dashCount = 0) Then
    begin // Do the replacement.
      baseName := ReplaceRegEx(baseName, rgxPattern, rgxReplace, false, true)
      FileName := baseName + extension;
    end;

end.

Offline

Board footer

Powered by FluxBB