Cheers for the great plugin Johan!
I signed up at last.fm just yesterday, and started using your plugin in combination with MonoLite Plus 0.4.3
The softplaylists plugin provided with the skin (dated 2009) was buggy for two reasons:
1. It took a very long time to load when starting Foobar
2. When going to Library->Configure->Tools->Soft Playlists, it took a long time to display that page and to save any alterations.
So I updated the softplaylists to the latest 2011 build. The first issue was gone. The second issue was partly gone, it still takes time to save any changes in soft playlists settings. Moreover, the Love button with the skin no longer is able to Love the tracks, it seems there is some handshake issue with the new version?
The code for the Love button is:
// ==PREPROCESSOR==
// @import "%fb2k_path%skin\mono_lite\scripts\common.js"
// @import "%fb2k_path%skin\mono_lite\scripts\tooltip_buttons.js"
// @import "%fb2k_path%monolite_lastfm_config.js"
// ==/PREPROCESSOR==
var bw = 24;
var bh = 20;
var top_margin = 0;
var left_margin = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var panel_id = window.GetProperty("panel_id", window.id);
var custom_background_file = settings_path + panel_id + "custom_background";
var custom_background = read(custom_background_file);
var username_file = settings_path + "username";
var username = read(username_file);
var api_key_file = settings_path + "api_key";
var api_key = read(api_key_file);
on_item_focus_change();
function on_notify_data(name, data) {
username = read(username_file);
api_key = read(api_key_file);
on_metadb_changed();
}
function update_button(b) {
switch(b) {
case 1:
n = "not_loved.png";
h = "exclamation.png";
tooltip = "Last.fm is disabled, run monolite_lastfm_install.bat to enable it first";
func = null;
break;
case 2:
n = "exclamation.png";
h = "exclamation.png";
tooltip = "Please enter your Last.fm username / api key through context menu";
func = null;
break;
case 3:
n = "love.png";
h = "love.png";
tooltip = "This track is already loved!";
func = null;
break;
case 4:
n = "not_loved.png";
h = "love_h.png";
tooltip = love_command;
func = function() {love_track();}
}
Buttons = {
but: new Button(left_margin,top_margin, bw, bh, {normal: images_path + n, hover: images_path + h}, func, tooltip)
};
window.Repaint();
}
function on_metadb_changed() {
if(!g_metadb) return;
artist = fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb);
track = fb.TitleFormat("%title%").EvalWithMetadb(g_metadb);
love_command = "Last.fm Love '" + track + "' by '"+ artist + "'";
old_userloved = fb.TitleFormat("%LASTFM_LOVED_DB%").EvalWithMetadb(g_metadb) == 1 ? 1 : 0;
switch(true) {
case (is_lastfm.length == 0):
update_button(1);
break;
case (username.length == 0):
case (api_key.length != 32):
update_button(2);
break;
default:
(old_userloved == 1) ? update_button(3) : update_button(4);
}
}
function on_playback_new_track() {
on_item_focus_change();
}
function on_playback_time(time) {
if(time == 3) sync();
}
function love_track() {
fb.RunContextCommandWithMetadb(love_command, g_metadb);
sync();
}
function sync() {
if(username.length == 0 || api_key.length != 32) return(fb.trace("Playcount sync: Can't contact Last.fm. Check your username / API KEY settings."));
fb.trace("Playcount sync: Contacting Last.fm....");
lastfm("&method=track.getinfo&artist=" + encodeURIComponent(artist) + "&track=" + encodeURIComponent(track), "foo_playcount_sync", function() {process();});
}
function process() {
fb.trace("Playcount sync: Last.fm responded \"" + xmlhttp.statustext + "\"");
xmlDoc = xmlhttp.responseXML;
try { userplaycount = xmlDoc.getElementsByTagName("userplaycount")[0].childNodes[0].nodeValue; } catch(e) { userplaycount = 0;}
try { userloved = xmlDoc.getElementsByTagName("userloved")[0].childNodes[0].nodeValue; } catch(e) { userloved = 0; }
userloved == 1 ? update_button(2) : update_button(3);
fb.RunContextCommandWithMetadb("Customdb Love " + userloved, g_metadb);
fb.RunContextCommandWithMetadb("CustomdbU " + (userplaycount > 0 ? userplaycount.substring(userplaycount.length - 1) : "Erase"), g_metadb);
fb.RunContextCommandWithMetadb("CustomdbT " + (userplaycount > 9 ? userplaycount.substring(userplaycount.length - 2, userplaycount.length -1) : "Erase"), g_metadb);
fb.RunContextCommandWithMetadb("CustomdbH " + (userplaycount > 99 ? userplaycount.substring(userplaycount.length - 3, userplaycount.length - 2) : "Erase"), g_metadb);
fb.RunContextCommandWithMetadb("CustomdbTH " + (userplaycount> 999 ? userplaycount.substring(userplaycount.length - 4, userplaycount.length - 3) : "Erase"), g_metadb);
}
function on_size() {
ww = window.Width;
wh = window.Height;
}
function on_mouse_rbtn_up(x, y) {
var _menu = window.CreatePopupMenu();
var _child = window.CreatePopupMenu();
var idx;
_child.AppendMenuItem(MF_STRING, 101, "None");
_child.AppendMenuItem(MF_STRING, 102, (dui ? "Default UI " : "Columns UI ") + "default");
_child.AppendMenuItem(MF_STRING, 103, "Splitter");
_child.AppendMenuItem(MF_STRING, 104, "Custom ");
_child.AppendMenuItem(MF_SEPARATOR, 0, 0);
_child.AppendMenuItem(window.GetProperty("mode") == 104 ? MF_STRING : MF_GRAYED, 105, "Set custom colour...");
_child.CheckMenuRadioItem(101, 104, window.GetProperty("mode", 101));
_menu.AppendMenuItem(username.length > 0 ? MF_STRING : MF_GRAYED, 1, "Visit your Last.fm user profile page");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(is_lastfm.length > 0 ? MF_STRING : MF_GRAYED, 2, "Set your Last.fm username...");
_menu.AppendMenuItem(is_lastfm.length > 0 ? MF_STRING : MF_GRAYED, 3, "Set your API KEY...");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
_menu.AppendMenuItem(MF_STRING | MF_POPUP, _child.ID, "Background");
_menu.AppendMenuItem(MF_SEPARATOR, 0, 0);
//_menu.AppendMenuItem(MF_STRING, 9, "Properties");
_menu.AppendMenuItem(MF_STRING, 10, "Configure...");
idx = _menu.TrackPopupMenu(x, y);
switch(idx) {
case 1:
WshShell.run("http://www.last.fm/user/" + encodeURIComponent(username));
break;
case 2:
username = text_input_box("Playcount Sync", "Please enter your Last.fm username", username_file);
on_metadb_changed();
window.NotifyOthers("update", 1);
break;
case 3:
api_key = text_input_box("Playcount Sync", "Please enter your Last.fm API KEY\n\nhttp://www.last.fm/api/account", api_key_file);
on_metadb_changed();
window.NotifyOthers("update", 1);
break;
case 101:
case 102:
case 103:
case 104:
window.SetProperty("mode", idx);
window.Repaint();
break;
case 105:
custom_background = text_input_box("Playcount Sync", "Enter a custom colour for the background. Uses RGB. Example usage:\n\n234-211-74", custom_background_file);
window.Repaint();
break;
case 9:
window.ShowProperties();
break;
case 10:
window.ShowConfigure();
break;
}
_menu.Dispose();
_child.Dispose()
return true;
}
function on_paint(gr) {
switch(window.GetProperty("mode", 102)) {
case 101:
col = null;
break;
case 102:
col = g_backcolor;
break;
case 103:
col = utils.GetSysColor(4);
break;
case 104:
temp_col = custom_background.split("-");
col = RGB(temp_col[0], temp_col[1], temp_col[2]);
break;
}
if(col) gr.FillSolidRect(0, 0, ww, wh, col);
buttonsDraw(gr);
}
I'm a complete newbie at foobar related programming, and was trying to go over the code for hours last night, but to no avail. The Console gives the following when trying to love a track:
Playcount sync: Contacting Last.fm....
Playcount sync: Last.fm responded "OK"
Can you tell what's wrong?