Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: WSH Panel Mod (Read 814765 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

WSH Panel Mod

Reply #425
here's a script that reads your lastfm playcount using the web services and then writes the response to your file tags. it only runs after the track has been playing for 60 seconds. it's not interactive in anyway so the panel should be hidden. just add a new column (default is LASTFM_PLAYCOUNT) and play your music as usual.

Nice, I thought about something like that.
There is one problem, the script does not work with tracks from the cue file, because it can not create a field. Played a little with foo_customdb, but I can't figure out how to modify its field from WSH.
Any idea?

WSH Panel Mod

Reply #426
Maybe with executing directly sqlite3.exe on customdb_sqlite.db, or through ODBC Driver then connecting:

Set objConn = CreateObject("ADODB.Connection")
objConn.Open "DRIVER=SQLite3 ODBC Driver;Database=customdb_sqlite.db;"
... etc


WSH Panel Mod

Reply #427
sorry i can't help with the problems in cue files (i don't know how ).

but i do have a new version. this also grabs the "loved" status as well. it also outputs any changes it makes to the console. there is also an optional debugging option (see comments) that will write the full server response to the console incase you get any results that you do not expect.

Code: [Select]
var username = "";
var api_key = "";

var sync_playcount = 1;
var playcount_tag_name = "LASTFM_PLAYCOUNT";
var sync_loved = 1;
var loved_tag_name = "LASTFM_LOVED";

function on_item_played() {
sync();
}

function sync() {
//no point querying last.fm if both options are turned off
if(sync_playcount == 0 && sync_loved == 0) return;
var g_metadb = fb.GetNowPlaying();
var artist = encodeURIComponent(fb.TitleFormat("%artist%").EvalWithMetadb(g_metadb));
var track = encodeURIComponent(fb.TitleFormat("%title%").EvalWithMetadb(g_metadb));
var url = "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=" + api_key + "&username=" + username + "&artist=" + artist + "&track=" + track;
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", url + "&s=" + Math.random(), true);
xmlhttp.setRequestHeader('User-Agent','foo_lastfm_playcount_sync');
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
//un-comment the following line to see full server response in console
//fb.trace(xmlhttp.responsetext);
if (xmlhttp.status == 200) {
var xmlDoc = xmlhttp.responseXML;
var y = xmlDoc.getElementsByTagName("userplaycount");
if(y.length == 1 && sync_playcount == 1) {
var lastfm_playcount = xmlDoc.getElementsByTagName("userplaycount")[0].childNodes[0].nodeValue;
var old_lastfm_playcount = fb.TitleFormat("%" + playcount_tag_name + "%").EvalWithMetadb(g_metadb);
if(lastfm_playcount != old_lastfm_playcount) {
fb.trace("Updating: " + playcount_tag_name + " " + old_lastfm_playcount + " -> " + lastfm_playcount);
g_metadb.UpdateFileInfoSimple(playcount_tag_name, lastfm_playcount);
}
}
var z = xmlDoc.getElementsByTagName("userloved");
if(z.length == 1 && sync_loved == 1) {
var lastfm_loved = xmlDoc.getElementsByTagName("userloved")[0].childNodes[0].nodeValue;
var old_lastfm_loved = fb.TitleFormat("%" + loved_tag_name + "%").EvalWithMetadb(g_metadb);
if((lastfm_loved == 1 && old_lastfm_loved == "?") || (lastfm_loved == 0 && old_lastfm_loved ==1)) {
fb.trace("Updating: " + loved_tag_name + " " + old_lastfm_loved + " -> " + lastfm_loved);
g_metadb.UpdateFileInfoSimple(loved_tag_name, (lastfm_loved == 1) ? 1 : '');
}
}
}
}
}
}

WSH Panel Mod

Reply #428
I made it for my personnal needs, but a new version of my "track info like" toolbar can be downloaded Here.
Features :
  • Now playing track only
  • Access to various track info (with mousewheel)
  • Automated text scrolling (horizontal)
  • Configurable colors (click on the toolbar)

WSH Panel Mod

Reply #429
Maybe with executing directly sqlite3.exe on customdb_sqlite.db, or through ODBC Driver then connecting:

Seems that foo_customdb keeps records locked for the currently played item. I'm able to lookup and insert data, but not to update if the track already exist because of "database locked" error. When I disable customdb plugin, script can update any track.

WSH Panel Mod

Reply #430
i've got my lastfm script working with customdb at last.

i have just one tiny issue left. because i'm running sqlite3 using WshShell.run, i'm getting a command prompt window flicker up on every update. is there a way to suppress this?

WSH Panel Mod

Reply #431
but not to update if the track already exist because of "database locked" error.


use

"INSERT OR REPLACE INTO quicktag(......"

that allows you to update already existing records in the database.

WSH Panel Mod

Reply #432
This is exactly what I use. It works when no such record exist (INSERT), but failed in other case (REPLACE). UPDATE and DELETE failed too.

WSH Panel Mod

Reply #433
edit: post removed. i'm having db locked errors when records exist. it was working fine last night. i must have changed something. 

WSH Panel Mod

Reply #434
Too bad component author doesn't stop here on HA. db is locked if file is playing as I see. Here is vbs code for accessing it:

Code: [Select]
Set oConn = CreateObject("ADODB.Connection")
oConn.Open "DRIVER=SQLite3 ODBC Driver;Database=C:/Users/Some Name/AppData/Roaming/foobar2000/customdb_sqlite.db;"
Set oRS = CreateObject("ADODB.Recordset")

strQuery = "INSERT OR REPLACE INTO quicktag (url,subsong,fieldname,value) values (some key,-1,some field,some value);"
oRS.CursorType = adOpenstatic
Set oRS.ActiveConnection = oConn
oRS.Open(strQuery)

oConn.Close

It "waits" until db is released (on track change) and than updates the field. Maybe "timeout [ms]" should be used, but then maybe all this is not worth it

 

WSH Panel Mod

Reply #435
i have a workaround. create an action in the customdb preferences to delete the field and then trigger it using WSH panel mod before running the sqlite command. so simple yet it took me ages to think of it. 

Code: [Select]
fb.RunContextCommandWithMetadb("Legacy commands (unsorted)/customdb delete playcount",g_metadb);
var query1 = '\"INSERT INTO quicktag(url,subsong,fieldname,value) VALUES(\\"' + crc32 + '\\",\\"-1\\",\\"' + playcount_tag_name + '\\",\\"' + lastfm_playcount + '\\")\";';
WshShell.Run("sqlite3.exe customdb_sqlite.db " + query1);


WSH Panel Mod

Reply #436
isn't db locked anyway?

WSH Panel Mod

Reply #437
i have a workaround. create an action in the customdb preferences to delete the field and then trigger it using WSH panel mod before running the sqlite command.
Nice trick! It works now 

I used the Litex COM wrapper, so I can do all in the script, without external system call or ODBC driver. Unpack the single file litex\bin\sqlite3.dll to the "components" directory and run "regsvr32 .\sqlite3.dll" command, that's all.

Delete field via trick and call

Code: [Select]
function WriteCustomDB(artist,album,title,field,value){

var urlstring = artist+ ", " + album + ", " + title;
oDb = new ActiveXObject("LiteX.LiteConnection");
oStmt = new ActiveXObject("LiteX.LiteStatement");
oDb.Path="customdb_sqlite.db";
oDb.open();
oStmt.ActiveConnection = oDb;

try {
oStmt.CommandText = "INSERT OR REPLACE INTO quicktag(url, subsong, fieldname, value) VALUES(:url, :subsong, :fieldname, :value)";
oStmt.Prepare();
oStmt.BindParameter(":url", urlstring);
oStmt.BindParameter(":subsong", -1);
oStmt.BindParameter(":fieldname", field);
oStmt.BindParameter(":value", value);
oStmt.Execute();
}
catch(e){
fb.trace( e )
fb.trace( "Number: ", e.number>>16 & 0x1FFF, e.number & 0xFFFF );
fb.trace( "Message:", e.message );
fb.trace( "Description:", e.description );
}
finally {
oStmt.Close();
oDb.close();
}
}


Of course, this is for default customdb key "%artist%, %album%, %title%", otherwise urlstring should be adjusted.

WSH Panel Mod

Reply #438
i might have a go at using that. at least then i won't get a command prompt window flicker on every update.

edit: oh balls. i can't register that dll on windows 7 64bit. i get some error.

WSH Panel Mod

Reply #439
isn't db locked anyway?

Yes, customdb locks the current focused item (even not playing), but only already existing records with customdb fields. Any process can add new records, but only customdb can update or delete them.

WSH Panel Mod

Reply #440
It doesn't seem to be that way on my PC: If foobar is playing db is locked (can't add any new field), if foobar isn't playing I'm able to update any field


WSH Panel Mod

Reply #442
It doesn't seem to be that way on my PC: If foobar is playing db is locked (can't add any new field), if foobar isn't playing I'm able to update any field

May be I'm wrong here. While playing with other callbacks,  on_item_focus_change() crashed several times at database access, but I'm not sure why.

WSH Panel Mod

Reply #443
Unfortunately db gets locked on the some tracks for inserting new records too, so this trick didn't work.

I can't find any pattern here, sometimes the first track in an album updated, but failed the second one.

WSH Panel Mod

Reply #444
Any complex operations during global callbacks shall be avioded, I've seen some crash reports about that. (you can use a timer to schedule them, as grimes did before: http://foobar-users.de/index.php?topic=200...14184#msg14184).

However, in order to prevent users using global callback incorrectly, I'll made WSH Panel Mod to invoke global callbacks asynchronously, in the next version.

WSH Panel Mod

Reply #445
i'm using on_playback_time to update tags when playback time hits 10 seconds.

Code: [Select]
var t = fb.TitleFormat("%playback_time_seconds%");
function on_playback_time(time) {
    if(ok && t.eval() == 10) sync();
}


my sync function contains just 2 "g_metadb.UpdateFileInfoSimple" operations. most of the time, it will only be running one.

is this safe to use?

i don't understand that timer stuff at all. 

WSH Panel Mod

Reply #446
@marc2003:
No, it's already declared in the doc.

And, I've uploaded 1.2.1 Beta 1, now with no restriction about global callbacks (because they are asynchronous now)

WSH Panel Mod

Reply #447
well i was using on_item_played before but i ran into this problem which i posted a few days back.

Quote
i'm using on_item_played to write tags to a file. but if the track is less than one minute, the function runs on the next track as soon as it begins playing, totally skipping the previous short track.


that's why i changed my code to use on_playback_time instead.

WSH Panel Mod

Reply #448
@U'nik:
I've received a lot of crash reports about "sqlite3_release_memory"
If you are encountering problems like that, please paste full of your scripts here.


WSH Panel Mod

Reply #449
1.2.1 Beta 2 is uploaded, with some fixed for async global callbacks.