Perl: How to get the link target of a soundcloud feed mp3

320 views Asked by At

I would like to retrieve the mp3 link target of an mp3 in a soundcloud feed in perl, for example the ultimate location of this podcast url: http://feeds.soundcloud.com/stream/176971524-thetalkshow-thetalkshow-100.mp3

If I try to stream it resolves into a comlex http://ec-media.soundcloud.com/.... address.

Is there any possibility to get this resolved ec-media.soundcloud address in Perl?

I've already tried the following code, but without success

use LWP::UserAgent qw();
my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://feeds.soundcloud.com/stream/176971524-thetalkshow-thetalkshow-100.mp3');
print $response->request->uri . "\n";
2

There are 2 answers

2
Miguel Prz On

You can download the mp3 file with LWP::Simple:

use strict;
use warnings;
use LWP::Simple;
my $url = "http://feeds.soundcloud.com/stream/176971524-thetalkshow-thetalkshow-100.mp3";
getstore($url, "my-file-name.mp3");
4
javamonk On

You mean get the 301 or 302 redirect address. Just disable auto redirect.

use LWP::UserAgent qw();
my $ua = LWP::UserAgent->new;
$ua->max_redirect(0); # disable auto redirect
my $response = $ua->get('http://feeds.soundcloud.com/stream/176971524-thetalkshow-thetalkshow-100.mp3');
print "new location: " . $response->header('Location');