scanUrl not being called

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Webster
    Senior Member
    • Apr 2005
    • 10343

    scanUrl not being called

    In a plugin, I am trying to replace the display of a stream URL with a local protocol handler version.
    I have seen that @expectingtofly VirginRadio plugin does this.

    e.g.
    myplugin:StationA
    translated by my explodePlaylist to
    h t t p: // radiostation.com/stream.mp3

    but I want LMS / players to show the URL as
    myplugin:StationA
    not
    h t t p: // radiostation.com/stream.mp3

    I think that scanUrl is the place to do this.

    My explodePlaylist is being called but my scanUrl is not.

    I have a
    use base qw(Slim::Player::Protocols::HTTPS);

    I also have:
    sub isAudio { 1 }
    sub isRemote { 1 }
    sub canDirectStream { 0 }


    Any ideas why my scanUrl is not being called then the stream is set to start?
    Paul Webster
    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
    and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin
  • expectingtofly
    Senior Member
    • Aug 2014
    • 1104

    #2
    Originally posted by Paul Webster
    In a plugin, I am trying to replace the display of a stream URL with a local protocol handler version.
    I have seen that @expectingtofly VirginRadio plugin does this.

    e.g.
    myplugin:StationA
    translated by my explodePlaylist to
    h t t p: // radiostation.com/stream.mp3

    but I want LMS / players to show the URL as
    myplugin:StationA
    not
    h t t p: // radiostation.com/stream.mp3


    Any ideas why my scanUrl is not being called then the stream is set to start?
    I don't think my virgin radio plugin uses the explodeplaylist??
    In fact virginradio protocol handler is probably a good example as it uses scan url : https://github.com/expectingtofly/LM...andler.pm#L638

    I can't remember that exact order of doing things, I did make a note of it somewhere. But getNextTrack is where you work out the real stream url. So you can probably follow it through on the virgin radio or times radio plugins. (I think I had to do some jiggery pokery in the scanUrl override to make sure it used the real stream url.)

    Meanwhile, I'll try and find my notes.....
    Stuart McLean

    ExpectingToFly Plugins :
    BBC Sounds, Global Player (UK), Times Radio, UK Radio Player, Virgin Radio (UK) and the Radio Favourites Plugin

    For BBC Sounds help see the BBC Sounds Wiki.

    Comment

    • bpa
      Senior Member
      • Oct 2005
      • 22880

      #3
      I had problem with scanning with PlayHLS and I know I had to add an importer (either addImporter or in install.xml) for some reason.

      edit:
      Importer is not what you need - To replace the displayed URL - expectingtofly is on the right idea - similar what TRiode did in BBCiPlayer when it hid "iplayer://"
      Last edited by bpa; 2021-05-18, 12:29.

      Comment

      • mherger
        Babelfish's Best Boy
        • Apr 2005
        • 24642

        #4
        scanUrl not being called

        > I had problem with scanning with PlayHLS and I know I had to add an
        > importer (either addImporter or in install.xml) for some reason.

        I'm very much confused by this... And you mention this for the second
        time this week... scanUrl in the protocol handler has been around for
        years before the importer feature was implemented. I don't really know
        what they would have to do with each other. In particular would
        addImporter have nothing to do with a radio station? It's used to import
        tracks into your library.

        --
        Michael

        "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
        (LMS: Settings/Information)

        Comment

        • mherger
          Babelfish's Best Boy
          • Apr 2005
          • 24642

          #5
          scanUrl not being called

          > In a plugin, I am trying to replace the display of a stream URL with a
          > local protocol handler version.


          What do you mean by "the display of a stream URL"? A protocol handler
          (PH) would deal with a URL of a specific protocol. Eg. your protocol
          would be "myplugin". So myplugin:someStation would be handled by your
          PH. A PH is not there to customize behaviour of http://mystation/stream,
          but to "mask" it. Eg. radioparadise://1.flac would be the Mellow
          station. Only once the PH is called to getNextTrack() it would return
          the real http URL. But in LMS you'd almost always see
          radioparadise://1.flac, and not the http URL.

          I probably don't understand what you're trying to do.
          Michael

          "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
          (LMS: Settings/Information)

          Comment

          • expectingtofly
            Senior Member
            • Aug 2014
            • 1104

            #6
            Originally posted by mherger
            > In a plugin, I am trying to replace the display of a stream URL with a
            > local protocol handler version.


            What do you mean by "the display of a stream URL"? A protocol handler
            (PH) would deal with a URL of a specific protocol. Eg. your protocol
            would be "myplugin". So myplugin:someStation would be handled by your
            PH. A PH is not there to customize behaviour of http://mystation/stream,
            but to "mask" it. Eg. radioparadise://1.flac would be the Mellow
            station. Only once the PH is called to getNextTrack() it would return
            the real http URL. But in LMS you'd almost always see
            radioparadise://1.flac, and not the http URL.

            I probably don't understand what you're trying to do.
            I think paul added an "explodeplaylist" to treate the customized url as a playlist, which would convert it to the real https:// playlist item. That means that the real https would then be used and his protocol handler would not be used from that point onwards.
            As you say, he needs to remove that explodeplaylist and use getNextTrack to resolve the real url (he should be able to follow my example in the virgin radio plugin).
            Stuart McLean

            ExpectingToFly Plugins :
            BBC Sounds, Global Player (UK), Times Radio, UK Radio Player, Virgin Radio (UK) and the Radio Favourites Plugin

            For BBC Sounds help see the BBC Sounds Wiki.

            Comment

            • bpa
              Senior Member
              • Oct 2005
              • 22880

              #7
              Originally posted by mherger
              > I had problem with scanning with PlayHLS and I know I had to add an
              > importer (either addImporter or in install.xml) for some reason.

              I'm very much confused by this... And you mention this for the second
              time this week... scanUrl in the protocol handler has been around for
              years before the importer feature was implemented. I don't really know
              what they would have to do with each other. In particular would
              addImporter have nothing to do with a radio station? It's used to import
              tracks into your library.

              --
              Ignore me, I got into my head Paul was trying to hide multiple formats under one. I was too lazy to look at the code as why importer was needed.

              PlayHLS is an oddity - the suffix m3u8 playlist &MIME is ambiguous, the content needs ot be examined before determining whether the playlist can either be m3u playlist or HLS ones. So PlayHLS had to do a scan of m3u8 playlist and decide whether they are to be handled by LMS or PlayHLS. There may be a better solution but part of the problem was learning how the real world has implemented HLS and where the rules have not been followed.

              Comment

              • Paul Webster
                Senior Member
                • Apr 2005
                • 10343

                #8
                ok - will try with getNextTrack.

                I think I went with explodePlaylist initially because I saw it being used in BBCSounds plugin when converting sounds:// protocol for live streams.
                It worked (in that I provided the real URL back to LMS and it played) but I did not want the real URL to appear in UI or on devices so was then hunting for a way to hide it again.
                Paul Webster
                Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
                and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin

                Comment

                • mherger
                  Babelfish's Best Boy
                  • Apr 2005
                  • 24642

                  #9
                  scanUrl not being called

                  > I think I went with explodePlaylist initially because I saw it being
                  > used in BBCSounds plugin when converting sounds:// protocol for live
                  > streams.
                  > It worked (in that I provided the real URL back to LMS and it played)
                  > but I did not want the real URL to appear in UI or on devices so was
                  > then hunting for a way to hide it again.


                  When you explode a list into its tracks, you can create your own URLs
                  again, which then would be "translated" into real URLs in getNextTrack().
                  Michael

                  "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
                  (LMS: Settings/Information)

                  Comment

                  • Paul Webster
                    Senior Member
                    • Apr 2005
                    • 10343

                    #10
                    Still having problems after removing explodePlaylist and having a getNextTrack
                    My code that takes the given protocol:// string to find the real stream URL is working - and returning the right value.

                    getNextTrack is called by LMS soon after scanUrl returns.
                    The code looks (to me) to be essentially the same as in Slim::Plugin::RemoteLibrary::ProtocolHandler

                    Code:
                    sub getNextTrack {
                    	my ( $class, $song, $successCb, $errorCb ) = @_;
                    	my $masterUrl = $song->track()->url;
                    	main::INFOLOG && $log->is_info && $log->info("getNextTrack " . $masterUrl);
                    
                    	if ( $masterUrl =~ /^$thisProtocol:/ ) {
                    
                    		my ($scheme, $auth, $path, $query, $frag) = uri_split($masterUrl);
                    		
                    		my $streamUrl;
                    		
                    		if ( $auth ){
                    			$streamUrl = Plugins::myplugin::Plugin::_matchId( $auth );
                    		}
                    
                    		main::DEBUGLOG && $log->is_debug && $log->debug("Setting Live Stream $streamUrl");
                    		
                    		$song->streamUrl($streamUrl);
                    		#$song->track->bitrate(128_000);
                    
                    		$successCb->();
                    	}
                    
                    }
                    Edited log
                    Code:
                    [21-05-18 15:37:49.6711] Plugins::myplugin::ProtocolHandler::scanUrl (70) scanurl myplugin://test
                    [21-05-18 15:37:49.6719] Plugins::myplugin::Plugin::_matchId (5586) _matchId: test exists
                    [21-05-18 15:37:49.6725] Plugins::myplugin::ProtocolHandler::scanUrl (83) scanurl myplugin://test actual stream https://somewhere.com/stream.aac
                    [21-05-18 15:37:52.4808] Plugins::myplugin::ProtocolHandler::getNextTrack (97) getNextTrack myplugin://test
                    [21-05-18 15:37:52.4821] Plugins::myplugin::Plugin::_matchId (5586) _matchId: test exists
                    [21-05-18 15:37:52.4832] Plugins::myplugin::ProtocolHandler::getNextTrack (109) Setting Live Stream https://somewhere.com/stream.aac
                    [21-05-18 15:37:52.4874] Slim::Player::Song::open (415) Error: Couldn't create command line for unk playback for [myplugin://test]
                    If I play the same final stream url in LMS then it works fine.
                    It looks to me like the line
                    Code:
                    $song->streamUrl($streamUrl);
                    did not change the song data so LMS tried to create a command line to handle myplugin: which failed.

                    Sorry for the trouble.
                    I don't want to share the exact stream URL in public for reasons that I am happy to explain via PM or email.
                    I can share the current code if an expert is willing to take a look offline.
                    Paul Webster
                    Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
                    and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin

                    Comment

                    • Paul Webster
                      Senior Member
                      • Apr 2005
                      • 10343

                      #11
                      FYI
                      I was a software developer in the early 80s and using very different languages that did not have the nuances of Perl.
                      While I enjoy working in and around LMS there are plenty of traps to fall into and copy/paste coding is great when it works quickly but painful when it does not.
                      Paul Webster
                      Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
                      and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin

                      Comment

                      • expectingtofly
                        Senior Member
                        • Aug 2014
                        • 1104

                        #12
                        Originally posted by Paul Webster
                        If I play the same final stream url in LMS then it works fine.
                        It looks to me like the line
                        Code:
                        $song->streamUrl($streamUrl);
                        did not change the song data so LMS tried to create a command line to handle myplugin: which failed.

                        Sorry for the trouble.
                        I don't want to share the exact stream URL in public for reasons that I am happy to explain via PM or email.
                        I can share the current code if an expert is willing to take a look offline.

                        Ah yes, that rings a bell. Scanurl gets called first, and it tries to use the customized url.
                        So, what you need to do is override scanUrl and call up to the real scanUrl ensuring you pass in the real url into that method.
                        However, there is a complication, if I remember correctly, that there is a callback method that is passed in thorugh args. You have to make sure that the customized url is passed into that rather than the real url so you have to do some interception and replace that callback function with one that does the callback with the real url. I remember that caused me pain at the time!
                        You should just need to copy what I've done in the virgin radio protocol handler (of course replacing the logic that works out the real url with your own)

                        Stuart McLean

                        ExpectingToFly Plugins :
                        BBC Sounds, Global Player (UK), Times Radio, UK Radio Player, Virgin Radio (UK) and the Radio Favourites Plugin

                        For BBC Sounds help see the BBC Sounds Wiki.

                        Comment

                        • philippe_44
                          Senior Member
                          • May 2008
                          • 9343

                          #13
                          Originally posted by Paul Webster
                          Still having problems after removing explodePlaylist and having a getNextTrack
                          My code that takes the given protocol:// string to find the real stream URL is working - and returning the right value.

                          getNextTrack is called by LMS soon after scanUrl returns.
                          The code looks (to me) to be essentially the same as in Slim::Plugin::RemoteLibrary::ProtocolHandler

                          Edited log
                          Code:
                          [21-05-18 15:37:49.6711] Plugins::myplugin::ProtocolHandler::scanUrl (70) scanurl myplugin://test
                          [21-05-18 15:37:49.6719] Plugins::myplugin::Plugin::_matchId (5586) _matchId: test exists
                          [21-05-18 15:37:49.6725] Plugins::myplugin::ProtocolHandler::scanUrl (83) scanurl myplugin://test actual stream https://somewhere.com/stream.aac
                          [21-05-18 15:37:52.4808] Plugins::myplugin::ProtocolHandler::getNextTrack (97) getNextTrack myplugin://test
                          [21-05-18 15:37:52.4821] Plugins::myplugin::Plugin::_matchId (5586) _matchId: test exists
                          [21-05-18 15:37:52.4832] Plugins::myplugin::ProtocolHandler::getNextTrack (109) Setting Live Stream https://somewhere.com/stream.aac
                          [21-05-18 15:37:52.4874] Slim::Player::Song::open (415) Error: Couldn't create command line for unk playback for [myplugin://test]
                          If I play the same final stream url in LMS then it works fine.
                          It looks to me like the line
                          Code:
                          $song->streamUrl($streamUrl);
                          did not change the song data so LMS tried to create a command line to handle myplugin: which failed.

                          Sorry for the trouble.
                          I don't want to share the exact stream URL in public for reasons that I am happy to explain via PM or email.
                          I can share the current code if an expert is willing to take a look offline.
                          AFAIR, the handler is not changed if you just change the $song->streamUrl. If you want LMS to re-evaluate the handler to use because of URL change, you need to set track's url. If you look at the LMS code, in Slim::Player::Song.pm
                          Code:
                          sub getNextSong {
                          	my ($self, $successCb, $failCb) = @_;
                          
                          	my $handler = $self->currentTrackHandler();
                          
                          	main::INFOLOG && $log->info($self->currentTrack()->url);
                          
                          	#	if (playlist and no-track and (scanned or not scannable)) {
                          	if (!$self->_currentTrack()
                          		&& $self->isPlaylist()
                          		&& ($self->_scanDone() || !$handler->can('scanUrl')))
                          	{
                          		if (!$self->_getNextPlaylistTrack()) {
                          			&$failCb('PLAYLIST_NO_ITEMS_FOUND', $self->_track()->url);
                          			return;
                          		}
                          		$handler = $self->currentTrackHandler();
                          	}
                          
                          	my $track   = $self->currentTrack();
                          	my $url     = $track->url;
                          	my $client  = $self->master();
                          
                          	# If we have (a) a scannable playlist track,
                          	# or (b) a scannable track that is not yet scanned and could be a playlist ...
                          	if ($handler->can('scanUrl') && !$self->_scanDone()) {
                          		$self->_scanDone(1);
                          		main::INFOLOG && $log->info("scanning URL $url");
                          		$handler->scanUrl($url, {
                          			client => $client,
                          			song   => $self,
                          			cb     => sub {
                          				my ( $newTrack, $error ) = @_;
                          
                          				if ($newTrack) {
                          
                          					if ($track != $newTrack) {
                          
                          						if ($self->_track() == $track) {
                          							# Update of original track, by playlist or redirection
                          							$self->_track($newTrack);
                          		[B]					$self->_currentTrackHandler(Slim::Player::ProtocolHandlers->handlerForURL($newTrack->url));[/B]
                          
                          							main::INFOLOG && $log->info("Track updated by scan: $url -> " . $newTrack->url);
                          So that should be done in the cb call in result of scanUrl. Here, if the url moves from myplugin:// to http:// then LMS will change the handler of the $song object to be a http:// handler and then it will not call anymore the functions of your PH
                          LMS 8.2 on Odroid-C4 - SqueezeAMP!, 5xRadio, 5xBoom, 2xDuet, 1xTouch, 1xSB3. Sonos PLAY:3, PLAY:5, Marantz NR1603, Foobar2000, ShairPortW, 2xChromecast Audio, Chromecast v1 and v2, Squeezelite on Pi, Yamaha WX-010, AppleTV 4, Airport Express, GGMM E5, RivaArena 1 & 3

                          Comment

                          • Paul Webster
                            Senior Member
                            • Apr 2005
                            • 10343

                            #14
                            scanUrl not being called

                            I think I had scanUrl by itself before I added getNextTrack.
                            It worked ... in that the stream played.
                            But the More display (etc) showed the real URL not the PH version ... which is what I am trying to avoid.

                            I think I'll experiment with completely removing scanUrl (having now got it being called) to see if getNextTrack is still called and if that works then I guess I will have minimal level of code which might make it easier to understand.
                            Paul Webster
                            Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
                            and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin

                            Comment

                            • philippe_44
                              Senior Member
                              • May 2008
                              • 9343

                              #15
                              Originally posted by Paul Webster
                              I think I had scanUrl by itself before I added getNextTrack.
                              It worked ... in that the stream played.
                              But the More display (etc) showed the real URL not the PH version ... which is what I am trying to avoid.

                              I think I'll experiment with completely removing scanUrl (having now got it being called) to see if getNextTrack is still called and if that works then I guess I will have minimal level of code which might make it easier to understand.
                              The Song.pm says that getNextSong() first calls scanURL if any (unless scanDone), optionally changes the song handler and *then* calls getNextTrack using *original* song's handler.
                              LMS 8.2 on Odroid-C4 - SqueezeAMP!, 5xRadio, 5xBoom, 2xDuet, 1xTouch, 1xSB3. Sonos PLAY:3, PLAY:5, Marantz NR1603, Foobar2000, ShairPortW, 2xChromecast Audio, Chromecast v1 and v2, Squeezelite on Pi, Yamaha WX-010, AppleTV 4, Airport Express, GGMM E5, RivaArena 1 & 3

                              Comment

                              Working...