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: HOW TO: synchronise your last.fm playback stats with foobar (Read 380104 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

HOW TO: synchronise your last.fm playback stats with foobar

this isn't a proper component but a script which utilises 2 other components (WSH panel mod & foo_customdb) to do the following:

-it can import the playcount/loved tracks from your entire last.fm library into foobar. it uses foo_customdb so your files are not touched.
-after doing the library import it will automatically update in the background as you listen.
-it can love/unlove tracks on last.fm via a button.
-it can automatically love tracks when they are played based on title formatting (for example, it can be set to automatically love tracks with a RATING of 5)
-you can display/filter the data in any custom columns, library viewers, display panels, etc using these simple tags:

Code: [Select]
%LASTFM_PLAYCOUNT_DB%
%LASTFM_LOVED_DB% //has a value of 1 for loved tracks


full instructions can be found here: https://dl.dropboxusercontent.com/u/2280132...ount%20sync.zip
changelog: https://dl.dropboxusercontent.com/u/2280132...e/changelog.txt

updated 30/04/13: no longer requires foo_softplaylists meaning artist field remapping is supported for loving tracks and background updates.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #1
This is amazing.  Thank you.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #2
Works like a charm, thank you.
Disregard the constabulary.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #3
I can't sync some tracks. Instead of number of plays and love status i get just "..." (Both should be displayed because i generated my loved track playlist with foo_softplaylist).

This problem occures really often (every 2nd track i guess), but my tags are fine so that's not the problem..

Am i doing something wrong?

And one more question: Is it posible to sync the whole playlist at the same time?
Disregard the constabulary.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #4
my script parses 2 values found in the xml response from lastfm named "userplaycount" and "userloved". look for the bits in bold. my script just writes them to the tags. if they don't exist, it just skips it.

Code: [Select]
[16:20:51] <?xml version="1.0" encoding="utf-8"?>
<lfm status="ok">
<track>
    <id>1036798</id>
    <name>Get Me Off</name>
    <mbid></mbid>
    <url>http://www.last.fm/music/Basement+Jaxx/_/Get+Me+Off</url>
    <duration>288000</duration>
    <streamable fulltrack="0">0</streamable>   
        <listeners>41414</listeners>
    <playcount>150455</playcount>
      [b] <userplaycount>7</userplaycount>    <userloved>0</userloved>[/b]
        <artist>
        <name>Basement Jaxx</name>
        <mbid>28cbf94d-0700-4095-a188-37e373b069a7</mbid>
        <url>http://www.last.fm/music/Basement+Jaxx</url>
    </artist>
        <album position="8">
        <artist>Basement Jaxx</artist>
        <title>Rooty</title>
        <mbid>b821473e-4959-40e4-9b40-48b95ecaf36b</mbid>
        <url>http://www.last.fm/music/Basement+Jaxx/Rooty</url>       
        <image size="small">http://userserve-ak.last.fm/serve/64s/5454246.jpg</image>
        <image size="medium">http://userserve-ak.last.fm/serve/126/5454246.jpg</image>
        <image size="large">http://userserve-ak.last.fm/serve/174s/5454246.jpg</image>
        <image size="extralarge">http://userserve-ak.last.fm/serve/300x300/5454246.jpg</image>
    </album>
        <toptags>
        <tag>
  <name>dance</name>
  <url>http://www.last.fm/tag/dance</url>
</tag>
        <tag>
  <name>electronic</name>
  <url>http://www.last.fm/tag/electronic</url>
</tag>
        <tag>
  <name>house</name>
  <url>http://www.last.fm/tag/house</url>
</tag>
        <tag>
  <name>electronica</name>
  <url>http://www.last.fm/tag/electronica</url>
</tag>
        <tag>
  <name>techno</name>
  <url>http://www.last.fm/tag/techno</url>
</tag>
      </toptags>
    </track></lfm>

as i mentioned in the readme, you can check the values that are being written in the console.

maybe the problem is with the feed? you can get your script to output this full response. find this line of code...

Code: [Select]
fb.trace("Status: " + xmlhttp.statustext);

add this as the next line directly after it.

Code: [Select]
fb.trace(xmlhttp.responsetext);

i've been using it for several days now and had no probems at all.

and WSH panel mod can only act on one track at a time. anyway, that's a good limitation because last.fm have a TOS with regards to how often you can query their service. 5 times a second is quite generous but i fear you'd break that unless you had some sort of delaying mechanism.

the quickest way to update your files using this would be stop playback. highlight a track, right click button, "sync now". repeat until bored.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #5
new version uploaded. same link as first post.

changes:
-now automatically updates when the playback time hits 10 seconds instead of requiring 60 seconds of continuous playback.
-as WSH panel mod is unable to tag external cue sheets, i've put a message in the console to alert people of this.

it's just the text in code.txt that has been updated. take care not to overwrite your own settings when updating.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #6
Thanks for new version.  Anyway, i fixed my "error", everything works perfect now..it was so stupid that i don't even want to mention it 
Disregard the constabulary.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #7
glad you sorted it.

also, i've just found out my latest update is bad practice in wsh panel mod. i've had no problems at all, but the author says it may cause it to crash. however, a new version of WSH panel mod has been uploaded which can work around it. just to be clear, it wasn't a problem in WSH panel mod. the new version is to protect idiots like me who didn't read the documentation correctly.

latest version: http://code.google.com/p/foo-wsh-panel-mod/downloads/list


HOW TO: synchronise your last.fm playback stats with foobar

Reply #8
Now i found a pretty big bug, you MUST prevent your script from doing anything when it is a streamed track like lastfm radio for example. Here the consequence is that when you try to write a tag to a currently playing streamed track, the song gets skipped.
Consequently i only have 10 sec of each song when using you script :s
and i am not sure how to correct it :s

HOW TO: synchronise your last.fm playback stats with foobar

Reply #9
ah yes my mistake. as i don't use streams very often i just put in a check to skip files with an unknown length. this works for live streams but not for last.fm radio. i'll update ASAP.

edit: hopefully fixed. try re-downloading again from the link in the first post.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #10
Still happens. I dont see the difference in the script, could you just post the change in the script here?

By The way in you screenshot i see tracks with a "love" number above 1, how do you do that?
Here clicking several times doesnt do the trick

HOW TO: synchronise your last.fm playback stats with foobar

Reply #11
maybe your browser was caching the file?? i did actually test this on the last.fm radio component before uploading.

anyway, i've made a couple more changes so try downloading the file again.

as for my screenshots, the loved status is a heart displayed if the value is 1. i did put the titleformatting in the readme. and the number is my playcount.

edit: changes were in this function. just replace yours with this.

Code: [Select]
function on_metadb_changed() {
if(!g_metadb) return;
length = fb.TitleFormat("%length_seconds%").EvalWithMetadb(g_metadb);
ok = false;
switch(true) {
case (username.length == 0):
case (api_key.length != 32):
n = image_path + "exclamation.png";
h = image_path + "exclamation_h.png";
tooltip = "Click to set your Last.fm username / api key.";
func = function() {window.ShowConfigure();}
break;
case (length == "?"):
case (length < 30):
case (length > 10800):
case (g_metadb.RawPath.indexOf("FOO_LASTFM_RADIO") == 0):
case (g_metadb.RawPath.indexOf("mms://") == 0):
case (g_metadb.RawPath.indexOf("http://") == 0):
n = image_path + "exclamation.png";
h = n;
tooltip = "Unsupported track length or stream.";
func = null;
break;
default:
ok = true;
n = image_path + "love.png";
h = image_path + "love_h.png";
tooltip = fb.TitleFormat("Last.fm Love ''%title%'' by ''%artist%''").EvalWithMetadb(g_metadb);
func = function() {love_track(tooltip);}
}
Buttons = {
but: new Button(0,0,bw,bh, {normal: n, hover: h}, func, tooltip)
};
window.Repaint();
}

HOW TO: synchronise your last.fm playback stats with foobar

Reply #12
@marc2003:
I think it's better to use something like this:
Code: [Select]
...
// or %_path_raw%
case (g_metadb.RawPath.indexOf("mms://") == 0):
...


HOW TO: synchronise your last.fm playback stats with foobar

Reply #13
thanks. post above edited to reflect changes.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #14
Thanks a lot, works perfectly now!

Just thought of a great addition. Right now your panel doesnt do a thing with radio tracks which is a shame. What it should do:
- still allow to love a track! (easily implemented, i did it here)
- write the tag as a temp tag just like biography_view(that i dont know how to do)

what do you think?

HOW TO: synchronise your last.fm playback stats with foobar

Reply #15
i need to play around a bit and see what is possible. i want this to support whatever the website does. if that means loving streams then i'll add it back in.

as for your 2nd point, i highly doubt that is possible. remember, this is just script running on top of WSH panel mod. plus my skills are weak. 

HOW TO: synchronise your last.fm playback stats with foobar

Reply #16
i did some experimenting and it seems there is only one rule for "loving" tracks: there are no rules. even tracks you can't scrobble can be loved. go figure. so i've uploaded a new version.

Quote
changes:

o   Removed “sync now” context menu item. Not needed now that auto updates run after just 10 seconds.
o   Fixed issues with the “loving” of streamed content.  All artificial restrictions have been removed. You can attempt to "love" anything. The response will depend entirely on last.fm.
o   Enforced stricter checks on files that can be tagged.


HOW TO: synchronise your last.fm playback stats with foobar

Reply #18
New question: How can we forced the script to look up times played counts for items in the default ui? I don't see a context menu anywhere, and I'm assuming it's because the component isn't compatible with the default ui...?

HOW TO: synchronise your last.fm playback stats with foobar

Reply #19
see my changelog 2 posts above. the context menu item to force a sync has been removed. the only reason it was there originally is because it was compulsory to listen to a track for a whole minute before it automatically updated. now it's just 10 seconds, i see no need for it. (maybe i should make the readme a bit more clear. it's not actually 10 seconds playback - it's when the elapsed time hits 10 seconds)

look at your console and see if it's automatically running. it should always give a message whether it tags your files or not.

edit: just re-tested my latest version in dockable panels and it's working exactly as expected.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #20
I see. So is there a way to update an entire library with last.fm playcount data then? Obviously this would be more quickly/efficiently done in one foul swoop than individually playing through each track.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #21
not possible. i already explained this earlier in the thread.

Quote
and WSH panel mod can only act on one track at a time.


i think i'll edit the readme to explain the limitations a little more clearly.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #22
Hm, that's ashame... Although it seems like using this method in as a tagging script seems fairly feasible. If I had the time/more developing expertise, I might take my hand at trying to make a component or script that could do it.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #23
there is also the last.fm TOS to consider. i've just added this information to the readme as well.

Quote
You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period, without prior written consent.


it hasn't really needed to be mentioned before because there's absolutely no chance of breaking it with this script.

HOW TO: synchronise your last.fm playback stats with foobar

Reply #24
there is also the last.fm TOS to consider. i've just added this information to the readme as well.

Quote
You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period, without prior written consent.


it hasn't really needed to be mentioned before because there's absolutely no chance of breaking it with this script.


Hm I see... Well an automated script could still be used, correct? It would just take awhile (and 5 requests per second isn't too bad).