Hi
I am on foobar only since a few weeks and discovered this plugin lately.
Would it be possible to send these ratings to musicbrainz?
To simplify things only track ratings and sending and getting ratings for only one track would be enough for a start, would make me, maybe others? very happy.
I tried an ugly workaround already myself by writing a small console app, which should be run by foo_run, submits the ratings and sets the rating in foobar back via foo_runcommand.
But since $if(%musicbrainz_trackid%,true,false) always returns false here even if this tag is within the file my approach won't work, even if it was already a very ugly and hacky one.
I thought whether I should post my request here, since it is THE rating plugin for foobar or in one of the two last.fm plugins, because these are already dealing with accounts and/or webservices so it wouldn't be a big deal for them to implement it, because the webservices seems to be working very similar.
Nevertheless I came to the conclusion that it would fit perfectly into this plugin, since all rating tasks are already properly implemented here which would be redundant if this feature should be a standalone plugin.
I also tried myself to dig into plugin writing but gave up, since it would require too much time for me to dig into c++ and foobar sdk.
I am only able to write very basic code in csharp, so I provide you the code here, which is working like a charme in my console application:
If you are interested in, here are more infos about the webservice options regarding ratings: http://musicbrainz.org/doc/XML_Web_Service#ratings_resources
Like said above, to make it simple, submitting ratings when setting them to 1 track would be OK for me, and maybe receiving ratings during playback, if no local one is set (or _optional_ always overwrite the local one)
thx so far for this great music player
regards
hanshans
NetworkCredential _networkCredential;
public MusicBrainzService(string username, string password)
{
_networkCredential = new NetworkCredential(username, password);
}
public void Post(string entity, string id, string rating)
{
Uri address = new Uri("http://musicbrainz.org/ws/1/rating/");
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Add authentication to request
request.Credentials = _networkCredential;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
StringBuilder data = new StringBuilder();
data.Append("entity=");
data.Append(entity);
data.Append("&id=");
data.Append(id);
data.Append("&rating=");
data.Append(rating);
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
Console.WriteLine(reader.ReadToEnd());
}
}