Example #1
0
def doMetaData(data):
    logger.debug('meta %s' % (json.dumps(data),))
    if 'userid' not in data or data['userid'] == 'none':
        print 'no userid'
        return
    user = User.get_user(id=data['userid'])
    if user == None:
        print 'user not found'
        return

    if 'artist' in data:
        artist = data['artist'].strip()
    else:
        artist = None

    if 'title' in data:
        title = data['title'].strip()
    else:
        title = None

    if 'song' in data:
        song = data['song'].split(' - ', 1)
        if (artist is None) or (len(artist) == 0):
            artist = song[0]
        if (title is None) or (len(title) == 0):
            title = song[1]
    show = init_show(user)
    if artist is None and title is None:
        track = Track.current_track()
        if track:
            track.end_track()
    else:
        track = Track.new_track(show, artist, title)
    rfk.database.session.commit()
Example #2
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
Example #3
0
def liquidsoap_disconnect():
    """Handles a client disconnect from liquidsoap

    """

    userid = request.get_json()

    logger.info('liquidsoap_disconnect: diconnect for userid %s' % (userid,))
    if userid == 'none' or userid == '':
        logger.warn('liquidsoap_disconnect: no userid supplied!')
        session.commit()
        return 'Whooops no userid?'
    user = User.get_user(id=int(userid))
    if user:
        usershows = UserShow.query.filter(UserShow.user == user,
                                          UserShow.status == UserShow.STATUS.STREAMING).all()
        for usershow in usershows:
            usershow.status = UserShow.STATUS.STREAMED
            if usershow.show.flags & Show.FLAGS.UNPLANNED:
                usershow.show.end_show()
        session.commit()
        track = Track.current_track()
        if track:
            track.end_track()
        session.commit()
        return 'true'
    else:
        return 'no user found'
Example #4
0
def doDisconnect(userid):
    logger.info('doDisconnect: diconnect for userid %s' % (userid, ))
    if userid == "none" or userid == '':
        print "Whooops no userid?"
        logger.warn('doDisconnect: no userid supplied!')
        rfk.database.session.commit()
        return
    user = User.get_user(id=int(userid))
    if user:
        usershows = UserShow.query.filter(
            UserShow.user == user,
            UserShow.status == UserShow.STATUS.STREAMING).all()
        for usershow in usershows:
            usershow.status = UserShow.STATUS.STREAMED
            if usershow.show.flags & Show.FLAGS.UNPLANNED:
                usershow.show.end_show()
        rfk.database.session.commit()
        track = Track.current_track()
        if track:
            track.end_track()
            publish.track_change()
        publish.show_change()
        rfk.database.session.commit()
    else:
        print "no user found"
Example #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)})
Example #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)})
Example #7
0
def liquidsoap_meta_data():
    """Handles track changes

    Returns error message if something suspicious happens
    Returns 'true' when everything worked like expected
    """

    data = request.get_json()
    logger.debug('liquidsoap_meta_data: %s' % (json.dumps(data),))
    if 'userid' not in data or data['userid'] == 'none':
        session.commit()
        return 'no userid'
    user = User.get_user(id=data['userid'])
    if user is None:
        session.commit()
        return 'user not found'

    if 'artist' in data:
        artist = data['artist'].strip()
    else:
        artist = None

    if 'title' in data:
        title = data['title'].strip()
    else:
        title = None

    if 'song' in data:
        song = data['song'].split(' - ', 1)
        if (artist is None) or (len(artist) == 0):
            artist = song[0]
        if (title is None) or (len(title) == 0):
            title = song[1]

    show = init_show(user)
    if artist is None and title is None:
        track = Track.current_track()
        if track:
            track.end_track()
    else:
        track = Track.new_track(show, artist, title)

    session.commit()
    return 'true'
Example #8
0
 def test_do_metadata(self):
     self.test_do_connect_valid_user()
     data = {
         "album": "Pedestrian Verse",
         "userid": "1",
         "title": "Late March, Death March",
         "vendor": "Xiph.Org libVorbis I 20101101 (Schaufenugget)",
         "artist": "Frightened Rabbit"
     }
     rfk.liquidsoaphandler.doMetaData(data)
     self.assertNotEqual(Track.current_track(), None)
Example #9
0
def nowPlaying():
    track = Track.current_track()
    if track:
        title = "%s - %s" % (track.title.artist.name,track.title.name)
        users = []
        for usershow in track.show.users:
            users.append(usershow)
        return {
                'title': title,
                'users': users,
                'showname': track.show.name,
                'showdescription':track.show.description
                }
    else:
        return None
Example #10
0
def current_track():
    """Return the currently playing track
    
    Keyword arguments:
        None
    """

    result = Track.current_track()
    if result:
        data = {'current_track' : {
            'track_id': result.track,
            'track_begin': result.begin.isoformat(),
            'track_title': result.title.name,
            'track_artist': result.title.artist.name
        }}  
    else:
        data = {'current_track': None}
    return jsonify(wrapper(data))
Example #11
0
def current_track():
    """Return the currently playing track

    Keyword arguments:
        - None
    """

    result = Track.current_track()
    if result:
        data = {'current_track': {
            'track_id': result.track,
            'track_begin': result.begin.isoformat(),
            'track_title': result.title.name,
            'track_artist': result.title.artist.name
        }}
    else:
        data = {'current_track': None}
    return jsonify(wrapper(data))
Example #12
0
def current_track():
    """Return the currently playing track

    Keyword arguments:
        - None
    """

    result = Track.current_track()
    if result:
        data = {
            "current_track": {
                "track_id": result.track,
                "track_begin": result.begin.isoformat(),
                "track_title": result.title.name,
                "track_artist": result.title.artist.name,
            }
        }
    else:
        data = {"current_track": None}
    return jsonify(wrapper(data))
Example #13
0
def doMetaData(data):
    logger.debug('meta %s' % (json.dumps(data),))
    if 'userid' not in data or data['userid'] == 'none':
        print 'no userid'
        return
    user = User.get_user(id=data['userid'])
    if user == None:
        print 'user not found'
        return
    artist = data['artist'] or ''
    title = data['title'] or ''
    if 'song' in data:
        song = data['song'].split(' - ', 1)
        if ('artist' not in data) or (len(data['artist'].strip()) == 0):
            artist = song[0]
        if ('title' not in data) or (len(data['title'].strip()) == 0):
            title = song[1]
    show = init_show(user)
    track = Track.new_track(show, artist, title)
    rfk.database.session.commit()
Example #14
0
def doDisconnect(userid):
    logger.info('doDisconnect: diconnect for userid %s' % (userid,))
    if userid == "none" or userid == '':
        print "Whooops no userid?"
        logger.warn('doDisconnect: no userid supplied!')
        rfk.database.session.commit()
        return
    user = User.get_user(id=int(userid))
    if user:
        usershows = UserShow.query.filter(UserShow.user == user,
                                          UserShow.status == UserShow.STATUS.STREAMING).all()
        for usershow in usershows:
            usershow.status = UserShow.STATUS.STREAMED
            if usershow.show.flags & Show.FLAGS.UNPLANNED:
                usershow.show.end_show()
        rfk.database.session.commit()
        track = Track.current_track()
        if track:
            track.end_track()
        rfk.database.session.commit()
    else:
        print "no user found"
Example #15
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
 def test_do_metadata(self):
     self.test_do_connect_valid_user()
     data = {"album": "Pedestrian Verse", "userid": "1", "title": "Late March, Death March", "vendor": "Xiph.Org libVorbis I 20101101 (Schaufenugget)", "artist": "Frightened Rabbit"}
     rfk.liquidsoaphandler.doMetaData(data)
     self.assertNotEqual(Track.current_track(),None)
Example #17
0
 def test_disconnect(self):
     liquidsoaphandler.doDisconnect(1)
     self.assertEqual(Show.get_active_show(), None)
     self.assertEqual(Track.current_track(), None)
Example #18
0
def api_legacy():
    '''lazy people...'''

    apikey = request.args.get("apikey")
    if apikey != '86c6c5162aa6845906cff55320ea8608991358c3':
        return ''

    #ltid=0&w=track%2Clistener%2Cdj%2Cshow%2Cnextshows,
    ret = {}
    listeners = Listener.query.filter(Listener.disconnect == None).all()
    tmp = {}
    for listener in listeners:
        if listener.stream_relay.stream.code in tmp:
            tmp[listener.stream_relay.stream.code]['c'] += 1
        else:
            tmp[listener.stream_relay.stream.code] = {
                'c': 1,
                'name': listener.stream_relay.stream.code,
                'description': listener.stream_relay.stream.name
            }
    ret['listener'] = tmp.values()

    currtrack = Track.current_track()
    ltid = request.args.get("apikey")
    if currtrack and ltid != currtrack.track:
        ret['trackid'] = currtrack.track
        ret['title'] = currtrack.title.name
        ret['artist'] = currtrack.title.artist.name

    show = Show.get_active_show()
    if show:
        user = show.get_active_user()
        ret['dj'] = user.username
        ret['djid'] = user.user
        ret['status'] = 'STREAMING'
        ret['showbegin'] = int(to_user_timezone(show.begin).strftime("%s"))
        if show.end:
            ret['showend'] = int(to_user_timezone(show.end).strftime("%s"))
        else:
            ret['showend'] = None
        ret['showtype'] = 'PLANNED'
        ret['showname'] = show.name
        ret['showdescription'] = show.description
        ret['showid'] = show.show
        ret['showthread'] = None
        ret['showdj'] = user.username
        ret['showdjid'] = user.user

    ret['shows'] = []
    if show and show.end:
        filter_begin = show.end
    else:
        filter_begin = now()
    nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(
        Show.begin.asc()).first()
    if nextshow:
        arr = {}
        arr['showbegin'] = int(to_user_timezone(nextshow.begin).strftime("%s"))
        if nextshow.end:
            arr['showend'] = int(to_user_timezone(nextshow.end).strftime("%s"))
        else:
            arr['showend'] = None
        arr['showtype'] = 'PLANNED'
        arr['showname'] = nextshow.name
        arr['showdescription'] = nextshow.description
        arr['showid'] = nextshow.show
        arr['showdj'] = nextshow.users[0].user.username
        arr['showdjid'] = nextshow.users[0].user.user
        arr['showthread'] = None
        ret['shows'].append(arr)

    return jsonify(ret)
Example #19
0
def api_legacy():
    '''lazy people...'''

    apikey = request.args.get("apikey")
    if apikey != '86c6c5162aa6845906cff55320ea8608991358c3':
        return ''

    #ltid=0&w=track%2Clistener%2Cdj%2Cshow%2Cnextshows,
    ret = {}
    listeners = Listener.query.filter(Listener.disconnect == None).all()
    tmp = {}
    for listener in listeners:
        if listener.stream_relay.stream.code in tmp:
            tmp[listener.stream_relay.stream.code]['c'] += 1
        else:
            tmp[listener.stream_relay.stream.code] = {'c': 1,
                                                      'name': listener.stream_relay.stream.code,
                                                      'description': listener.stream_relay.stream.name}
    ret['listener'] = tmp.values()

    currtrack = Track.current_track()
    ltid = request.args.get("apikey")
    if currtrack and ltid != currtrack.track:
        ret['trackid'] = currtrack.track
        ret['title'] = currtrack.title.name
        ret['artist'] = currtrack.title.artist.name

    show = Show.get_active_show()
    if show:
        user = show.get_active_user()
        ret['dj'] = user.username
        ret['djid'] = user.user
        ret['status'] = 'STREAMING'
        ret['showbegin'] = int(to_user_timezone(show.begin).strftime("%s"))
        if show.end:
            ret['showend'] = int(to_user_timezone(show.end).strftime("%s"))
        else:
            ret['showend'] = None
        ret['showtype'] = 'PLANNED';
        ret['showname'] = show.name
        ret['showdescription'] = show.description
        ret['showid'] = show.show
        ret['showthread'] = None;
        ret['showdj'] = user.username
        ret['showdjid'] = user.user

    ret['shows'] = []
    if show and show.end:
        filter_begin = show.end
    else:
        filter_begin = now()
    nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first()
    if nextshow:
        arr = {}
        arr['showbegin'] = int(to_user_timezone(nextshow.begin).strftime("%s"))
        if nextshow.end:
            arr['showend'] = int(to_user_timezone(nextshow.end).strftime("%s"))
        else:
            arr['showend'] = None
        arr['showtype'] = 'PLANNED';
        arr['showname'] = nextshow.name;
        arr['showdescription'] = nextshow.description;
        arr['showid'] = nextshow.show;
        arr['showdj'] = nextshow.users[0].user.username;
        arr['showdjid'] = nextshow.users[0].user.user;
        arr['showthread'] = None;
        ret['shows'].append(arr)

    return jsonify(ret)
 def test_disconnect(self):
     liquidsoaphandler.doDisconnect(1)
     self.assertEqual(Show.get_active_show(), None)
     self.assertEqual(Track.current_track(), None)