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: Changing the rating of songs (Read 4831 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Changing the rating of songs

Hello, this is my first day coding a component for foobar

I cant find informations about how to change the rating field of a track. Here is the code I wrote

static_api_ptr_t<playlist_manager> _pm;
t_size _pl = _pm->get_active_playlist();
metadb_handle_list _its;
_pm->playlist_get_selected_items(_pl, _its);
if(_its.get_count() > 0){
   MessageBeep(MB_OK);
   for(t_size i=0; i<_its.get_count(); i++){
      _its.get_item(i)->
   }
}

Here is the interesting part:
_its.get_item(i)-> ...
how to change the rating for this item ? Can anyone help ?

Thanks in advance

Changing the rating of songs

Reply #1
There is no method on metadb_handles for setting tags and the foo_playcount component does not provide an API through which you could set the rating. You could execute the context menu command from foo_playcount, but doing that programmatically is a bit of a challenge.

Changing the rating of songs

Reply #2
I see, here is the incomplete command that I think I should use:

menu_helpers::run_command_context(standard_commands::guid_context_save_playlist, standard_commands::guid_context_save_playlist, _its);

But I need to replace "standard_commands::guid_context_save_playlist" with the GUID of the "set rating to 1"
I can't find in the documentation that GUID... can you please help ?

Thanks

Changing the rating of songs

Reply #3
I've been looking into the exact same problem. What I'm doing until now is

Code: [Select]
GUID command,subcommand;
bool result=menu_helpers::find_command_by_name("Playback Statistics/Rating",command);
result=menu_helpers::run_command_context_playlist(command,subcommand);

Unfortunately, find_command_by_name() doesn't seem to work for context menus which have more than two levels, i.e. calling it with "Playback Statistics/Rating/1" does not work. So I only have the GUID of the "Rating" menu (15D9655C-F6DE-4B98-8942-A9DAE2F9AD75), but not the one of the "1" action.

Changing the rating of songs

Reply #4
I can't find in the documentation that GUID... can you please help ?
That GUID is not part of the documentation of foo_playcount. Strictly speaking it is an implementation detail. However since changing it would also invalidate keyboard shortcuts for that command, it is safe to assume that it will stay fairly stable.

Unfortunately, find_command_by_name() doesn't seem to work for context menus which have more than two levels, i.e. calling it with "Playback Statistics/Rating/1" does not work.
The problem is that this helper function will not find dynamic menu commands, i.e. commands with a non-null subcommand GUID. (By the way, you'd better initialise that subcommand variable there. Use pfc::guid_null if you don't have a concrete subcommand GUID.)

Changing the rating of songs

Reply #5
The problem is that this helper function will not find dynamic menu commands, i.e. commands with a non-null subcommand GUID.

Oh, I wouldn't have expected the Rating submenu to be dynamic. The content seems pretty static to me. Well, anyway, so how do I find out the GUIDs of the "1" ... "5" subcommands so I can execute them programmatically?

(By the way, you'd better initialise that subcommand variable there. Use pfc::guid_null if you don't have a concrete subcommand GUID.)

Sure! That was just some example code and I left the subcommand variable uninitialized to indicate that I don't know what to fill in there.

Thanks!



Changing the rating of songs

Reply #8
Thanks its working
By using this:

if (!find_context_command_recur("1", dummy, cm->get_root(), node))

for "set rating to 1"
That's not really clean, as there might be others actions in the futur labeled "1", but it does the job

Changing the rating of songs

Reply #9
Please don't ever release or redistibute anything containing such horrible hacks.
Stay sane, exile.