Site
Home / Forum / General Discussion / Anyone good with Regex or filebot

Anyone good with Regex or filebot


Posted: 02 May 2022 07:55
Retrorat1
Posts: 32
Joined: 2020-06-25

Hi All,
So with the latest update for SportScanner, it is working wonderfully for me so big thanks to everyone involved.
Next is there anyone who knows they way around filebot for the naming conversions? or experts with Regex
I posted in the filebot forum but got the use the plain text with no explanation on how to do it, so thought someone here might be better equipped to handle such a request.

I have been looking at ways to take parts of the file name and make a new one that will work with The Sports DB this is one example

EPL 2009 Aston Villa vs Wigan 08 14 720pEN60fps WhAma.mp4
this is the file I have and I need to extract certain bits from the file name and discard the rest to make it look like this
English.Premier.League.2009-08-14.Aston.Villa.vs.Wigan

So EPL - English.Premier.League
2009 - 2009-08-14
Aston Villa - Aston.Villa
Wigan - Wigan
702p onwards get deleted.

Is there a way to do it? basically I am looking at splitting the file name (EPL) (2009) (Aston Villa) vs (Wigan) (08) (14) (720pEN60fps) (WhAma).mp4 so the spaces will be the bookmarks for isolatation

I am no coder of programmer but what I see is possibility in a formula
First we find all numbers involved
so 2009, 08,14,720,60
next find if there is 720
and remove everything up till the extension from there
next the remaining numbers assigned tags
2009 -(a)
08 - (b)
14 - (c)
next the strings left
EPL (d)
name before vs replace space with(.) - (e)
name after vs replace space with(.) - (f)

now put it together (d).(a)-(b)-(c).(e).vs.(f).ext
In my head it seems simple but in actual real life lol is best to aske some one who understands regex type problems.

Any advice in doing this will be greatly appreciated .

Thanks

Posted: 03 May 2022 00:57
daveyjake
Posts: 4
Joined: 2022-05-03

What language are you using? If PHP, I would use this approach:

// Original string.
$str = 'EPL 2009 Aston Villa vs Wigan 08 14 720pEN60fps WhAma.mp4';

// Get the primary substring.
preg_match_all( '/^(.*)(?= 720)/', $str, $matches );
$str = $matches[1][0]; // EPL 2009 Aston Villa vs Wigan 08 14

// Format the date.
preg_match_all( '/\s\d{2,4}/', $str, $parts );
$parts = array_map( 'trim', $parts[0] ); // array( '2009', '08', '14' )
$date = sprintf( '%1$s-%2$s-%3$s', $parts[0], $parts[1], $parts[2] ); // 2009-08-14

// Remove date $parts from original string.
$str = preg_replace( '/\s\d{2,4}/', '', $str ); // EPL Aston Villa vs Wigan

// Replace all whitespaces with a dot (.).
$str = preg_replace( '/\s/', '.', $str );

// Replace `EPL` with `English.Premier.League.$date`.
$str = preg_replace( '/EPL/', sprintf( 'English.Premier.League.%s', $date ), $str );

echo $str; // English.Premier.League.2009-08-14.Aston.Villa.vs.Wigan

The whole solution can be viewed online here: https://sandbox.onlinephpfunctions.com/c/47a3a


zag
Posted: 03 May 2022 06:10
Retrorat1
Posts: 32
Joined: 2020-06-25

Wow that is exactly what I was looking to do. Thank you very much. I thought my idea would only live in my head lol.
Now to implement it in the EPL directory and do it to each new file transferred there.
Thank you once again

daveyjake
Posted: 05 May 2022 19:56

zag
Posts: 3,331
Joined: 2020-03-23

Awesome, thanks for the help


Who is Online?

In total there are 68 users online :: 3 registered, 0 hidden and 65 guests (based on users active over the past 5 minutes) Most users ever online was 424 on Fri Nov 10, 2017 9:02 pm

About Us

Discussion forum for TheSportsDB.com site and related topics

Rules

- Be Polite
- Respect other users
- Always post log files with issues
- Try to be helpful
- No Piracy discussion

Showing 0 to 4 (Total: 4)