Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Mar 2011
    Posts
    131

    Rewrite a URL before redirect

    I am trying to fix some functionality of the SoundCloud plugin. One challenge is that the SoundCloud API does a 302 redirect. Even if the first URL is on HTTP, the redirect is always pointing to HTTPS. This is a problem, because it leads to connection timeouts. Can I rewrite the redirect URL before it is processed?

    I am using Slim::Networking::SimpleAsyncHTTP->new(&\success, \&error)->get($url) to retieve the URL that does a redirect. Async::HTTP appears to have a onRedirect option, but it seams that SimpleAsyncHTTP does not pass that through if I add 'onRedirect => &\onRedirct' as a third argument to the new() function.
    Am I doing something wrong, or is that any other way to either stop the redirect, get the redirect URL, and send a new request?
    My patch: Reduce brightness when screen saver is active for Touch
    Source code: GitHub for SqueezeCloud, Mixcloud, 22tracks and YouTube (old version)

  2. #2
    Senior Member
    Join Date
    May 2008
    Location
    Canada
    Posts
    3,113
    Quote Originally Posted by 505 View Post
    I am trying to fix some functionality of the SoundCloud plugin. One challenge is that the SoundCloud API does a 302 redirect. Even if the first URL is on HTTP, the redirect is always pointing to HTTPS. This is a problem, because it leads to connection timeouts. Can I rewrite the redirect URL before it is processed?

    I am using Slim::Networking::SimpleAsyncHTTP->new(&\success, \&error)->get($url) to retieve the URL that does a redirect. Async::HTTP appears to have a onRedirect option, but it seams that SimpleAsyncHTTP does not pass that through if I add 'onRedirect => &\onRedirct' as a third argument to the new() function.
    Am I doing something wrong, or is that any other way to either stop the redirect, get the redirect URL, and send a new request?
    I'm not sure this is answering your question, but if the soundclound plugin has a protocolhandler, you can overload there various functions of the base class that allow you to tweak the url. For example, in the Shairtunes2 plugin:
    Code:
    sub new {
        my $class  = shift;
        my $args   = shift;
        
        my $client = $args->{client};
        my $song   = $args->{song};
    	my $url    = $args->{url};
    	
    	$url =~ s/airplay/http/;
        ...
    You can look as well the YouTube plugin code code for more
    LMS 7.7, 7.8 and 7.9 - 5xRadio, 3xBoom, 4xDuet, 1xTouch, 1 SB2. Sonos PLAY:3, PLAY:5, Marantz NR1603, JBL OnBeat, XBoxOne, XBMC, Foobar2000, ShairPortW, JRiver 21, 2xChromecast Audio, Chromecast v1 and v2, , Pi B3, B2, Pi B+, 2xPi A+, Odroid-C1, Odroid-C2, Cubie2, Yamaha WX-010, AppleTV 4, Airport Express

Tags for this Thread

Posting Permissions

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