Home of the Squeezebox™ & Transporter® network music players.
Page 4 of 4 FirstFirst ... 234
Results 31 to 33 of 33
  1. #31
    Quote Originally Posted by mherger View Post
    if you set up $log correctly
    It's logging now, mostly. I guess LMS got a bit crazy from all of my endless and quick restarting after every plugin code change.

    I have some code for letting the MusicInfoScreen display a character when the song is in my virtual library 'Favs'.

    Code:
    sub checkIfInVirtualLibrary
    {	my $thistrackID =           ### how do I get the track_id of the currently playing song (on the client)???
    	
    	my $LibID = { library_id => Slim::Music::VirtualLibraries->getRealId('FAVS') };    ### this only gets me a HASH(0x5bc123456789) value
    
    	my $sql = "SELECT COUNT(1) FROM library_track WHERE library_track.library = '2a111f4b' AND library_track.track = '1234657'";     ### the sql query with these specific values works and returns 1 if  song is part of VL
    	my $sth = Slim::Schema->dbh->prepare( $sql );
    	my $result = undef;
    	$sth->execute();
    		my $IsPartOfVirtualLibrary;
    		$sth->bind_columns( undef, \$IsPartOfVirtualLibrary );
    		if($sth->fetch()) {
    	   		$log->warn("IsPartOfVirtualLibrary = ".$IsPartOfVirtualLibrary);
    		}else {
    	   		$log->warn("IsPartOfVirtualLibrary = ".$IsPartOfVirtualLibrary);
    	   		#$IsPartOfVirtualLibrary = 0;
    		}
    
    	my $string = '';
    	if ($IsPartOfVirtualLibrary == 1) {
    		$string='*';
    		}else {
    		$string='';
    		}
    	$sth->finish();
    	return $string;
    }
    A test with a specific track_id and library_id in the sql part already works.
    But I need to solve 2 problems to finish it:

    1) I need to get the trackID of the currently playing song for the sql query. I couldn't get this to work.

    2) The getRealID returns a HASH value for the virtual library ID and I didn't know how to use the hash value with a sql query. It seems that the sql query only accepts the id in the form of "2a111f4b" instead of "HASH(0x5bc123456789)".

    I'd be glad if you could point me in the right direction. Thank you.

  2. #32
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,260

    Virtual Libraries - help beginner please

    Am 01.06.19 um 16:05 schrieb afriend:
    >
    > mherger wrote:
    >> if you set up $log correctly

    > It's logging now, mostly. I guess LMS got a bit crazy from all of my
    > endless and quick restarting after every plugin code change.
    >
    > I have some code for letting the MusicInfoScreen display a character
    > when the song is in my virtual library 'Favs'.
    >
    >
    > Code:
    > --------------------
    > sub checkIfInVirtualLibrary
    > { my $thistrackID = ### how do I get the track_id of the currently playing song (on the client)???
    >
    > my $LibID = { library_id => Slim::Music::VirtualLibraries->getRealId('FAVS') }; ### this only gets me a HASH(0x5bc123456789) value
    >
    > my $sql = "SELECT COUNT(1) FROM library_track WHERE library_track.library = '2a111f4b' AND library_track.track = '1234657'"; ### the sql query with these specific values works and returns 1 if song is part of VL
    > my $sth = Slim::Schema->dbh->prepare( $sql );
    > my $result = undef;
    > $sth->execute();
    > my $IsPartOfVirtualLibrary;
    > $sth->bind_columns( undef, \$IsPartOfVirtualLibrary );
    > if($sth->fetch()) {
    > $log->warn("IsPartOfVirtualLibrary = ".$IsPartOfVirtualLibrary);
    > }else {
    > $log->warn("IsPartOfVirtualLibrary = ".$IsPartOfVirtualLibrary);
    > #$IsPartOfVirtualLibrary = 0;
    > }
    >
    > my $string = '';
    > if ($IsPartOfVirtualLibrary == 1) {
    > $string='*';
    > }else {
    > $string='';
    > }
    > $sth->finish();
    > return $string;
    > }
    > --------------------
    >
    >
    > 1) I need to -get the trackID- of the currently playing song for the sql
    > query. I couldn't get this to work.


    Depending on where you do this you might need to get the currently
    playing song from the $client object, then the corresponding track
    object, from which you'd get the id. Something like:

    $client->playingSong()->currentTrack()->id()

    I haven't tested this. If it doesn't work, I suggest you investigate
    what you get for the playingSong(), then the currentTrack() etc.

    > 2) The getRealID returns a HASH value for the virtual library ID and I


    That's because you define it as a hash:

    my $LibID = { library_id =>
    Slim::Music::VirtualLibraries->getRealId('FAVS') };

    That's how you create a hash ref with one value with the key
    "library_id". What you need obviously is the result of getRealId() only:

    my $LibID = Slim::Music::VirtualLibraries->getRealId('FAVS');

    --

    Michael

  3. #33
    Quote Originally Posted by mherger View Post
    $client->playingSong()->currentTrack()->id()

    I haven't tested this. If it doesn't work, I suggest you investigate
    what you get for the playingSong(), then the currentTrack() etc.
    [color=blue]
    Thanks. I figured it out eventually. The track object was actually provided, just needed my $track = shift in the end.

    I have one issue/bug I would like to fix - and which I think is caused by how I use Slim::Menu::BrowseLibrary.
    I'm trying to create an artist (Top Rated by Artist) and a genre (Top Rated by Genre) menu for my virtual library FAVS (of top rated tracks). The virtual library has exactly the number of tracks it should have. So no problem there.

    However, on the second level down (= in the artists menu: artists->albums and in the genre menu: genres->artists) I have quite a number of albums (in the case of the Top Rated by Genre menu that would be artists) that shouldn't be there and which have no tracks/are empty (which is correct because they are not top rated and are not even part of the virtual library FAVS). But they shouldn't show up in the first place. I wasn't able to confirm this for every single empty dummy entry but most of them seem to be related to compilation albums. I wonder why CustomBrowse has no problem filtering them out...

    I've tried to recreate the genre menu (Top Rated by Genre) with Custom Browse to see if my music files or my LMS settings are causing this. But CustomBrowse somehow gets it right and shows only entries that should be there.
    So that has me thinking the way I call Slim::Menu::BrowseLibrary in the code below is wrong or missing something that filters out all those empty dummy artists/albums that don't belong there.

    Do you have any idea how I could tweak my use of Slim::Menu::BrowseLibrary to get rid of the empty artist/album entries on the second menu level?

    Code:
    		Slim::Menu::BrowseLibrary->registerNode({
                            type         => 'link',
                            name         => 'MENUGROUP',
                            id           => 'custommenus',
                            feed         => sub {
                            	my ($client, $cb, $args, $pt) = @_;
                            	my @items = ();
    
    			# Top Rated Artists Menu
                            	$pt = { library_id => Slim::Music::VirtualLibraries->getRealId('FAVS') };
                            	push @items,{
    
                            		type => 'link',
                            		name => string('TOP_RATED_ARTISTS'),
                            		url => \&Slim::Menu::BrowseLibrary::_artists,
                            		icon => 'html/images/artists.png',
                            		jiveIcon => 'html/images/artists.png',
    								id => string('myMusicArtists_TOP_RATED_TracksByArtist'),
                             		condition => \&Slim::Menu::BrowseLibrary::isEnabledNode,
                             		weight => 210,
                             		cache => 1,
                             		passthrough => [{
                             			library_id => $pt->{'library_id'},
                             			searchTags => [
                             				'library_id:'.$pt->{'library_id'}
                             			],
                             		}],
                            	};
    
    			# Top Rated Genres Menu
                            	$pt = { library_id => Slim::Music::VirtualLibraries->getRealId('FAVS') };
                            	push @items,{
    
                            		type => 'link',
                            		name => string('TOP_RATED_GENRES'),
                            		url => \&Slim::Menu::BrowseLibrary::_genres,
                            		icon => 'html/images/genres.png',
                            		jiveIcon => 'html/images/genres.png',
    					id => string('myMusicGenres_TOP_RATED_TracksByGenres'),
                             		condition => \&Slim::Menu::BrowseLibrary::isEnabledNode,
                             		weight => 211,
                             		cache => 1,
                             		passthrough => [{
                             			library_id => $pt->{'library_id'},
                             			searchTags => [
                             				'library_id:'.$pt->{'library_id'}
                             			],
                             		}],
                            	};
     
    				$cb->({
    					items => \@items,
    					});
                             },
    
    (...)
    Last edited by afriend; 2019-07-12 at 02:54.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •