Exemple #1
0
def listeners():

    # get current bandwidth of all active relays
    total_bandwidth = 0
    relays = Relay.query.filter(Relay.status == Relay.STATUS.ONLINE).all()
    active_relays = len(relays)
    for relay in relays:
        total_bandwidth += relay.usage
    total_bandwidth *= 128  # convert kbit to byte

    # get all current listeners
    current_listener = Listener.get_current_listeners()

    # generate per country stats
    per_country = {}
    for listener in current_listener:
        country = listener.country
        try:
            per_country[country]['count'] += 1
        except KeyError:
            per_country[country] = {'count': 1}
            per_country[country]['ball'] = iso_country_to_countryball(country)
    per_country = sorted(per_country.iteritems(),
                         key=lambda (k, v): v['count'],
                         reverse=True)

    return render_template('listenergraph.html',
                           TITLE='Listeners',
                           listeners=current_listener,
                           per_country=per_country,
                           total_bandwidth=total_bandwidth,
                           active_relays=active_relays)
Exemple #2
0
def liquidsoap_listener_count():
    """This mimics an icecast2 statistic output so clients will display the total listener count

    """

    lc = Listener.get_total_listener()
    return '<icestats><source mount=\"/live.ogg\"><listeners>%d</listeners><Listeners>%d</Listeners></source></icestats>' % (lc, lc,)
Exemple #3
0
def disco():
    show = Show.get_active_show()
    ret = {}
    if show:
        user = show.get_active_user()
        ret['countryball'] = iso_country_to_countryball(user.country)
        ret['logo'] = show.get_logo(),
    else:
        ret['countryball'] = False
        ret['logo'] = False
    track = Track.current_track()
    if track:
        ret['track'] = {
            'title': track.title.name,
            'artist': track.title.artist.name,
        }
        #get listenerinfo for disco
    listeners = Listener.get_current_listeners()
    ret['listener'] = {}
    for listener in listeners:
        ret['listener'][listener.listener] = {
            'listener': listener.listener,
            'county': listener.country,
            'countryball': iso_country_to_countryball(listener.country)
        }
    return ret
Exemple #4
0
def listeners():

    # get current bandwidth of all active relays
    total_bandwidth = 0
    relays = Relay.query.filter(Relay.status == Relay.STATUS.ONLINE).all()
    active_relays = len(relays)
    for relay in relays:
        total_bandwidth += relay.usage
    total_bandwidth *= 128 # convert kbit to byte

    # get all current listeners
    current_listener = Listener.get_current_listeners()

    # generate per country stats
    per_country = {}
    for listener in current_listener:
        country = listener.country
        try:
            per_country[country]['count'] += 1
        except KeyError:
            per_country[country] = {'count': 1}
            per_country[country]['ball'] = iso_country_to_countryball(country)
    per_country = sorted(per_country.iteritems(), key=lambda (k, v): v['count'], reverse=True)

    return render_template('listenergraph.html', TITLE='Listeners', listeners=current_listener, per_country=per_country,
                           total_bandwidth=total_bandwidth, active_relays=active_relays)
Exemple #5
0
def now_playing():
    try:
        ret = {}
        #gather showinfos
        show = Show.get_active_show()
        if show:
            user = show.get_active_user()
            if show.end:
                end = to_timestamp(to_user_timezone(show.end))
            else:
                end = None
            ret['show'] = {'id': show.show,
                           'name': show.name,
                           'begin': to_timestamp(to_user_timezone(show.begin)),
                           'now': to_timestamp(to_user_timezone(now())),
                           'end': end,
                           'logo': show.get_logo(),
                           'type': Show.FLAGS.name(show.flags),
                           'user': {'countryball': iso_country_to_countryball(user.country)}
            }
            if show.series:
                ret['series'] = {'name': show.series.name}
            link_users = []
            for ushow in show.users:
                link_users.append(make_user_link(ushow.user))
            ret['users'] = {'links': natural_join(link_users)}

        #gather trackinfos
        track = Track.current_track()
        if track:
            ret['track'] = {'title': track.title.name,
                            'artist': track.title.artist.name,
            }

        #gather nextshow infos
        if show and show.end:
            filter_begin = show.end
        else:
            filter_begin = now()
        if request.args.get('full') == 'true':
            nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first();
            if nextshow:
                ret['nextshow'] = {'name': nextshow.name,
                                   'begin': to_timestamp(to_user_timezone(nextshow.begin)),
                                   'logo': nextshow.get_logo()}
                if nextshow.series:
                    ret['nextshow']['series'] = nextshow.series.name

        #get listenerinfo for disco
        listeners = Listener.get_current_listeners()
        ret['listener'] = {}
        for listener in listeners:
            ret['listener'][listener.listener] = {'listener': listener.listener,
                                                  'county': listener.country,
                                                  'countryball': iso_country_to_countryball(listener.country)}
        return jsonify({'success': True, 'data': ret})
    except Exception as e:
        raise e
        return jsonify({'success': False, 'data': unicode(e)})
Exemple #6
0
def now_playing():
    try:
        ret = {}
        #gather showinfos
        show = Show.get_active_show()
        if show:
            user = show.get_active_user()
            if show.end:
                end = to_timestamp(to_user_timezone(show.end))
            else:
                end = None
            ret['show'] = {'id': show.show,
                           'name': show.name,
                           'begin': to_timestamp(to_user_timezone(show.begin)),
                           'now': to_timestamp(to_user_timezone(now())),
                           'end': end,
                           'logo': show.get_logo(),
                           'type': Show.FLAGS.name(show.flags),
                           'user': {'countryball': iso_country_to_countryball(user.country)}
            }
            if show.series:
                ret['series'] = {'name': show.series.name}
            link_users = []
            for ushow in show.users:
                link_users.append(make_user_link(ushow.user))
            ret['users'] = {'links': natural_join(link_users)}

        #gather trackinfos
        track = Track.current_track()
        if track:
            ret['track'] = {'title': track.title.name,
                            'artist': track.title.artist.name,
            }

        #gather nextshow infos
        if show and show.end:
            filter_begin = show.end
        else:
            filter_begin = now()
        if request.args.get('full') == 'true':
            nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first();
            if nextshow:
                ret['nextshow'] = {'name': nextshow.name,
                                   'begin': to_timestamp(to_user_timezone(nextshow.begin)),
                                   'logo': nextshow.get_logo()}
                if nextshow.series:
                    ret['nextshow']['series'] = nextshow.series.name

        #get listenerinfo for disco
        listeners = Listener.get_current_listeners()
        ret['listener'] = {}
        for listener in listeners:
            ret['listener'][listener.listener] = {'listener': listener.listener,
                                                  'county': listener.country,
                                                  'countryball': iso_country_to_countryball(listener.country)}
        return jsonify({'success': True, 'data': ret})
    except Exception as e:
        raise e
        return jsonify({'success': False, 'data': unicode(e)})
Exemple #7
0
def doListenerCount():
    lc = Listener.get_total_listener()
    sys.stdout.write(
        "<icestats><source mount=\"/live.ogg\"><listeners>%d</listeners><Listeners>%d</Listeners></source></icestats>"
        % (
            lc,
            lc,
        ))
Exemple #8
0
def listeners():

    # check if current_user is logged in and if user is streaming or if user is admin
    if not current_user.is_anonymous():
        is_streaming = UserShow.query.join(User).filter(UserShow.status == UserShow.STATUS.STREAMING, UserShow.user == current_user).first()
        if is_streaming or current_user.has_permission('admin'):
            show_listener_list = True
        else:
            show_listener_list = False
    else:
        show_listener_list = False

    # get current bandwidth of all active relays
    total_bandwidth = 0
    relays = Relay.query.filter(Relay.status == Relay.STATUS.ONLINE).all()
    active_relays = len(relays)
    for relay in relays:
        total_bandwidth += relay.usage
    total_bandwidth *= 128 # convert kbit to byte

    # get all current listeners
    current_listener = Listener.get_current_listeners()

    # generate per country stats
    per_country = {}
    for listener in current_listener:
        country = listener.country
        try:
            per_country[country]['count'] += 1
        except KeyError:
            per_country[country] = {'count': 1}
            per_country[country]['ball'] = country
    per_country = sorted(per_country.iteritems(), key=lambda (k, v): v['count'], reverse=True)

    # get recent listener count to calculate a trend
    try:
        stats_total = Statistic.query.filter(Statistic.identifier == 'lst-total').one()
        stats = stats_total.get(start=now() - datetime.timedelta(minutes=2), stop=now())
    except exc.NoResultFound:
        stats = None

    if stats and stats.count() > 0:
        listener_sum = 0
        for stat in stats:
            listener_sum += stat.value
        average_listeners = listener_sum / stats.count()
    else:
        average_listeners = len(current_listener)

    return render_template('listenergraph.html', TITLE='Listeners', show_listener_list=show_listener_list,
                           listeners=current_listener, per_country=per_country, total_bandwidth=total_bandwidth,
                           active_relays=active_relays, average_listeners=average_listeners)
Exemple #9
0
def icecast_add_listener():
    #logger.info('add_listener {}'.format(request.form))
    if request.form['action'] != 'listener_add':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
    stream = Stream.get_stream(mount=request.form['mount'])
    listener = Listener.create(request.form['ip'], request.form['client'], request.form['agent'], relay.get_stream_relay(stream))
    session.add(listener)
    session.flush()
    relay.update_statistic()
    stream.update_statistic()
    relay.get_stream_relay(stream).update_statistic()
    session.commit()
    return make_response('ok', 200, {'icecast-auth-user': '******'})
Exemple #10
0
def icecast_remove_listener():
    #logger.info('remove_listener {}'.format(request.form))
    if request.form['action'] != 'listener_remove':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
    stream = Stream.get_stream(mount=request.form['mount'])
    listener = Listener.get_listener(relay.get_stream_relay(stream), int(request.form['client']))
    listener.set_disconnected()
    session.flush()
    relay.update_statistic()
    stream.update_statistic()
    relay.get_stream_relay(stream).update_statistic()
    session.commit()
    return make_response('ok', 200, {'icecast-auth-user': '******'})
Exemple #11
0
def icecast_remove_listener():
    #logger.info('remove_listener {}'.format(request.form))
    if request.form['action'] != 'listener_remove':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
    stream = Stream.get_stream(mount=request.form['mount'])
    listener = Listener.get_listener(relay.get_stream_relay(stream),
                                     int(request.form['client']))
    listener.set_disconnected()
    session.flush()
    relay.update_statistic()
    stream.update_statistic()
    relay.get_stream_relay(stream).update_statistic()
    session.commit()
    return make_response('ok', 200, {'icecast-auth-user': '******'})
Exemple #12
0
def icecast_add_listener():
    #logger.info('add_listener {}'.format(request.form))
    if request.form['action'] != 'listener_add':
        return make_response('you just went full retard', 405)
    relay = Relay.get_relay(address=request.form['server'],
                            port=request.form['port'])
    stream = Stream.get_stream(mount=request.form['mount'])
    listener = Listener.create(request.form['ip'], request.form['client'],
                               request.form['agent'],
                               relay.get_stream_relay(stream))
    session.add(listener)
    session.flush()
    relay.update_statistic()
    stream.update_statistic()
    relay.get_stream_relay(stream).update_statistic()
    session.commit()
    return make_response('ok', 200, {'icecast-auth-user': '******'})
Exemple #13
0
def disco():
    show = Show.get_active_show()
    ret = {}
    if show:
        user = show.get_active_user()
        ret['countryball'] = iso_country_to_countryball(user.country)
        ret['logo'] = show.get_logo(),
    else:
        ret['countryball'] = False
        ret['logo'] = False
    track = Track.current_track()
    if track:
        ret['track'] = {'title': track.title.name,
                        'artist': track.title.artist.name,
        }
            #get listenerinfo for disco
    listeners = Listener.get_current_listeners()
    ret['listener'] = {}
    for listener in listeners:
        ret['listener'][listener.listener] = {'listener': listener.listener,
                                              'county': listener.country,
                                              'countryball': iso_country_to_countryball(listener.country)}
    return ret
Exemple #14
0
def listeners():

    # check if current_user is logged in and if user is streaming or if user is admin
    if not current_user.is_anonymous():
        is_streaming = UserShow.query.join(User).filter(
            UserShow.status == UserShow.STATUS.STREAMING,
            UserShow.user == current_user).first()
        if is_streaming or current_user.has_permission('admin'):
            show_listener_list = True
        else:
            show_listener_list = False
    else:
        show_listener_list = False

    # get current bandwidth of all active relays
    total_bandwidth = 0
    relays = Relay.query.filter(Relay.status == Relay.STATUS.ONLINE).all()
    active_relays = len(relays)
    for relay in relays:
        total_bandwidth += relay.usage
    total_bandwidth *= 128  # convert kbit to byte

    # get all current listeners
    current_listener = Listener.get_current_listeners()

    # generate per country stats
    per_country = {}
    for listener in current_listener:
        country = listener.country
        try:
            per_country[country]['count'] += 1
        except KeyError:
            per_country[country] = {'count': 1}
            per_country[country]['ball'] = country
    per_country = sorted(per_country.iteritems(),
                         key=lambda (k, v): v['count'],
                         reverse=True)

    # get recent listener count to calculate a trend
    try:
        stats_total = Statistic.query.filter(
            Statistic.identifier == 'lst-total').one()
        stats = stats_total.get(start=now() - datetime.timedelta(minutes=5),
                                stop=now())
    except exc.NoResultFound:
        stats = None

    if stats and stats.count() > 0:
        listener_sum = 0
        for stat in stats:
            listener_sum += stat.value
        average_listeners = listener_sum / stats.count()
    else:
        average_listeners = len(current_listener)

    return render_template('listenergraph.html',
                           TITLE=gettext('Listeners'),
                           show_listener_list=show_listener_list,
                           listeners=current_listener,
                           per_country=per_country,
                           total_bandwidth=total_bandwidth,
                           active_relays=active_relays,
                           average_listeners=average_listeners)
Exemple #15
0
def doListenerCount():
    lc = Listener.get_total_listener()
    sys.stdout.write("<icestats><source mount=\"/live.ogg\"><listeners>%d</listeners><Listeners>%d</Listeners></source></icestats>" % (lc, lc,))
Exemple #16
0
def listener_list():
    listener = Listener.get_current_listeners()
    return render_template('admin/listener_list.html', listeners=listener)