def get(self): def getVideoDuration(video_id): if video_id.startswith("yt;"): video_id = video_id.replace("yt;", "", 1) API_URL = "http://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=jsonc&prettyprint=true" % video_id video_json = urllib.urlopen(API_URL) json_data = json.load(video_json) return int(json_data["data"]["duration"]) session_id = self.request.get('id') video_id = self.request.get('video') db = Database(connect=1) if db.sessionExists(session_id) and db.isStringSafe(video_id): old_queue = db.deserialize(db.getData("queue", session_id)) duration = getVideoDuration(video_id) timestamp = int(time()) play_time = timestamp + db.PLAY_OFFSET if old_queue: last_item = old_queue[-1].split(":") last_song_duration = last_item[2] last_song_playtime = last_item[3] play_time = int(last_song_playtime) + int(last_song_duration) if play_time < timestamp: play_time = timestamp + db.PLAY_OFFSET old_queue.append("%s:yt;%s:%s:%s" % (timestamp, video_id, duration, play_time)) db.setData("queue", db.serialize(old_queue), session_id)
def get(self): session_id = self.request.get("id") search_creator = self.request.get("creator") search_users = self.request.get("users") search_recent = self.request.get("recent") db = Database(connect=1) #structure of session data: "id;creator;users;create_time" if search_creator and db.isStringSafe(search_creator): cursor = db.cursor() cursor.execute('SELECT id, users FROM data WHERE creator = "%s"' % search_creator) for row in cursor.fetchall(): self.response.out.write("{0};{1};{2};255".format(row[0], search_creator, '1')) elif search_users: self.response.out.write("not implemented") elif search_recent: self.response.out.write("not implemented") else: self.response.out.write("not implemented")