Exemplo n.º 1
0
    def __init__(self, cfg):

        # set attributes based on config
        self.__dict__.update(cfg)
        # if name not set in config file use the directory name
        if not cfg.has_key('name'):
            self.name = cfg.dir.split(os.sep)[-1]
        # default nick to gozerbot
        if not cfg.has_key('nick'):
            self.nick = 'gozerbot'
        # default port to 0 (use default port)
        if not cfg.has_key('port'):
            self.port = 0
        # make sure bot name is not a directory
        if '..' in self.name or '/' in self.name:
            raise Exception('wrong bot name %s' % self.name)
        # set datadir to datadir/fleet/<botname>
        self.datadir = datadir + os.sep + 'fleet' + os.sep + self.name
        # bot state
        self.state = Pdod(self.datadir + os.sep + 'state')  # bot state
        # joined channels list .. used to join channels
        if not self.state.has_key('joinedchannels'):
            self.state['joinedchannels'] = []
        # allowed commands on the bot
        if not self.state.has_key('allowed'):
            self.state['allowed'] = []
        # channels we dont want ops in
        if not self.state.has_key('no-op'):
            self.state['no-op'] = []
        # channels we are op in
        if not self.state.has_key('opchan'):
            self.state['opchan'] = []
        self.cfg = cfg  # the bots config
        self.orignick = ""  # original nick
        self.blocking = True  # use blocking sockets
        self.lastoutput = 0  # time of last output
        self.stopped = False  # flag to set when bot is to be stopped
        self.connected = False  # conencted flag
        self.connecting = False  # connecting flag
        self.connectok = threading.Event()  # event set when bot has connected
        self.waitingforconnect = False  # flag to indicate we are waiting for connect
        self.starttime = time.time()  # start time of the bot
        self.nrevents = 0  # number of events processed
        self.gcevents = 0  # number of garbage collected events
        self.less = Less(5)  # output buffering
        self.userchannels = Dol()  # list of channels a user is in
        self.channels = Channels(self.datadir + os.sep +
                                 'channels')  # channels
        self.userhosts = PersistState(self.datadir + os.sep +
                                      'userhosts')  # userhosts cache
        self.splitted = []  # list of splitted nicks
        self.throttle = []  # list of nicks that need to be throttled
        self.jabber = False  # flag is set on jabber bots
        self.google = False  # flag is set on google bots

        # start runners
        runners_start()
Exemplo n.º 2
0
Arquivo: esp.py Projeto: smplgd/repo
def channel(data):
    from channels import Channels
    if data.get('PlayerObj', []):
        obj = data['PlayerObj']
        for i in obj:
            if i.get('streams', None):
                items.add(Channels(i).item)
    items.add({'mode':'epg', 'title':getString(30103), 'plot':getString(30103)})
    items.add({'mode':'sports', 'title':getString(30101), 'plot':getString(30102)})
    items.list()
Exemplo n.º 3
0
 def __init__(self):
     self.conf = Config()
     self.channels = Channels()
     self.delay = __delay__
     self.version = __version__
     self.ENCODING = "utf-8"
     self._replacer, self._endreplacer = utils._replacer, utils._endreplacer
     self.chan = []
     self.startdir = os.getcwd() + "/"
     self.disconnection = False
     self.connect()
     os.chdir(self.startdir)
Exemplo n.º 4
0
from flask_instance import FlaskInstance
from jwt_controller import JWTController
from synchronizer import Synchronizer

import logging

# Import http methods
from clients import Clients
from channels import Channels

clients = Clients()
channels = Channels()

logging.basicConfig(level=logging.DEBUG)  # Configure logging

# Configure flask
flask_app = FlaskInstance().__getinstance__
app = flask_app.get_app()

# Creating symmetric key for the server
jwt = JWTController().__get_instance__
jwt.set_global_key(jwt.generate_new_symmetric_key())
logging.info(f"Use the following key to encrypt the data in order to talk with this server in external connections: {jwt.get_global_key}")

syncker = Synchronizer().__get_instance__

# Configure endpoints
# Client endpoints
flask_app.add_endpoint('/user', "new_user", clients.add_user, ['post'])
flask_app.add_endpoint('/user/<user>', 'delete_user', clients.delete_user, ['delete'])
flask_app.add_endpoint('/users', 'get_all_users', clients.get_all_users, ['get'])
Exemplo n.º 5
0
socketio = SocketIO(app)

# Compile scss
assets = Environment(app)
assets.url = app.static_url_path
scss = Bundle(
    'sass/main.scss',
    filters='pyscss',
    depends=('**/*.scss'),
    output='styles.css')
assets.register('scss_all', scss)


# Globals
users = {}
rooms = Channels()

# Initalize channels
rooms.add_channel('general')
msg = {'text': 'Welcome to channel #general',
       'name': 'FlackBot', 'stamp': now_stamp(), 'color': cObj('#888888')}
rooms.add_message('general', msg)


@app.route("/")
def index():
    """Show chat app"""
    return render_template('index.html')


@app.route('/new_room', methods=['POST'])
Exemplo n.º 6
0
addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')
sys.path.insert(0, os.path.join(addon.getAddonInfo('path'), 'resources',
                                'lib'))

from flask import (Flask, render_template, Response, redirect, url_for,
                   request, jsonify, abort)
from channels import Channels

logging.basicConfig(format=addon.getSetting('log_format'),
                    level=addon.getSetting('log_level'),
                    filename=os.path.join(addon.getAddonInfo('path'),
                                          'addon.log'))
logger = logging.getLogger(__name__)
app = Flask(__name__)
chls = Channels()


def jsonloads(value):
    try:
        return json.loads(value)
    except:
        return value


@app.route('/')
def home():
    return render_template('home.html')


@app.route('/api/groups/get')
Exemplo n.º 7
0
def startservice(openetv_config, logging):
    # set startup defaults
    bouquet_id = 0
    bouquet_name = None
    bouquet_ref = None

    max_bouquets = 1000
    max_channels = 1000

    vlc_quality = "good"

    # create the bouquets and channels objects
    r_bouquets = Bouquets(openetv_config, logging)
    r_channels = Channels(openetv_config, logging, max_channels)

    # refresh bouquet list
    rb_res = r_bouquets.refresh_bouquet_list()

    # check if the bouquet list is successfully fetched
    if rb_res:
        # get bouquet list
        html_bouquets = r_bouquets.list_bouquets()

        # get bouquet name and ref
        bouquet = r_bouquets.set_active_bouquet(bouquet_id)
        bouquet_name = bouquet[0]
        bouquet_ref = bouquet[1]

        # refresh the channel list
        rc_res = r_channels.refresh_channel_list(bouquet_name, bouquet_ref)

        # socket/bind/listen setup
        s = socket.socket()
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind((openetv_config['openetv']['bind_host'],
                int(openetv_config['openetv']['bind_port'])))
        s.listen(5)

        while True:
            c, addr = s.accept()

            logging.debug("[App::run] debug: incomming connection from: " +
                          addr[0] + ":%d" % addr[1])

            # recieve HTTP command
            cmd = c.recv(1024).split('\n')[0]

            logging.debug("[App::run] debug: command [" + cmd + "]")

            if cmd[:3] == "GET":
                page = cmd.split(' ')[1]

                logging.debug("[App::run] debug: page request [" + page + "]")

                # get current active channels
                active_channel = r_channels.get_active_channel()
                active_channel_name = r_channels.get_active_channel_name()

                if page == "/" or page == "/index.htm" or page == "index.html":
                    """
                    Expected parameters: none
                    """

                    html = html_header(openetv_config)

                    if rb_res:
                        html += r_bouquets.list_bouquets()
                    else:
                        html += "<b>Error: could not get bouquet list!</b>"

                    if rc_res:
                        html += r_channels.list_channels()

                    html += html_menu(openetv_config, vlc_quality,
                                      active_channel, active_channel_name,
                                      max_channels)
                    html += html_footer(openetv_config)

                    write_data = "HTTP/1.1 200 OK\n"
                    write_data += "Content-Length: %d\n" % len(html)
                    write_data += "Content-Type: text/html\n\n"
                    write_data += html

                    c.send(write_data)
                elif page[:8] == "/quality":
                    """
                    Expected parameters: /quality=<poor|medium|good>
                    """

                    q_str = page.split('=')[1]

                    if q_str == "poor":
                        vlc_quality = "poor"
                    elif q_str == "medium":
                        vlc_quality = "medium"
                    else:
                        vlc_quality = "good"

                    logging.debug("[App::run] debug: quality changed to [" +
                                  q_str + "]")

                    html = html_header(openetv_config)

                    if rb_res:
                        html += r_bouquets.list_bouquets()
                    else:
                        html += "<b>Error: could not get bouquet list!</b>"

                    if rc_res:
                        html += r_channels.list_channels()

                    html += html_menu(openetv_config, vlc_quality,
                                      active_channel, active_channel_name,
                                      max_channels)
                    html += html_footer(openetv_config)

                    write_data = "HTTP/1.1 200 OK\n"
                    write_data += "Content-Length: %d\n" % len(html)
                    write_data += "Content-Type: text/html\n\n"
                    write_data += html

                    c.send(write_data)
                elif page[:8] == "/bouquet":
                    """
                    Expected parameters: /bouquet=<bouquet-id>
                    """

                    bid = page.split('=')[1]

                    logging.debug(
                        "[App::run] debug: changing bouquet list to [" + bid +
                        "]")

                    try:
                        id = int(bid)
                    except ValueError:
                        html = html_header(openetv_config)

                        if rb_res:
                            html += r_bouquets.list_bouquets()
                        else:
                            html += "<b>Error: could not get bouquet list!</b>"

                        html += html_menu(openetv_config, vlc_quality,
                                          active_channel, active_channel_name,
                                          max_channels)
                        html += "<b>Error: bouquet id is invalid!</b><br>"
                        html += html_footer(openetv_config)

                        write_data = "HTTP/1.1 200 OK\n"
                        write_data += "Content-Length: %d\n" % len(html)
                        write_data += "Content-Type: text/html\n\n"
                        write_data += html

                        c.send(write_data)
                        c.close()

                    if not 0 <= int(bid) < max_bouquets:
                        html = html_header(openetv_config)

                        if rb_res:
                            html += r_bouquets.list_bouquets()
                        else:
                            html += "<b>Error: could not get bouquet list!</b>"

                        html += html_menu(openetv_config, vlc_quality,
                                          active_channel, active_channel_name,
                                          max_channels)
                        html += "<b>Error: bouquetplaylist id is not in range between 0 and 999!</b><br>"
                        html += html_footer(openetv_config)

                        write_data = "HTTP/1.1 200 OK\n"
                        write_data += "Content-Length: %d\n" % len(html)
                        write_data += "Content-Type: text/html\n\n"
                        write_data += html

                        c.send(write_data)
                        c.close()

                    if rb_res:
                        # select bouquet
                        bouquet_id = id
                        bouquet = r_bouquets.set_active_bouquet(bouquet_id)
                        bouquet_name = bouquet[0]
                        bouquet_ref = bouquet[1]

                    html = html_header(openetv_config)

                    if rb_res:
                        html += r_bouquets.list_bouquets()
                    else:
                        html += "<b>Error: could not get bouquet list!</b>"

                    # refresh the channels
                    rc_res = r_channels.refresh_channel_list(
                        bouquet_name, bouquet_ref)
                    if rc_res:
                        html += r_channels.list_channels()

                    html += html_menu(openetv_config, vlc_quality,
                                      active_channel, active_channel_name,
                                      max_channels)
                    html += html_footer(openetv_config)

                    write_data = "HTTP/1.1 200 OK\n"
                    write_data += "Content-Length: %d\n" % len(html)
                    write_data += "Content-Type: text/html\n\n"
                    write_data += html

                    c.send(write_data)
                elif page[:6] == "/start":
                    """
                    Expected parameters: /start=<channel-id>
                    """

                    cid = page.split('=')[1]

                    logging.debug("[App::run] debug: start channel id [" +
                                  cid + "]")

                    try:
                        id = int(cid)
                    except ValueError:
                        html = html_header(openetv_config)

                        if rb_res:
                            html += r_bouquets.list_bouquets()
                        else:
                            html += "<b>Error: could not get bouquet list!</b>"

                        html += html_menu(openetv_config, vlc_quality,
                                          active_channel, active_channel_name,
                                          max_channels)
                        html += "<b>Error: playlist id is invalid!</b><br>"
                        html += html_footer(openetv_config)

                        write_data = "HTTP/1.1 200 OK\n"
                        write_data += "Content-Length: %d\n" % len(html)
                        write_data += "Content-Type: text/html\n\n"
                        write_data += html

                        c.send(write_data)
                        c.close()

                    if not 0 <= int(id) < max_channels:
                        html = html_header(openetv_config)

                        if rb_res:
                            html += r_bouquets.list_bouquets()
                        else:
                            html += "<b>Error: could not get bouquet list!</b>"

                        html += html_menu(openetv_config, vlc_quality,
                                          active_channel, active_channel_name,
                                          max_channels)
                        html += "<b>Error: playlist id is not in range between 0 and 999!</b><br>"
                        html += html_footer(openetv_config)

                        write_data = "HTTP/1.1 200 OK\n"
                        write_data += "Content-Length: %d\n" % len(html)
                        write_data += "Content-Type: text/html\n\n"
                        write_data += html

                        c.send(write_data)
                        c.close()

                    html = html_header(openetv_config)

                    if rb_res:
                        html += r_bouquets.list_bouquets()
                    else:
                        html += "<b>Error: could not get bouquet list!</b>"

                    # play the selected channel
                    r_channels.play_channel(id, vlc_quality)

                    # get current active channels
                    active_channel = r_channels.get_active_channel()
                    active_channel_name = r_channels.get_active_channel_name()

                    if rc_res:
                        html += r_channels.list_channels()

                    html += html_menu(openetv_config, vlc_quality,
                                      active_channel, active_channel_name,
                                      max_channels)
                    html += html_footer(openetv_config)

                    write_data = "HTTP/1.1 200 OK\n"
                    write_data += "Content-Length: %d\n" % len(html)
                    write_data += "Content-Type: text/html\n\n"
                    write_data += html

                    c.send(write_data)

                    # shutdown the socket, otherwise the client still thinks it recieves data
                    c.shutdown(socket.SHUT_RDWR)
                elif page[:5] == "/stop":
                    """
                    Expected parameters: none
                    """

                    logging.debug("[App::run] debug: stop channel id [%d" %
                                  active_channel + "]")

                    if active_channel < max_channels:
                        html = html_header(openetv_config)

                        if rb_res:
                            html += r_bouquets.list_bouquets()
                        else:
                            html += "<b>Error: could not get bouquet list!</b>"

                        # stop the transcoding process
                        stop_res = r_channels.stop_channel()

                        # get current active channels
                        active_channel = r_channels.get_active_channel()
                        active_channel_name = r_channels.get_active_channel_name(
                        )

                        if rc_res:
                            html += r_channels.list_channels()

                        html += html_menu(openetv_config, vlc_quality,
                                          active_channel, active_channel_name,
                                          max_channels)

                        if not stop_res:
                            html += "<b>Error: unable to stop stream, nothing is playing!</b><br>\n"

                        html += html_footer(openetv_config)
                    else:
                        html = html_header(openetv_config)

                        if rb_res:
                            html += r_bouquets.list_bouquets()
                        else:
                            html += "<b>Error: could not get bouquet list!</b>"

                        if rc_res:
                            html += r_channels.list_channels()

                        html += html_menu(openetv_config, vlc_quality,
                                          active_channel, active_channel_name,
                                          max_channels)
                        html += html_footer(openetv_config)

                    write_data = "HTTP/1.1 200 OK\n"
                    write_data += "Content-Length: %d\n" % len(html)
                    write_data += "Content-Type: text/html\n\n"
                    write_data += html

                    c.send(write_data)
                elif page[:8] == "/refresh":
                    """
                    Expected parameters: "bouquet" or "channel"
                    """

                    type = page.split('=')[1]

                    html = html_header(openetv_config)

                    # refresh bouquets
                    if type == "bouquet":
                        rb_res = r_bouquets.refresh_bouquet_list()

                    if rb_res:
                        html += r_bouquets.list_bouquets()

                        # refresh the channel list
                        if type == "channel":
                            rc_res = r_channels.refresh_channel_list(
                                bouquet_name, bouquet_ref)

                        if rc_res:
                            html += r_channels.list_channels()
                    else:
                        html += "<b>Error: could not get bouquet list!</b>"

                    html += html_menu(openetv_config, vlc_quality,
                                      active_channel, active_channel_name,
                                      max_channels)
                    html += html_footer(openetv_config)

                    write_data = "HTTP/1.1 200 OK\n"
                    write_data += "Content-Length: %d\n" % len(html)
                    write_data += "Content-Type: text/html\n\n"
                    write_data += html

                    c.send(write_data)

            logging.debug("[App::run] closing connection")

            c.close()