def room(room_id): try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) try: room = Room(room_id) except NonexistentError: abort(404) return render_template('room.html', room=room, in_room=me.in_room(room), is_owner=(me == room.owner()))
def p_skipto(request): if "access_key" in request.POST and request.POST["access_key"] == LIVE_ACCESS_KEY: if "room_id" in request.POST: try: room = Room.get_by_id(request.POST['room_id']) except: return apiRespond(400, msg='room_id invalid') else: curr_time = timezone.now() if not room.is_paused: dur = room.duration_to_complete if curr_time >= (room.play_start_time+datetime.timedelta(seconds=dur.second, minutes=dur.minute)-datetime.timedelta(seconds=5, minutes=0)): print('valid time to skipto') room.skip_to_next() return apiRespond(201, msg='skipped to next') else: print('NOT valid time to skipto', curr_time-(room.play_start_time + datetime.timedelta(seconds=dur.second, minutes=dur.minute))) return apiRespond(400, msg='NOT valid time to skipto') else: print('skipto canceled, playback is paused') return apiRespond(400, msg='playback is paused') else: return apiRespond(400, msg='room_id missing') else: return apiRespond(400, msg='access_key invalid')
def main(request): if request.user.is_authenticated: room = None if 'room_id' in request.POST: try: room = Room.get_by_id(request.POST['room_id']) except: return apiRespond(400, msg='invalid room_id') if room == None: room = request.user.room if room != None: members = room.get_members() friends = [] others = [] for member in members: friend_status, friend_obj = member.friendship_status( request.user) if friend_status == 3: friends.append(member.get_profile_min()) else: others.append(member.get_profile_min()) return apiRespond(200, friends=friends, others=others) else: return apiRespond(400, msg='Not a member of any room and no room_id provided') else: # user is already logged in, redirect to root return apiRespond(401, msg='User not logged in')
def create(): name = request.args.get('name') findable = request.args.get('findable') if name is None: abort(400) # Bad Request if findable is None: findable = True else: if findable in ["true", "True"]: findable = True elif findable in ["false", "False", ""]: findable = False else: abort(400) # Bad Request try: user = User() except APIError: abort(500) # Internal Server Error except UnauthorizedError: return redirect(url_for('login', next=request.url)) room = Room(name=name, findable=findable, owner=user) return redirect(url_for('profile'))
def main(request, code): try: room = Room.get_by_code(code) except: return HttpResponse("Invalid code") else: room.grant_access(request.user) return redirect(to="/roomPreview/" + str(room.id))
def delete(room_id): try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) try: room = Room(room_id) except NonexistentError: abort(404) if me == room.owner(): room.delete() return redirect(url_for('profile'))
def playback(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) if (me != room.owner()): abort(401) else: return render_template('playback.html', room=room)
def profile(): try: user = User() except APIError: abort(500) # Internal Server Error except UnauthorizedError: return redirect(url_for('login', next=request.url)) return render_template( 'profile.html', user=user, public=Room.public_rooms() )
def listen(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) return render_template('listen.html', domain=domain, room=room)
def dislike(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) me.dislike(room); return "ok"
def leave(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) if me.in_room(room): me.leave_room(room) return redirect(url_for('room', room_id=room_id))
def play(room_id): try: room = Room(room_id) except NonexistentError: abort(404) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) pl = room.playlist() pl.get_next_songs(results='0', lookahead='1') cur_song = pl.get_lookahead_songs()[0] cur_track = cur_song.get_tracks('rdio-US')[0] cur_rdio_id = cur_track['foreign_id'].split(':')[-1] current = { 'song_id': cur_song.id, 'rdio_id': cur_rdio_id, 'artist': cur_song.artist_name, 'title': cur_song.title } if room.cur_song()['song_id'] is not None and room.num_members() > 0: pl.feedback(rate_song='last^'+str(room.get_cur_rating())) pl.feedback(play_song=current['song_id']) room.set_song(current) redis.publish('push', json.dumps({'room': room_id, 'name': 'playing', 'data': current})) pl.get_next_songs(results='0', lookahead='1') next_song = pl.get_lookahead_songs()[0] next_track = next_song.get_tracks('rdio-US')[0] next_rdio_id = next_track['foreign_id'].split(':')[-1] return json.dumps({ 'song_id': next_song.id, 'rdio_id': next_rdio_id, 'artist': next_song.artist_name, 'title': next_song.title })
def main(request): if request.user.is_authenticated: if "room_id" in request.POST: try: room = Room.get_by_id(request.POST['room_id']) except: return apiRespond(400, msg='invalid room_id') else: try: room = request.user.join_room(room) except: return apiRespond(400, msg='Access denied') else: return apiRespond(201, **room.get_state_obj()) else: return apiRespond(400, msg='room_id missing') else: # user is already logged in, redirect to root return apiRespond(401, msg='User not logged in')
def start(room_id): try: room = Room(room_id) except NonexistentError: abort(404) if (room.num_members() == 0): # Do something better like returning some json abort(400) try: me = User() except APIError: abort(500) except UnauthorizedError: return redirect(url_for('login', next=request.url)) liked_artists = room.artist_counts() updater = [] for artist in liked_artists: count = liked_artists[artist] item = {'item': {'item_id': artist, 'artist_id': 'facebook:artist:' + artist, 'play_count': count}} updater.append(item) cat = room.seed_catalog() ticket = cat.update(updater) while True: status = cat.status(ticket) if status['ticket_status'] == 'complete': break time.sleep(0.1) pl = room.playlist(generate=True) pl.get_next_songs(results='0', lookahead='1') song = pl.get_lookahead_songs()[0] track = song.get_tracks('rdio-US')[0] rdio_id = track['foreign_id'].split(':')[-1] return json.dumps({'song_id': song.id, 'rdio_id': rdio_id, 'artist': song.artist_name, 'title': song.title})