How do I play an HTTP music stream over SSH?

7,048

Solution 1

You can use ssh's -L flag to create a tunnel from your system to a remote:

ssh -L <localport>:<streamhost>:<streamport> <user>@<remote>

You can then connect to your end of the tunnel with mplayer as you would otherwise:

mplayer localhost:<localport>

Solution 2

You can use wget over ssh to open an HTTP connection and output stream data, then mplayer on the local machine to play it.

ssh <user>@<host> "wget <stream> -O -" | mplayer -cache 512 -

The subtleties:

  • wget's -O (capital letter oh) option sets its output file; - (dash) implies stdout.

  • mplayer's -cache option causes a configurable amount of input to be buffered, compensating for network jitter. The - (dash) option makes it read from stdin.

Try streaming SceneSat Radio, for example. http://r1.scenesat.com:8000/scenesat

Solution 3

You can set up a SOCKS proxy:

ssh -D localhost:8080 user@remotehost
mplayer http_proxy://localhost:8080/http://stream

You can use tell any other application, such as your web browser, to use this proxy too.

Solution 4

sshfs is a wonderful tool for cases like this. It hides many a firewall and allows you to use whatever player you choose (though mplayer is still a nice choice).

sudo apt-get install sshfs # your favorite packager here
sshfs [email protected]:/home/arthur/Music ~/Music

I also run Subsonic listening to port 4040 on localhost and then ssh-tunnel home with

ssh -L 4040:localhost:4040 [email protected]

I can then open Subsonic in the browser at http://localhost:4040.

Share:
7,048

Related videos on Youtube

Владислав Щербин
Author by

Владислав Щербин

Updated on September 18, 2022

Comments

  • Владислав Щербин
    Владислав Щербин almost 2 years

    I know I can just do mplayer <stream> to open and play a stream on the local machine. However, I'm behind a firewall.

    Instead, I'd like to open the stream on a remote machine, but still play it on this one. Remote connections are what SSH is for, but doing ssh "mplayer <stream>" both opens and plays the stream on the remote.

    SSH's -x flag enables X11 display forwarding. Do I need that?

  • SaultDon
    SaultDon over 10 years
    I don't even know what kind of music this is, but because I'm piping it, it's awesome! Thanks.
  • yieldsfalsehood
    yieldsfalsehood over 10 years
    Note that the question doesn't mention any particular protocol over which music is streamed. There are other protocols over which music can be streamed, for example RTP and MMS. Both can be played by mplayer, but not downloaded by wget.
  • yieldsfalsehood
    yieldsfalsehood over 10 years
    Note that this will not work if the HTTP server is using virtual domains (or in other words, requires a proper domain name sent by the client as an HTTP header). To solve this problem, you can for example temporarily add a rule to your hosts file that will make mplayer think that the target domain is hosted at local machine.
  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams over 10 years
    Or you could use -http-header-fields to force a Host header.
  • yieldsfalsehood
    yieldsfalsehood over 10 years
    Does the http_proxy feature actually work with SOCKS proxies too? The feature is undocumented in my man page, and various sites on the web prefer the tsocks approach.
  • Владислав Щербин
    Владислав Щербин over 10 years
    @liori Good point. This clearly isn't a general solution.
  • William
    William over 10 years
    @IgnacioVazquez-Abrams do you mind clarifying where? I don't such an option in man ssh.
  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams over 10 years
    @LiamWilliam: It's a mplayer option.
  • erik
    erik about 8 years
    @liori: Yes, this works together with tsocks mplayer -playlist http://bassdrive.com/bassdrive.m3u. Thanks for your advise. Without tsocks (aka only with http_proxy://…) it didn’t work.