1
Scripting / Re: is it possible to check video artwork file exist or not
« on: February 22, 2022, 10:58:44 PM »
I'm working on a layout and needed something similar. Here's a modified version that could work for you. Note: I modified this from my original code and didn't test run it, I may have typos but the core logic is the same.
The function GetArtOfType() will return a filename if it matches your criteria or empty string if nothing is found for example:
local fileName = GetArtOfType(0, "");
fileName could equal an asset name found in the "video" subfolder with any extension .mp4, .avi, .mkv etc...
local fileName = GetArtOfType(0, ".mp4");
Performs the same search but only return a filename if it contains ".mp4" in the name.
Code:
// Configure the root art folder such as /emu/artwork you can get the value from UserConfig or hard code if you like
local g_baseArtFolder = my_config["baseArtFolder"];
// List of media folders that can be searched. The index parameter in GetArtOfType refers to this list
local g_mediaFolders = ["video","snap","flyer"];
// Store files in found in folders to avoid performing the directory search each time
local g_assetFileNames = [];
/////////////////////////////////////////////////////////////////////////
// Get the asset file of a given type if it exists
//
// \param mediaIndex - Index into your media folder list to use for lookup
// \param extension - Specific file extension if desired, otherwise first match will be returned
//
/////////////////////////////////////////////////////////////////////////
function GetArtOfType(mediaIndex, extension)
{
// Note this assumes assets are stored in system folders such as /emu/artwork/atari2600/video
// where the system name comes from the emulator name you use in AM. If you do not use that
// structure edit below to match
local baseName = g_baseArtFolder + "/" + fe.game_info(Info.Emulator) + "/" + g_mediaFolders[mediaIndex];
local gameName = fe.game_info(Info.Name) + ".";
// Only get the directory listing 1 time
if (g_assetFileNames[mediaIndex] == null)
{
g_assetFileNames[mediaIndex] = DirectoryListing(baseName).results;
}
// Determine if a file in the target folder matches the active game and optionally the desired extension
foreach (filename in g_assetFileNames[mediaIndex])
{
// Find any file that has the game name in it
if (filename.find(gameName) != null)
{
if (extension.len() > 0)
{
if (filename.find(extension) != null)
{
return filename;
}
}
else
{
return filename;
}
}
}
return "";
}
The function GetArtOfType() will return a filename if it matches your criteria or empty string if nothing is found for example:
local fileName = GetArtOfType(0, "");
fileName could equal an asset name found in the "video" subfolder with any extension .mp4, .avi, .mkv etc...
local fileName = GetArtOfType(0, ".mp4");
Performs the same search but only return a filename if it contains ".mp4" in the name.
Code:
// Configure the root art folder such as /emu/artwork you can get the value from UserConfig or hard code if you like
local g_baseArtFolder = my_config["baseArtFolder"];
// List of media folders that can be searched. The index parameter in GetArtOfType refers to this list
local g_mediaFolders = ["video","snap","flyer"];
// Store files in found in folders to avoid performing the directory search each time
local g_assetFileNames = [];
/////////////////////////////////////////////////////////////////////////
// Get the asset file of a given type if it exists
//
// \param mediaIndex - Index into your media folder list to use for lookup
// \param extension - Specific file extension if desired, otherwise first match will be returned
//
/////////////////////////////////////////////////////////////////////////
function GetArtOfType(mediaIndex, extension)
{
// Note this assumes assets are stored in system folders such as /emu/artwork/atari2600/video
// where the system name comes from the emulator name you use in AM. If you do not use that
// structure edit below to match
local baseName = g_baseArtFolder + "/" + fe.game_info(Info.Emulator) + "/" + g_mediaFolders[mediaIndex];
local gameName = fe.game_info(Info.Name) + ".";
// Only get the directory listing 1 time
if (g_assetFileNames[mediaIndex] == null)
{
g_assetFileNames[mediaIndex] = DirectoryListing(baseName).results;
}
// Determine if a file in the target folder matches the active game and optionally the desired extension
foreach (filename in g_assetFileNames[mediaIndex])
{
// Find any file that has the game name in it
if (filename.find(gameName) != null)
{
if (extension.len() > 0)
{
if (filename.find(extension) != null)
{
return filename;
}
}
else
{
return filename;
}
}
}
return "";
}