コード例 #1
0
def do_chat_event(socket,stream_id , post=None , user=None):
    message = post.get("chat_message",["-"])
    stream_events_handler.publish_event(stream_id, Event.CHAT_MESSAGE,  message[0], from_user = user.to_short_mongo())
    
    socket.send(OK_200)
    socket.send("ok")
    socket.close()
コード例 #2
0
def do_dedicate_event(socket, stream_id,  post=None , user = None):
    user_name2 = post.get("user_name",["somebody"])
    stream_events_handler.publish_event(stream_id, Event.DEDICATE,  user_name2[0], from_user = user.to_short_mongo())
    
    socket.send(OK_200)
    socket.send("ok")
    socket.close()
    
コード例 #3
0
def do_poll(socket, stream_id, poll_id, poll_item_id, user = None):
    old_poll_item_id, old_song_title, new_poll_id , new_song_title = user.do_poll(poll_id, poll_item_id)
    
    # do events
    if(old_poll_item_id!=poll_item_id):
        changes = [PollChangeEvent(poll_id = poll_item_id , count = 1, song_title= new_song_title)]
        if(old_poll_item_id!=None):
            changes.append(PollChangeEvent(poll_id = old_poll_item_id , count = -1 , song_title=old_song_title))
            
        p = PollChangeEvent.get_poll_changes_to_json(changes)
        stream_events_handler.publish_event(stream_id, Event.POLL_CHANGES,  p, from_user = user.to_short_mongo())

    socket.send(OK_200)
    socket.send("ok")
    socket.close()
    
コード例 #4
0
    def _run(self):
        print "loading audio stream :: ", self.stream_id
        while(True):
            song_url_path = None
            current_poll = Poll.get_current_poll(self.stream_id)
            if(current_poll):
                if(not IS_TEST_BUILD):
                    song = current_poll.get_highest_poll_song(self.stream_id)
                else:
                    song = Song.objects(track_n=158).get()
                    
                if(song):
                    song_url_path = song.path

                    
            retry_poll_creation = 3
            while(retry_poll_creation>0):
                poll = Poll.create_next_poll(self.stream_id , not IS_TEST_BUILD)
                if(poll!=None):
                    break
                retry_poll_creation-=1
                
            if(poll==None):
                continue
            
            if(not song_url_path):
                song_url_path = "http://storage.googleapis.com/telugubeats_files/music/Telugu/devisri%20prasad/arya/amalapuram.mp3"
                
            if(song_url_path.startswith("/Users/abhinav/Desktop/Telugu//")):                    
                song_url_path="http://storage.googleapis.com/telugubeats_files/music/Telugu/"+urllib.quote(song_url_path[31:])
                
            print "playing::", song_url_path
            self.fd = RemoteUrlFileObject(song_url_path)
            
            #spawn greenlet, keep reading into buffer
            #block calls to seek and read if buffer is not sufficient enough
            
            
            reset_data = InitData()
            
            reset_data.poll = poll
            reset_data.n_user = 1000+len( stream_events_handler.event_listeners[self.stream_id])
            reset_data.current_song  = song
            song.last_played = datetime.utcnow()
            if(not IS_TEST_BUILD):
                song.save()
            event_data = json_util.dumps(reset_data.to_son())
            
            stream_events_handler.publish_event(self.stream_id, Event.RESET_POLLS_AND_SONG, event_data, from_user = None)

            # if there is valid ID3 data, read it out of the file first,
            # so we can skip sending it to the client
            try:
                self.id3 = id3reader.Reader(self.fd)
                if isinstance(self.id3.header.size, int): # read out the id3 data
                    self.fd.seek(self.id3.header.size)
                
                while(True):
                    try:
                        cur_time = time.time()
                        if(cur_time- self.last_time_stamp > self.sleep_time):
                            self.last_time_stamp = cur_time
                            self.buffer.queue_chunk(self.fd.read(self.buffer.chunk_byte_size))
                            gevent.sleep(self.sleep_time- time.time()+self.last_time_stamp)
                    except EOFError:
                        self.fd.close()
                        break        
            except Exception as e:
                    print e