Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    6,296

    Accessing data in songStreamController

    I am trying to resolve an issue that I have had for ages ... where a stream URL changes because of a redirect and then the new stream URL no longer matches a regex that I have in place.
    I have been getting around this by working out a set of regex matches that work for the original and for the one redirected to but have now hit one that this is not feasible to do.

    So - time has come to do it properly and use the original URL.

    I do this because I have to set up a timer to call me back to go out and find metadata for the currently playing song (since it is not in the stream metadata).

    My recollection of the history of this is that if my timer expires but the listener has changed to play something else then I must not overwrite the now playing information with the track info from what is now the previous station being listened to ... so I get the current stream via

    Code:
    my $song = $client->playingSong();
    if ( $song && $song->streamUrl ) { $playingURL = $song->streamUrl}
    However, I dumped out a bunch of stuff and saw ... (edited) ...

    Code:
    'songStreamController' => bless( [
                                                                 bless( [
                                                                          'Slim::Player::Protocols::HTTPS',
                                                                          0,
                                                                          bless( [
                                                                                   -157146472,
                                                                                   1,
                                                                                   undef,
                                                                                   undef,
                                                                                   'h t t p s ://currentlyplaying.stream/mp3',
                                                                                   'h t t p://originally.launched.stream/mp3',
                                                                                   'mp3',
                                                                                   192000,
                                                                                   0,
                                                                                   undef,
                                                                                   undef,
                                                                                   undef,
                                                                                   undef,
                                                                                   undef,
                                                                                   'station name',
    So my question ... what is the correct way to get those 2 URLs from songStreamController ?
    Is the first one the same as
    $song->streamUrl

    I tried to find where the blessed object is defined but without luck so far.
    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

  2. #2
    Senior Member
    Join Date
    Aug 2014
    Location
    UK
    Posts
    751
    Quote Originally Posted by Paul Webster View Post
    I am trying to resolve an issue that I have had for ages ... where a stream URL changes because of a redirect and then the new stream URL no longer matches a regex that I have in place.
    I have been getting around this by working out a set of regex matches that work for the original and for the one redirected to but have now hit one that this is not feasible to do.

    So - time has come to do it properly and use the original URL.

    I do this because I have to set up a timer to call me back to go out and find metadata for the currently playing song (since it is not in the stream metadata).

    My recollection of the history of this is that if my timer expires but the listener has changed to play something else then I must not overwrite the now playing information with the track info from what is now the previous station being listened to ... so I get the current stream via

    Code:
    my $song = $client->playingSong();
    if ( $song && $song->streamUrl ) { $playingURL = $song->streamUrl}
    However, I dumped out a bunch of stuff and saw ... (edited) ...

    Code:
    'songStreamController' => bless( [
                                                                 bless( [
                                                                          'Slim::Player::Protocols::HTTPS',
                                                                          0,
                                                                          bless( [
                                                                                   -157146472,
                                                                                   1,
                                                                                   undef,
                                                                                   undef,
                                                                                   'h t t p s ://currentlyplaying.stream/mp3',
                                                                                   'h t t p://originally.launched.stream/mp3',
                                                                                   'mp3',
                                                                                   192000,
                                                                                   0,
                                                                                   undef,
                                                                                   undef,
                                                                                   undef,
                                                                                   undef,
                                                                                   undef,
                                                                                   'station name',
    So my question ... what is the correct way to get those 2 URLs from songStreamController ?
    Is the first one the same as
    $song->streamUrl

    I tried to find where the blessed object is defined but without luck so far.
    This might be correct, it certainly is with protocol handlers when I handle the redirect myself :

    original URL is : $song->track()->url
    actual URL is : $song->streamUrl
    Last edited by expectingtofly; 2022-05-17 at 06:01. Reason: Got them the wrong way around!
    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.

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    6,296
    Just tried examining $song->track()->url ... and it is the redirected to URL in my case.

    Perhaps because I do not have my own protocol handler in this case (and don't really want one in this plugin - at least while I can avoid it) ... so maybe http/https protocol handler has already handled it and updated $song->track()->url to point to the accepted redirection.

    I /think/ that Slim/Schema/RemoteTrack.pm is where the blessed structure is defined ... and if it is then attribute "redir" might be the one I need ... which would be somewhat unintuitive if correct (it comes after _url and before content_type and bitrate ... which seems to match the array dump).

    I see that there is a "get" routine in there so maybe I need to call it with "redir" ... next step is to work out how to do that.

    Edit:
    Aha ... from developers.txt
    That $song contains a $track object that is created from the original $url set when OPML item is
    added in the playlist. When scanning $url, the Slim::Utils::Scanner::Remote::scanURL creates a new
    $track object everytime the uri returned by the GET is different from the $url argument. This
    happens on HTTP redirection and if the $url argument differs from $args->{'song'}->track->url. The
    original url is stored as $track->redir (note that it might be empty).
    Last edited by Paul Webster; 2022-05-17 at 07:12.
    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

  4. #4
    Senior Member
    Join Date
    Apr 2005
    Location
    UK/London
    Posts
    6,296
    Looking promising ...
    $song->track()->redir does seem to hold the original URL.
    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

Posting Permissions

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