Using symlinks to match artwork

A nice (keyboard based) front end for Arcade / Console game emulators.

Moderator: battlecat

Using symlinks to match artwork

Postby snaff » Fri Nov 01, 2013 8:52 pm

I'm setting up Wahcade as a C64/Vice frontend. I have an archive of screenshots that have nice tidy names, and a collection of disk images with messy names. So a screenshot might be:

Green_Beret.png

while the disk image has a name like:

Green_Beret.Imagine.+2p-NO.zip

So I made a perl script that fuzzy matches two lists and creates symlinks with the name of one pointing to the other. It uses the Levenshtein algorithm where 'foo' and 'four' have a 'distance' of 2, because it takes two edits to get from one to the other. It picks the best match between the lists and ignores any string that needs more than 25% of it editing to get a match.

To use it ls screenshots/>screenshots.txt, ls games/>games.txt and run script.pl>mklinks.sh and it will build a script that makes symlinks.

Code: Select all
#!/usr/bin/perl -w

use strict;
use Text::LevenshteinXS qw(distance);

my @screenshots;
open (SS, 'screenshots.txt');
while (<SS>) {
   chomp;
   push(@screenshots, $_);
}
close (SS);

my @games;
open (GM, 'games.txt');
while (<GM>) {
   chomp;
   push(@games, $_);
}
close (GM);

foreach(@screenshots) {
   my $screenshot=$_;
   my $best_score=999;
   my $best_match="";

   my $rscreenshot=$screenshot;
   $rscreenshot=~s/\..*//;
   my $slen=length $rscreenshot;

   foreach(@games) {
      my $game=$_;

      my $rgame=$game;
      $rgame=~s/\..*//;

      my $score=distance(lc($rscreenshot), lc($rgame));
      $score=$score/$slen;

      if($score<$best_score) {
         $best_score=$score;
         $best_match=$game;
      }
   }

   if($best_score<0.25) {
      print 'ln -s "../../games/all/'.$best_match.'" "games/'.$rscreenshot.'.zip"';
      print "\n";
   }
}


Edit to suit your fancy.
snaff
 
Posts: 5
Joined: Thu Oct 31, 2013 9:28 pm

Re: Using symlinks to match artwork

Postby General_Faliure » Sat Nov 02, 2013 7:21 am

Nice. So far i have been using a windows program for that: Fuzzyrename. (works in Wine)
My Arcade cab: https://goo.gl/photos/yE1KACHryQjCaaCj7
Core 2 duo 8400 @3600, 4 gig mem, Geforce 9500. Mame, Mess, Daphne, and some more.
Mah!cade
User avatar
General_Faliure
 
Posts: 154
Joined: Sat Mar 20, 2010 12:51 pm
Location: Drunen, Netherlands

Re: Using symlinks to match artwork

Postby General_Faliure » Wed Nov 06, 2013 11:11 am

can you elaborate a bit more about how it works?
I created a new folder called rename.
I have put my game roms (nintendo) in a subfolder named games and my pics in a subfolder named screenshots.
I copied the script text to leafpad and saved it as script.pl in the rename folder.
The first two commands work; i get screenshots.txt and games.txt.
The last command does not seem to work; i get, command not found.
I do get a file mklinks.sh, which is empty.
I know very little about perl and scripts, so i am probably doing something wrong
My Arcade cab: https://goo.gl/photos/yE1KACHryQjCaaCj7
Core 2 duo 8400 @3600, 4 gig mem, Geforce 9500. Mame, Mess, Daphne, and some more.
Mah!cade
User avatar
General_Faliure
 
Posts: 154
Joined: Sat Mar 20, 2010 12:51 pm
Location: Drunen, Netherlands

Re: Using symlinks to match artwork

Postby sairuk » Wed Nov 06, 2013 10:46 pm

is Text::LevenshteinXS a standard perl package? might need to see if that is installed General Failure, install it through the cpan command. It's been a while since i did anything with perl but that's the only thing that stands out for me.

Run the last command without the redirect and see if the script errors on a missing package.

Interesting idea none the less, I'd started something similar to build artwork dats for clrmamepro many years ago for Mame!Wah.

Is the OP using Wah!Cade or the Mah!Cade? I only ask as fuzzy artwork matching is included in the experimental branch (Mah!Cade) on launchpad and I'd be interested to see some examples where the fuzzy artwork regex is not working successfully so we have the opportunity to improve it.

I use the same regex in other projects so am keen to make it all encompassing.
mameau - My random bits | Wah!Ki - A Wah!Cade wiki | Mah!Cade - Experimental Wah!cade Branch | ListGen | Lazarus
User avatar
sairuk
 
Posts: 432
Joined: Sat May 22, 2010 12:37 am

Re: Using symlinks to match artwork

Postby General_Faliure » Thu Nov 07, 2013 4:10 pm

I found i did have to install the LevenshteinXS package. ( did it with Synaptic).
Now i got the script to run. (in Gnome commander: execute), but i don't know where the symlinks went.
I use Fuzzyrename to better match the games to the pictures, i get a better result then using just fuzzy artwork.
My Arcade cab: https://goo.gl/photos/yE1KACHryQjCaaCj7
Core 2 duo 8400 @3600, 4 gig mem, Geforce 9500. Mame, Mess, Daphne, and some more.
Mah!cade
User avatar
General_Faliure
 
Posts: 154
Joined: Sat Mar 20, 2010 12:51 pm
Location: Drunen, Netherlands

Re: Using symlinks to match artwork

Postby sairuk » Thu Nov 07, 2013 11:18 pm

General_Faliure wrote:I found i did have to install the LevenshteinXS package. ( did it with Synaptic).
Now i got the script to run. (in Gnome commander: execute), but i don't know where the symlinks went.
I use Fuzzyrename to better match the games to the pictures, i get a better result then using just fuzzy artwork.


FuzzyRename looks interesting, had a quick look at the source it doesn't use regex and the method it uses will give you [a] codes, etc. fuzzy artwork cuts these items down to the bare game name which (in theory) should give you 1 artwork across all variants of the same game, correct or otherwise. Maybe something we can improve.
mameau - My random bits | Wah!Ki - A Wah!Cade wiki | Mah!Cade - Experimental Wah!cade Branch | ListGen | Lazarus
User avatar
sairuk
 
Posts: 432
Joined: Sat May 22, 2010 12:37 am

Re: Using symlinks to match artwork

Postby snaff » Sat Nov 09, 2013 9:29 pm

sairuk wrote:Is the OP using Wah!Cade or the Mah!Cade? I only ask as fuzzy artwork matching is included in the experimental branch (Mah!Cade) on launchpad and I'd be interested to see some examples where the fuzzy artwork regex is not working successfully so we have the opportunity to improve it.

I use the same regex in other projects so am keen to make it all encompassing.


I was using Wahcade but am using Mahcade now. The built-in fuzzy matching seems to work great. My c64 disk images are all a disorganised mess though, so this script allowed me to use a nicely named list of images to point into them so I get a tidy game list as well.

Now I'm adding other systems I don't have to do anything non-standard, except for Amiga, where I'm using a script to build a list of matching disk images to attach for any given game.
snaff
 
Posts: 5
Joined: Thu Oct 31, 2013 9:28 pm

Re: Using symlinks to match artwork

Postby snaff » Sat Nov 09, 2013 9:32 pm

General_Faliure wrote:I found i did have to install the LevenshteinXS package. ( did it with Synaptic).
Now i got the script to run. (in Gnome commander: execute), but i don't know where the symlinks went.
I use Fuzzyrename to better match the games to the pictures, i get a better result then using just fuzzy artwork.


It should output the list to standard output when you run it from a terminal. I had it create a script rather than actually do anything itself so the output could be sanity checked, rather than letting it do anything crazy.
snaff
 
Posts: 5
Joined: Thu Oct 31, 2013 9:28 pm

Re: Using symlinks to match artwork

Postby sairuk » Mon Nov 11, 2013 8:41 am

snaff wrote:Now I'm adding other systems I don't have to do anything non-standard, except for Amiga, where I'm using a script to build a list of matching disk images to attach for any given game.


I just had a few problems with Amiga roms over the weekend, nothing explicitly mahcade related am building myself an offline disk/c catalogue which was falling over on some names.

I can't remember what set mine was, been a long time since i looked at amiga,(there was a disk format that was a plugin for UAE some years ago) although i may add support to my setup shortly as I am planning to move forward with setting up more systems.

Need to improve the layout loading tho, it's really slow the more complex you go
mameau - My random bits | Wah!Ki - A Wah!Cade wiki | Mah!Cade - Experimental Wah!cade Branch | ListGen | Lazarus
User avatar
sairuk
 
Posts: 432
Joined: Sat May 22, 2010 12:37 am


Return to Wah!Cade

Who is online

Users browsing this forum: No registered users and 3 guests

cron