Proxying Acestream to Phone / TVs from a Pi

Proxying Acestream to Phone / TVs from a Pi

ACESTREAM is a streaming software – I used to run a proxy service on AWS such that I could watch ACESTREAMS via a http link on my devices such as mobile phones, or Smart TVs. Once the free tier expired, I anticipated costs would be rather expensive so I switched it to run on my Orange Pi which is a US$15-US$20 small board computer.

How to

I run Armbian OS on my Orange Pi or you can use any standard Linux distro on Raspberry Pi / similar arm-based small board computers. Steps are similar if you want to run in on an x86 machine, just get the appropriate acestream. Open a terminal and run the following :

git clone https://github.com/pepsik-kiev/aceproxy
cd aceproxy
sudo pip2 install -r requirements.txt
sudo apt-get install vlc
git clone https://github.com/sestus/acestream-openelec
mv acestream-openelec/acestream .
rm -rf acestream-openelec/

Edit aceconfig.py with the following parameters:

acespwan = True
acecmd = "acestream/start_acestream.sh --client-console"

Now run:

./acehttp.py

You are installing:
1) AceProxy and it allows you to watch Ace Stream live streams or BitTorrent files over HTTP. It’s written in Python.
2) acestream-openelec is a chroot version of Acestream engine, which allows it run on an arm device, which is the processor for your small board computers
3) VLC works in conjunction with Aceproxy to buffer the network stream

Once you start up aceproxy, you can get your device to load streams by browsing to:

http://<>:8000/pid//stream.mp4
e.g.:http://192.168.0.1:8000/pid/1234567890123456789012345678901234567890/stream.mp4

Aceproxy allows you to add plugins too. There are more details on the Wiki. I added a simple plugin where if I am already watching an Acestream, request to /tv/stream will share the first available stream. Otherwise, I can append tv/stream/ to load that channel.

import urllib2
import urlparse
import os.path
from modules.PluginInterface import AceProxyPlugin

EXTERNAL_URL = "/tv"

class Current(AceProxyPlugin):
    handlers = ('stream', 'favicon.ico')

    def __init__(self, AceConfig, AceStuff):
        self.config = AceConfig
        self.stuff = AceStuff

    def handle(self, connection, headers_only=False):

        request = os.path.basename(os.path.normpath(connection.path))

        if request == "stream":
            cid = "empty"
            for i in self.stuff.clientcounter.clients:
                cid = i
            if cid == "empty":
                redirect = "https://i.ytimg.com/vi/qoAXey2ujf4/maxresdefault.jpg"
            else:
                redirect = EXTERNAL_URL + "/pid/" + cid + "/stream.mp4"
        else:
            redirect = EXTERNAL_URL + "/pid/" + request + "/stream.mp4"

        connection.send_response(302)
        connection.send_header('Location', redirect)
        connection.end_headers()

What is it for

I run it as a background service on my Orange Pi, which I leave it on almost all the time. I am able to watch Acestream channels from any device that can handle a HTTP stream – tablets, phones, smart TVs using this proxy. Sources such as : https://acestreamid.com/ are available – and I simplify it further by hosting the proxy service behind an Apache server, which could do other things such as 1) parse the updated Acestream links, 2) automatically grab the latest Acestream links like for the Match of the Day types.