1

I am trying to get the final download file name of an mp3 from a server, specifically audiotool.com

e.g. http://api.audiotool.com/track/haunt_opaque/mixdown.mp3

When you navigate to this url in a web browser it starts downloading a file with a name that contains the full info for the song

e.g. "opaqity - Haunt (opaque).mp3"

Is it possible to get the final download name from the top link using a standard linux command such as curl? I have already tried using a few redirect finder commands with curl, but none have worked.

Thank you for your help

3 Answers 3

0
echo -e "GET /track/haunt_opaque/mixdown.mp3 HTTP/1.1\nHost: api.audiotool.com\n\n" | nc -q 3 api.audiotool.com 80 | head -n 20 | grep -a "^Content-Disposition:" | cut -d = -f 2

Output:

"opaqity - Haunt (opaque).mp3"
3
  • what is nc -q for? I get this error when I try to run it in cygwin nc: unknown option -- q
    – Sun
    Commented Sep 27, 2014 at 7:45
  • From man netcat: -q: after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever.
    – Cyrus
    Commented Sep 27, 2014 at 7:51
  • I guess it is not an option on the Cygwin distribution
    – Sun
    Commented Sep 27, 2014 at 7:52
0

Using wget, the file is saved, as the URL specifies, asmixdown.mp3. If wget -S is used, the full name, if you want it, is shown under the Content-Disposition disposition header:

$ wget -S http://api.audiotool.com/track/haunt_opaque/mixdown.mp3
--2014-09-26 15:34:19--  http://api.audiotool.com/track/haunt_opaque/mixdown.mp3
Resolving api.audiotool.com (api.audiotool.com)... 144.76.222.84
Connecting to api.audiotool.com (api.audiotool.com)|144.76.222.84|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Server: nginx/1.5.6
  Date: Fri, 26 Sep 2014 22:34:20 GMT
  Content-Type: audio/mpeg
  Transfer-Encoding: chunked
  Connection: keep-alive
  Keep-Alive: timeout=65
  Access-Control-Allow-Origin: *
  Expires: Fri, 26 Sep 2014 22:34:20 GMT
  Cache-Control: no-cache, private, no-store
  Content-Disposition: attachment; filename="opaqity - Haunt (opaque).mp3"
  Pragma: no-cache
  X-Lift-Version: 2.4
Length: unspecified [audio/mpeg]
Saving to: `mixdown.mp3'

    [                              <=>                               ] 4,499,633    784K/s   in 7.0s    

2014-09-26 15:34:27 (630 KB/s) - `mixdown.mp3' saved [4499633]
0

Anyway, this will not tell you the remote file name until the transfer of the file is complete:

user@server ~
$ curl --remote-header-name --remote-name http://api.audiotool.com/track/haunt_opaque/mixdown.mp3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 4394k    0 4394k    0     0   167k      0 --:--:--  0:00:26 --:--:--  294k
curl: Saved to filename 'opaqity - Haunt (opaque).mp3'

I was able to get the response headers Chrome Developer Tools with the Content-Disposition header value. Not sure why curl was having problems, but I suspect it has to do with nginx performance reasons.

HTTP/1.1 200 OK
Server: nginx/1.5.6
Date: Fri, 26 Sep 2014 22:08:05 GMT
Content-Type: audio/mpeg
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=65
Access-Control-Allow-Origin: *
Expires: Fri, 26 Sep 2014 22:08:05 GMT
Cache-Control: no-cache, private, no-store
Content-Disposition: attachment; filename="opaqity - Haunt (opaque).mp3"
Pragma: no-cache
X-Lift-Version: 2.4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .