Scanning Atari 2600 Roms

RetroArch uses databases from “No-Intro” in scanning for content (to associate roms with cores when generating playlists).

However, there is no database for Atari 2600 roms. No amount of scanning your Atari 2600 roms will result in a playlist.

So, with information provided by Kivutar here, and also from this post (regarding icons for custom playlists), I wrote a semi-robust shell script to generate a playlist from any arbitrary dir containing roms.

My script (below) does NOT handle zip files (like the RetroArch scanner seems to do). It is NOT intelligent about file types in any way, either. However, it does handle paths containing spaces just fine.

Furthermore, to get icons to appear in the main menu gui, you must name your playlist so it conforms with the icon names appearing in this directory… /usr/share/retroarch-assets/xmb/monochrome/png/For instance, your Atari 2600 playlist must be named exactly “Atari - 2600.lpl” because the icon is named “Atari - 2600.png”

You may be able to assign a custom icon to any custom playlist by putting a properly-named icon pair in this directory… /storage/.config/retroarch/assets/xmb/monochrome/png/

Copy the code (way below) and paste it to a new shell script located anywhere you can access (and write to) using ssh I called mine /storage/.config/RomScanner.sh[FONT=arial] [/FONT] [ul] [li]$> vi /storage/.config/RomScanner.sh[/li][li]or $> nano /storage/.config/RomScanner.sh[/li][li][FONT=arial]Remember to make it executable: [FONT=courier new]$> chmod +x RomScanner.sh[/li][/FONT][/FONT] [/ul] [FONT=arial] From the directory where “RomScanner.sh” now lives, call it like this…

[FONT=courier new]$> ./RomScanner.sh "/storage/roms/<Some Rom Dir>" "Atari - 2600.lpl" "/tmp/cores/stella_libretro.so" "Atari 2600 (Stella)"

In theory it should work like this, with the and becoming DETECT in the playlist, but that didn’t work for me. At least not with Atari 2600 roms. [/FONT][/FONT]

$> ./RomScanner.sh "/storage/roms/<Some Rom Dir>" "Atari - 2600.lpl"

Call “RomScanner.sh” with no args to see usage Here’s the script…


#!/bin/sh

################################################################################
## **dfd** ("usury" on libretro.com forums)
##
##   30 Nov 2015     created
##   @see: http://libretro.com/forums/showthread.php?t=4549&p=31622&viewfull=1#post31622
##
##
################################################################################
##
## simple script to scan a directory for roms and create a playlist
## looks at all regular files in and under $SCAN_FQDIR
## !! DOES NOT HANDLE ZIP ARCHIVES !!
##
################################################################################
## Playlists found in "/storage/playlists" have the following format:
## Each rom requires six lines
##  1) rom path
##  2) display name
##  3) path to core [or DETECT]
##  4) name of core [or DETECT]
##  5) CRC          [or DETECT]
##  6) name of playlist
##
## @see http://libretro.com/forums/showthread.php?t=4535&p=31582&viewfull=1#post31582
##
##
##
################################################################################


SCAN_FQDIR=$1
PLAYLIST_NAME=$2
CORE_PATH=$3
CORE_NAME=$4
SCREEN_ONLY=$5


PLAYLIST_FQDIR='/storage/playlists'
PLAYLIST_PATH="${PLAYLIST_FQDIR}/${PLAYLIST_NAME}"
CRC='DETECT'


echoerr() { echo "$@" 1>&2; }




########## ##########
sanity_check()
{
    local fPROBLEM=false


    [[ ! -d "$PLAYLIST_FQDIR" ]] && \
        echoerr " ERROR: Playlist dir not found [$PLAYLIST_FQDIR]" && \
        fPROBLEM=true




    [[ -z "$SCAN_FQDIR" ]] && \
        echoerr " ERROR: <rom dir to scan> is required" && \
        fPROBLEM=true
    [[ ! -z "$SCAN_FQDIR" ]] && \
      { SCAN_FQDIR=$(readlink -f "$SCAN_FQDIR") || \
        { echoerr " ERROR: Fully-qualified path for requested <rom dir to scan> cannot be determined" && \
          fPROBLEM=true; } }
    [[ ! -z "$SCAN_FQDIR" ]] && [[ ! -d "$SCAN_FQDIR" ]] && \
        echoerr " ERROR: Requested <rom dir to scan> does not exist" && \
        fPROBLEM=true




    [[ -z "$PLAYLIST_NAME" ]] && \
        echoerr " ERROR: <name of playlist> is required" && \
        fPROBLEM=true
    [[ ! -z "$PLAYLIST_NAME" ]] && [[ 'lpl' != "${PLAYLIST_NAME##*.}" ]] && \
        echoerr " ERROR: Playlist must end with \".lpl\"" && \
        fPROBLEM=true
    ## nuke existing, or create new $PLAYLIST_NAME in $PLAYLIST_FQDIR
     [[ -z "$SCREEN_ONLY" ]] && [[ ! -z "$PLAYLIST_NAME" ]] && \
      { echo -n "" 2> /dev/null 1> "${PLAYLIST_PATH}" || \
        { echoerr " ERROR: Cannot create playlist with the name you requested" && \
          echoerr "        Full path not supported for <name of playlist>" && \
          fPROBLEM=true; } }






    [[ -z "$CORE_PATH" ]] && CORE_PATH='DETECT' && \
        echoerr " using 'DETECT' for <path to core>"
    [[ 'DETECT' != "$CORE_PATH" ]] && [[ ! -e "$CORE_PATH" ]] && \
        echoerr "ERROR: Requested <path to core> does not exist" && \
        fPROBLEM=true




    [[ -z "$CORE_NAME" ]] && CORE_NAME='DETECT' && \
        echoerr " using 'DETECT' for <name of core>"




    if [[ false != $fPROBLEM ]]; then
        echoerr
        echoerr " USAGE: $0 <rom dir to scan> <name of playlist>"
        echoerr "             [<path to core>|DETECT] [<name of core>|DETECT] [SCREEN-ONLY]"
        echoerr
        echoerr "        pass \"SCREEN-ONLY\" as fifth argument to send output to stdout only"
        echoerr
        echoerr "        make certain you use quotes around args that contain spaces"
        echoerr "        ie. \"/path/with some spaces\" \"Playlist - With Some Spaces.lpl\""
    fi




    [[ false == $fPROBLEM ]] || return 1
}




########## ##########
## helper function - all vars come from caller's scope
## called first time   - output directed to script's stdout
## called second time  - output directed to desired $PLAYLIST_NAME
## all output is quoted in case paths contain multiple consecutive spaces
__one_rom()
{
    local ROM_NAME="$(basename "$ROM_PATH")"


    echo "${ROM_PATH}"
    echo "${ROM_NAME%.*}"
    echo "${CORE_PATH}"
    echo "${CORE_NAME}"
    echo "${CRC}"
    echo "${PLAYLIST_NAME}"


    return 0    # always success
}


########## ##########
main()
{
    local ROM_PATH


    ## suppress status-related messages if doing screen output
    ## (presumably for output redirection)
    if [[ -z "$SCREEN_ONLY" ]]; then
        echo; echo
        echo    "  -- creating playlist \"${PLAYLIST_PATH}\""
        echo    "  -- from ALL roms anywhere under \"${SCAN_FQDIR}\""
        echo -n "  -- generating playlist..."
    fi


    ## read newline-delimited results from sorted "find"
    find "${SCAN_FQDIR}" -type f | sort | while read ROM_PATH; do
        [[ -n "$SCREEN_ONLY" ]] && __one_rom || echo "$(__one_rom)" >> "${PLAYLIST_PATH}"
    done


    [[ -z "$SCREEN_ONLY" ]] && echo "DONE!"
}


sanity_check || exit $?
main || exit $?



I just fixed a bug where my script (above) would nuke an existing playlist in “/storage/playlists/” even when doing “SCREEN-ONLY” output.