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: Help with writing a component utilizing index-data db / metadb_index_client (Read 3610 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Help with writing a component utilizing index-data db / metadb_index_client

So I'm trying to write an alternate playback statistics component (foo_enhanced_playback_statistics) that functions exactly like the official v3.0.2 one except that instead of just recording the count, it stores a string containing a JSON object with all plays timestamped. Maybe it's possible to get it to function like the normal $meta_num / $meta(field, 5) stuff, but I'm not sure.

At the moment I've got a component using the playback_statistics_collector service which gets called after 60secs, and I can retrieve a titleformat string of "%artist% %album% $if2(%discnumber%,1) %tracknumber% %title%" (which is supposedly what foo_playcount uses for differentiating songs) and spit it to the console.

Of course, that doesn't get me very far. Documentation for how to actually use metadb_index_client is basically non-existent, and I guess I'm not smart enough to just figure it out from the method definitions in metadb.h.

So I think what I need to do is in the on_init I need to instantiate my own class based off metadb_index_client. But to do that I need to implement the transform method which seems to return an MD5 hash, but I can't for the life of me figure out how that method is supposed to look. Also that method takes a playable_location which maybe means that I need to call transform when the file is loaded and then cache the hashed value for using later in my playback_statistics_collector?

Anyway, once the playcount is ready to be incremented, I need to call metadb_index_manager->set_user_data which seems relatively straightforward. I also think metadb_display_field_provider probably isn't too bad.

Any help you guys could provide would be much appreciated. Ideally if you could point me towards the source of a component that's already doing something similar it would be super helpful. As it is, I'm flying blind right now. The really frustrating thing is that if the source for foo_playcount was available, I could probably knock this component out in an hour or two. I basically need exactly that, but with only 25% of the functionality.

Thanks.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #1
So is this really nothing that anybody is doing? From what I can tell playback statistics and foo_lyrics3 are the only components doing this sort of thing, and neither is open source which makes figuring out how this is supposed to work a lot harder.

Does anyone know of other components that are creating a metadb_index_client that are open source?


Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #2
I made a new foo_sample module implementing a simple rating database, just add this .cpp file to foo_sample project.
The next SDK update will include this.
I hope this helps.
Microsoft Windows: We can't script here, this is bat country.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #3
This looks very useful. Is there a way to make the custom fields/values appear in the Properties dialog on the Details tab.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #4
Now with more track_property_provider
Microsoft Windows: We can't script here, this is bat country.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #5
Excellent. Thank you very much.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #6
Thanks, Peter! I'll give this a look soon hopefully.

 

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #7
Because I'm incredibly stupid, I've not figured out to get multiple fields working with a single GUID. Could the next SDK example include that as well?

For now, I've hacked around it with multiple GUIDs which seems to work fine. I'm using it to store playcounts from last.fm and I've finally been able to ditch foo_customdb (hooray!  :P )

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #8
The data pinned to each guid+hash is a blob so it can hold anything that you want, you just have to pack it into a blob on your side. I'll add relevant code to foo_sample for the next update.
Microsoft Windows: We can't script here, this is bat country.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #9
Thanks again.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #10
The data pinned to each guid+hash is a blob so it can hold anything that you want, you just have to pack it into a blob on your side. I'll add relevant code to foo_sample for the next update.
I haven't tried to handle multiple fields yet, but are you saying that if I want my component to handle both %foo_mordred_field1% and %foo_mordred_field2%, then when I call api->set_user_data I'll need to store the values for both fields in the same blob and then unpack them and return the individual fields as needed when doing a get?

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #11
I haven't tried to handle multiple fields yet, but are you saying that if I want my component to handle both %foo_mordred_field1% and %foo_mordred_field2%, then when I call api->set_user_data I'll need to store the values for both fields in the same blob and then unpack them and return the individual fields as needed when doing a get?
Correct.
Microsoft Windows: We can't script here, this is bat country.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #12
New SDK out.
https://www.foobar2000.org/SDK
The above rating.cpp has been improved further and is included.
Microsoft Windows: We can't script here, this is bat country.

Re: Help with writing a component utilizing index-data db / metadb_index_client

Reply #13
Hey Peter,

If you've got a metadb hash generated for a string like "%artist% %album% %title%", how do you update the value for the hash when the file's title is changed?