Index: Slim/Buttons/Common.pm =================================================================== --- Slim/Buttons/Common.pm (revision 10009) +++ Slim/Buttons/Common.pm (working copy) @@ -732,33 +732,80 @@ if (defined $buttonarg && $buttonarg eq "add") { + # First lets try for a listRef from INPUT.* my $list = $client->modeParam('listRef'); + my $obj; + # If there is a list, try grabbing the current index. if ($list) { - my $obj = $list->[$client->modeParam('listIndex')]; + $obj = $list->[$client->modeParam('listIndex')]; + + # hack to grab currently browsed item from current playlist (needs to use INPUT.List at some point) + } elsif (mode($client) eq 'playlist') { + + $obj = Slim::Player::Playlist::song($client, Slim::Buttons::Playlist::browseplaylistindex($client)); + } + + # if that doesn't work, perhaps we have a track param from something like trackinfo + if (!blessed($obj) && $client->modeParam('track')) { + + $obj = $client->modeParam('track'); + } + + my $title; + my $url; + + # start with the object if we have one + if ($obj) { if (blessed($obj) && $obj->can('url')) { + $url = $obj->url; + + # xml browser uses hash lists with url and name values. + } elsif (ref($obj) eq 'HASH') { + + $url = $obj->{'url'}; + } + + if (blessed($obj) && $obj->can('name')) { - my $title; + $title = $obj->name; + }elsif (ref($obj) eq 'HASH') { - if ($obj->can('name')) { - $title = $obj->name; + $title = $obj->{'name'} || $obj->{'title'}; + } else { + + # failing specified name values, try the db title + $title = Slim::Music::Info::standardTitle($client, $obj); + } + } + + # remoteTrackInfo uses url and title params for lists. + if ($client->modeParam('url') && !$url) { + + $url = $client->modeParam('url'); + $title = $client->modeParam('title'); + } + + if ($url && $title) { + Slim::Utils::Favorites->clientAdd($client, $url, $title); + $client->showBriefly($client->string('FAVORITES_ADDING'), $title); + + # if all of that fails, send the debug with a best guess helper for tracing back + } else { + + if ($::d_favorites) { + msg("Favorites: no valid url found, not adding favorite\n"); + + if ($obj) { + msg(Data::Dumper::Dumper($obj)); + } else { - $title = Slim::Music::Info::standardTitle($client, $obj); + Slim::Utils::Misc::bt(); } - - if ($title) { - Slim::Utils::Favorites->clientAdd($client, $obj, $title); - $client->showBriefly($client->string('FAVORITES_ADDING'), $title); - } - - } else { - - $::d_favorites && msg("list item is not an object, not adding favorite\n"); - $::d_favorites && msg(Data::Dumper::Dumper($obj)); } - } + } } elsif (mode($client) ne 'FAVORITES') {