def test4(create_poll=False): ''' poll create and get one''' # initDb() if(create_poll): poll = Poll.create_next_poll("telugu") print poll.to_json() print Poll.get_current_poll("telugu").to_json()
def test_7(): #random , test id , mongo field initDb() poll = Poll.get_current_poll("telugu") print str(poll.poll_items[0].id) print json_util.dumps(poll.poll_items[0].id) print json_util.dumps(poll.poll_items[0].poll.id)
def insert_init_data(): Album.drop_collection() Song.drop_collection() data = json.loads(open("mapped_songs.json","r").read()) count = 0 for movie_name in data: movie = data[movie_name] a = Album() a.name = movie_name a.directors = movie.get("directors",None) a.music_directors = movie.get("music_directors",None) a.image_url = movie.get("img",None) a.actors = movie.get("actors",None) a.save() print "saved :: ", a.name for song_title_path in movie.get("song_entries",[]): if(not song_title_path): continue song_title , path = song_title_path s = Song() s.title = song_title # s.lyricists = song.get("lyricists",None) # s.singers = song.get("singers",None) s.path = path s.album = a s.track_n = count count +=1 s.save() print " ", "saved song : " , s.title , s.album poll = Poll.create_next_poll("telugu") print poll.to_json() print Poll.get_current_poll("telugu").to_json() set_max_track()
def insert_init_data(): Album.drop_collection() Song.drop_collection() data = json.loads(open("mapped_songs.json", "r").read()) count = 0 for movie_name in data: movie = data[movie_name] a = Album() a.name = movie_name a.directors = movie.get("directors", None) a.music_directors = movie.get("music_directors", None) a.image_url = movie.get("img", None) a.actors = movie.get("actors", None) a.save() print "saved :: ", a.name for song_title_path in movie.get("song_entries", []): if (not song_title_path): continue song_title, path = song_title_path s = Song() s.title = song_title # s.lyricists = song.get("lyricists",None) # s.singers = song.get("singers",None) s.path = path s.album = a s.track_n = count count += 1 s.save() print " ", "saved song : ", s.title, s.album poll = Poll.create_next_poll("telugu") print poll.to_json() print Poll.get_current_poll("telugu").to_json() set_max_track()
def get_init_data(stream_id, user=None): from requests import stream_events_handler song = Song.objects().order_by("-last_played")[0] poll = Poll.get_current_poll(stream_id) init_data = InitData() if(user): init_data.user = user poll_item = user.get_poll_item(poll) if(poll_item): init_data.user_poll_item_id = str(poll_item.id)#string init_data.poll = poll init_data.n_user = len( stream_events_handler.event_listeners[stream_id]) init_data.current_song = song return init_data
def get_init_data(stream_id, user=None): from requests import stream_events_handler song = Song.objects().order_by("-last_played")[0] poll = Poll.get_current_poll(stream_id) init_data = InitData() if (user): init_data.user = user poll_item = user.get_poll_item(poll) if (poll_item): init_data.user_poll_item_id = str(poll_item.id) #string init_data.poll = poll init_data.n_user = len(stream_events_handler.event_listeners[stream_id]) init_data.current_song = song return init_data
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