Watching sopcast from the command line

SopCast is a simple, free way to broadcast video and audio or watch the video and listen to radio on the Internet, adopting P2P(Peer-to-Peer) technology. In order to be able to watch sopcast streams you need to start the p2p client and once the p2p connection is established connect a video player to a local network port. My script automates these tasks, adds some sanity checks and cleans up any remaining processes.

In order to watch a sopcast stream all you need is the Linux client, which you can get at
As the client is written in C++ you need a libstdc++ V5.
If there is no on your system you can get a copy from the same site.

My script expects libstdc++ library right next to the sp-sc-auth binary itself. I chose this setup, so the remaining system is not contaminated with a potential incompatible libstdc++ library.

The script takes and requires only one argument, the sop URL, e.g.:

# ./ sop://<CHANNEL_ID>

First thing the script spawns the sp-sc-auth process in the background. Afterwards it waits up to ten seconds for the sopcast client to open a local network port (8908), which signals the connection to the requested stream is about to be established. Once that happens the configured video player is started connecting to the local port.

I use mpv, a fork of the popular mplayer.
Adjust the value of VIDEO_PLAYER_CMD at the top of the script to accommodate your favourite player.

That's it, enjoy watching TV ( your favourite sports event ;-) ) from the cmdline !

#set -x

VIDEO_PLAYER_CMD="mpv --quiet --idle=yes"

# Some basic sanity check for the URL
[[ $URL =~ ^sop:// ]] || { echo "Usage: $0 sop://URL"; exit 1; }

# Make sure local port is not in use
netstat -vant | grep 8908 | grep -q LISTEN && { echo "Port 8908 is in use, aborting!"; exit 1; }

# add locale
cd $(dirname $0)
export LD_LIBRARY_PATH=$(pwd)

./sp-sc-auth $URL 3908 8908 >/dev/null &

cleanup () {
    ps | grep -q $_PID && kill $_PID


# Wait up to 10 seconds to connect
until [ $n -ge 10 ]; do
    # if sp-auth died, exit
    ps | grep -q $_PID || exit 1

    netstat -vant | grep 8908 | grep -q LISTEN && break
    sleep 1

$VIDEO_PLAYER_CMD http://localhost:8908/tv.asf