Thursday, 5 January 2012

Artist/Album Info in Foobar2000

foobar2000 is perfect mediaplayer for Windows platforms. It is kind of those applications whose functionality is extendable simply adding plugins. One of these finest plugins is Run services that allows to run external applications and scrpts from within foobar2000.

I use Run services to view/edit information about albums or artists stored in plain text files. Let's consider how it is possible.

I like to keep some interesting notes about artists or separate albums in plain text files within appropriate folders. This can be achieved easily -- an upper level folder is an artist name and a lower level folder is an album title. A text file info.txt keeps information corresponding to an artist or an album. From the context menu of the player I can launch one of them using this plugin.
  1. Download and install the plugin Run Services accordingly it's instructions
  2. In the Preferences: Run services add the services as it is shown in the section Added services
  3. Under the home directory of foobar2000 create the subdirectory tools
  4. Within this subdirectory create the file info.js with the content from the section Running script or follow to this link
Added services
Add these services in the Preferences: Run services
Information about an album
service - Info :: Album Info
path    - tools\info.js "%path%" /S
Information about an artist
service - Info :: Artist Info
path    - tools\info.js "%path%" /A /S
Running script
Store this code as the file tools/info.js

var args = WScript.Arguments;

if ( args.Unnamed.length != 1 ) {
    WScript.Echo([
        'Usage: ', 
        WScript.ScriptName + ' [/A] path [/S]', 
        '', 
        '/A - Show Artist Info (by default - Album Info)', 
        '/S - Suppress a message if an Info file does not exist', 
    ].join('\n'));
    WScript.Quit();
}

var fso = new ActiveXObject('Scripting.FileSystemObject');

var info_file = args.Unnamed.item(0);

if ( ! fso.FileExists(info_file) ) {
    WScript.Echo('Could not find the info file: ' + info_file);
    WScript.Quit();
}

info_file = fso.GetFile(info_file).ParentFolder;

if ( args.Named.Exists('A') ) {
    info_file = info_file.ParentFolder;
}

info_file += '\\info.txt';

if ( ! fso.FileExists(info_file) && ! args.Named.Exists('S') ) {
    WScript.Echo('File not found: ' + info_file);
    WScript.Quit();
}

var shell = WScript.CreateObject('WScript.Shell');

shell.Run('notepad.exe "' + info_file + '"', 1, false);

There is short description of the available arguments
Usage: 
info.js [/A] path [/S]

/A - Show Artist Info (by default - Album Info)
/S - Suppress a message if an Info file does not exist
Usage is simple. By default, the script looks for the file info.txt under an album's directory and launches notepad with the found file. The /A argument forces to look for the same file under an artist's directory.

The /S argument changes behavior of the script when it does not find the info.txt. By default, the script shows a dialog where it informs that it could not find the file. When /S is present the script runs notepad which informs that the file is not exist and suggests to create it. This might be useful if you found something and want to keep it.
Links
  1. foobar2000 player's homepage
  2. Run services plugin's homepage
  3. Running script hosted on PasteBin.com

No comments:

Post a Comment