Exemple #1
0
def main():
    parser = argparse.ArgumentParser(description='PyRfK Interface for liquidsoap',
                                     epilog='Anyways, this should normally not be called manually')
    parser.add_argument('--debug', action='store_true')
    subparsers = parser.add_subparsers(dest='command', help='sub-command help')

    authparser = subparsers.add_parser('auth', help='a help')
    authparser.add_argument('username')
    authparser.add_argument('password')

    metadataparser = subparsers.add_parser('meta', help='a help')
    metadataparser.add_argument('data', metavar='data', help='mostly some json encoded string from liquidsoap')
    connectparser = subparsers.add_parser('connect', help='a help')
    connectparser.add_argument('data', metavar='data', help='mostly some json encoded string from liquidsoap')
    disconnectparser = subparsers.add_parser('disconnect', help='a help')
    disconnectparser.add_argument('data', metavar='data', help='mostly some json encoded string from liquidsoap')
    playlistparser = subparsers.add_parser('playlist', help='a help')
    listenerparser = subparsers.add_parser('listenercount', help='prints total listenercount')

    args = parser.parse_args()

    rfk.init()
    rfk.database.init_db("%s://%s:%s@%s/%s" % (rfk.CONFIG.get('database', 'engine'),
                                               rfk.CONFIG.get('database', 'username'),
                                               rfk.CONFIG.get('database', 'password'),
                                               rfk.CONFIG.get('database', 'host'),
                                               rfk.CONFIG.get('database', 'database')))
    try:
        global logger
        logger = init_db_logging('liquidsoaphandler')

        logger.info(args.command)
        rfk.database.session.commit()
        if args.command == 'auth':
            doAuth(args.username, args.password)
        elif args.command == 'meta':
            data = decode_json(args.data)
            doMetaData(data)
        elif args.command == 'connect':
            data = decode_json(args.data)
            doConnect(data)
        elif args.command == 'disconnect':
            data = decode_json(args.data)
            doDisconnect(data)
        elif args.command == 'playlist':
            doPlaylist()
        elif args.command == 'listenercount':
            doListenerCount()

    except Exception as e:
        rfk.database.session.rollback()
        exc_type, exc_value, exc_tb = sys.exc_info()
        import traceback

        logger.error(''.join(traceback.format_exception(exc_type, exc_value, exc_tb)))
        rfk.database.session.commit()

    finally:
        rfk.database.session.rollback()
        rfk.database.session.remove()
Exemple #2
0
def main():
    parser = argparse.ArgumentParser(description='PyRfK Interface for liquidsoap',
                                     epilog='Anyways, this should normally not be called manually')
    parser.add_argument('--debug', action='store_true')
    subparsers = parser.add_subparsers(dest='command', help='sub-command help')

    authparser = subparsers.add_parser('auth', help='a help')
    authparser.add_argument('username')
    authparser.add_argument('password')

    metadataparser = subparsers.add_parser('meta', help='a help')
    metadataparser.add_argument('data', metavar='data', help='mostly some json encoded string from liquidsoap')
    connectparser = subparsers.add_parser('connect', help='a help')
    connectparser.add_argument('data', metavar='data', help='mostly some json encoded string from liquidsoap')
    disconnectparser = subparsers.add_parser('disconnect', help='a help')
    disconnectparser.add_argument('data', metavar='data', help='mostly some json encoded string from liquidsoap')
    playlistparser = subparsers.add_parser('playlist', help='a help')
    listenerparser = subparsers.add_parser('listenercount', help='prints total listenercount')

    args = parser.parse_args()

    rfk.init()
    rfk.database.init_db("%s://%s:%s@%s/%s" % (rfk.CONFIG.get('database', 'engine'),
                                               rfk.CONFIG.get('database', 'username'),
                                               rfk.CONFIG.get('database', 'password'),
                                               rfk.CONFIG.get('database', 'host'),
                                               rfk.CONFIG.get('database', 'database')))
    try:
        global logger
        logger = init_db_logging('liquidsoaphandler')

        logger.info(args.command)
        rfk.database.session.commit()
        if args.command == 'auth':
            doAuth(args.username, args.password)
        elif args.command == 'meta':
            data = decode_json(args.data);
            doMetaData(data)
        elif args.command == 'connect':
            data = decode_json(args.data);
            doConnect(data)
        elif args.command == 'disconnect':
            data = decode_json(args.data);
            doDisconnect(data)
        elif args.command == 'playlist':
            doPlaylist()
        elif args.command == 'listenercount':
            doListenerCount()
    except Exception as e:
        rfk.database.session.rollback()
        exc_type, exc_value, exc_tb = sys.exc_info()
        import traceback

        logger.error(''.join(traceback.format_exception(exc_type, exc_value, exc_tb)))
        rfk.database.session.commit()
    finally:
        rfk.database.session.rollback()
        rfk.database.session.remove()
Exemple #3
0
from flask import Blueprint, request, make_response

from rfk.database.streaming import Relay, Stream, StreamRelay, Listener
from rfk.database import session
from rfk.log import init_db_logging

backend = Blueprint('icecast', __name__)
logger = init_db_logging('IcecastBackend')


@backend.route('/icecast/auth', methods=['POST'])
def icecast_auth():
    logger.info('icecast_auth {}'.format(request.form))
    if request.form['action'] != 'stream_auth':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
    if relay.auth_password == request.form['pass'] and \
                    relay.auth_username == request.form['user']:
        return make_response('ok', 200, {'icecast-auth-user': '******'})
    else:
        return make_response('authentication failed', 401)


@backend.route('/icecast/add', methods=['POST'])
def icecast_add_mount():
    logger.info('add_mount {}'.format(request.form))
    if request.form['action'] != 'mount_add':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
Exemple #4
0
import rfk.database
from rfk.database import session
from rfk.database.base import User, Loop
from rfk.database.show import Show, Tag, UserShow
from rfk.database.track import Track
from rfk.database.streaming import Relay, Stream, StreamRelay, Listener

from rfk.liquidsoap import LiquidInterface

from rfk import exc as rexc
from rfk.helper import get_path, now
from rfk.log import init_db_logging


backend = Blueprint('backend', __name__)
logger = init_db_logging('backend')

# Maybe make this an configurable option?
# TODO: Make this an configurable option!
username_delimiter = '|'


def update_global_statistics():
    try:
        stat = rfk.database.stats.Statistic.query.filter(rfk.database.stats.Statistic.identifier == 'lst-total').one()
    except sqlalchemy.orm.exc.NoResultFound:
        stat = rfk.database.stats.Statistic(name='Overall Listener', identifier='lst-total')
        rfk.database.session.add(stat)
        rfk.database.session.flush()
    stat.set(now(), rfk.database.streaming.Listener.get_total_listener())
Exemple #5
0
from flask import Blueprint, request, make_response

from rfk.helper import update_global_statistics
from rfk.database.streaming import Relay, Stream, StreamRelay, Listener
from rfk.database import session
from rfk.log import init_db_logging

backend = Blueprint('icecast', __name__)
logger = init_db_logging('IcecastBackend')


@backend.route('/icecast/auth', methods=['POST'])
def icecast_auth():
    logger.info('icecast_auth {}'.format(request.form))
    if request.form['action'] != 'stream_auth':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
    if relay.auth_password == request.form['pass'] and \
                    relay.auth_username == request.form['user']:
        return make_response('ok', 200, {'icecast-auth-user': '******'})
    else:
        return make_response('authentication failed', 401)


@backend.route('/icecast/add', methods=['POST'])
def icecast_add_mount():
    logger.info('add_mount {}'.format(request.form))
    if request.form['action'] != 'mount_add':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(basedir,'lib'))

import rfk
import rfk.database 
from rfk.database.base import User, Log, Loop
from rfk.database.show import Show, Tag, UserShow
from rfk.database.track import Track
from rfk.database.streaming import Listener
from rfk.liquidsoap import LiquidInterface
from rfk import exc as rexc
from rfk.helper import get_path
from rfk.log import init_db_logging

username_delimiter = '|'
logger = init_db_logging('liquidsoaphandler')

def kick():
    """shorthand method for kicking the currently connected user
    
    returns True if someone was kicked  
    """
    liquidsoap = LiquidInterface()
    liquidsoap.connect()
    kicked = False
    for source in liquidsoap.get_sources():
        if source.status() != 'no source client connected':
            source.kick()
            kicked = True
    liquidsoap.close()
    return kicked