def scan_db(self): self.the_db_1 = db.DB_MYSQL() ret = self.the_db_1.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 one_sql = "SELECT CP_ALBUM_ID, CP_TV_ID from CONT_INJECT_TASK " \ "WHERE TASK_STATUS= 2 ORDER BY TASK_PRIORITY DESC LIMIT 20" logging.info("before_exec, sql=[%s]" % (one_sql)) result = self.the_db_1.execute(one_sql) logging.info("result=[%d], sql=[%s]" % (result, one_sql)) if (result < 0): return -1 for one_row in self.the_db_1.cur.fetchall(): album_id = one_row[0] video_id = one_row[1] bits_str = "xxx" one_video = VIDEO_CLEAN(album_id, video_id, bits_str) logging.info( "one_video=[%d:%d:%s]" % (one_video.album_id, one_video.video_id, one_video.bits_str)) self.video_list.append(one_video) return result
def scan_db_old(self): self.the_db_1 = db.DB_MYSQL() ret = self.the_db_1.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 one_sql = "SELECT id, vrs_tv_id from fiona.injection_task " \ "WHERE status=2 and video_url not like '%%.75:2151%%' ORDER BY priority DESC LIMIT 20" logging.info("before_exec, sql=[%s]" % (one_sql)) result = self.the_db_1.execute(one_sql) logging.info("result=[%d], sql=[%s]" % (result, one_sql)) if (result < 0): return -1 for one_row in self.the_db_1.cur.fetchall(): # album_id actually is id(task_id) album_id = one_row[0] video_id = one_row[1] bits_str = "xxx" one_video = VIDEO_CLEAN(album_id, video_id, bits_str) logging.info( "one_video=[%d:%d:%s]" % (one_video.album_id, one_video.video_id, one_video.bits_str)) self.video_list.append(one_video) return result
def trigger_inject_old(self): task_id = self.task_id album_id = self.album_id video_id = self.video_id self.the_db_2 = db.DB_MYSQL() ret = self.the_db_2.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 #video_url = "ftp://%s:%s@%s:%d/%d/%d/index.m3u8" % (config.FTP_CONFIG.user, config.FTP_CONFIG.password, config.FTP_CONFIG.host, config.FTP_CONFIG.port, album_id, video_id) video_url = "ftp://%s:%s@%s:%d/%d/index.m3u8" % ( config.FTP_CONFIG.user, config.FTP_CONFIG.password, config.FTP_CONFIG.host, config.FTP_CONFIG.port, video_id) self.db_status = DB_STATUS.DOWNLOAD_SUCCESS # album_id actually is id(task_id) one_sql = "update fiona.injection_task set video_url='%s', status=%d where id=%d" % ( video_url, self.db_status, task_id) logging.info("important! sql=[%s]" % (one_sql)) #result=1 result = self.the_db_2.execute(one_sql) if (result < 0): return -1 self.the_db_2.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result
def query_bits(self): video_id = self.video_id self.the_db_1 = db.DB_MYSQL() ret = self.the_db_1.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return False one_sql = "SELECT CP_TV_ID, CP_VER_ID from CONT_TV_M3U8 where CP_TV_ID=%s and CP_VER_ID != 1 and CP_VER_ID != 96 order by CP_VER_ID DESC" % ( video_id) result = self.the_db_1.execute(one_sql) logging.info("result=[%d], sql=[%s]" % (result, one_sql)) if (result < 0): return False bits_list = [] for one_row in self.the_db_1.cur.fetchall(): str_bits_id = "%d" % (one_row[1]) bits_list.append(str_bits_id) if (len(bits_list) == 0): self.set_status(DB_STATUS.BITS_NOT_AVAILIABLE) return False bits_str = ",".join(bits_list) self.bits_str = bits_str self.GetBits() if (self.valid_bits_num == 0): self.set_status(DB_STATUS.GLOBAL_NO_VIDEO) return False return True
def query_global(self): self.the_db_1 = db.DB_MYSQL() ret = self.the_db_1.connect(config.GLOBAL_DB_CONFIG.host, config.GLOBAL_DB_CONFIG.port, config.GLOBAL_DB_CONFIG.user, config.GLOBAL_DB_CONFIG.password, config.GLOBAL_DB_CONFIG.db) if (ret == False): return -1 one_sql = "select album_id, video_id, bits_id, file_size from video where album_id=%d and video_id=%d and bits_id=%d" % ( self.album_id, self.video_id, self.bits_id) result = self.the_db_1.execute(one_sql) logging.info("result=[%d], sql=[%s]" % (result, one_sql)) if (result < 0): return -1 for one_row in self.the_db_1.cur.fetchall(): album_id = one_row[0] video_id = one_row[1] bits_id = one_row[2] file_size = one_row[3] if (file_size == None): logging.info("result=[%d], columns=[%d:%d:%d:None]" % (result, album_id, video_id, bits_id)) else: logging.info("result=[%d], columns=[%d:%d:%d:%d]" % (result, album_id, video_id, bits_id, file_size)) if (file_size > 0): self.exist_at_global = True return result
def tag_clean(self, album_id, video_id): self.the_db_2 = db.DB_MYSQL() ret = self.the_db_2.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 one_sql = "UPDATE CONT_INJECT_TASK set TASK_STATUS=12 where CP_TV_ID=%d" % ( video_id) logging.info("important! sql=[%s]" % (one_sql)) #result=1 result = self.the_db_2.execute(one_sql) if (result < 0): return -1 self.the_db_2.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result
def scan_db_old(self): self.the_db_1 = db.DB_MYSQL() ret = self.the_db_1.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 video_num = 2 * config.PROCESS_NUM - self.video_queue.qsize() one_sql = 'select t3.id, t2.CP_ALBUM_ID, t1.CP_TV_ID, t1.VIDEO_VERSION '\ 'from tum.TUM_VIDEO t1, tum.TUM_ALBUM t2, fiona.injection_task t3 '\ "where t3.status in(%d) and t1.album_id=t2.id and t1.CP_TV_ID=t3.vrs_tv_id and t3.video_url not like '%%.75:2151%%' "\ "order by priority DESC,create_time DESC LIMIT %d" % (DB_STATUS.PREPARE_INJECT, video_num) logging.info("before_exec, sql=[%s]" % (one_sql)) result = self.the_db_1.execute(one_sql) logging.info("result=[%d], sql=[%s]" % (result, one_sql)) if (result < 0): return -1 task_id_list = [] for one_row in self.the_db_1.cur.fetchall(): task_id = one_row[0] album_id = one_row[1] video_id = one_row[2] bits_str = one_row[3] one_video = VIDEO_TASK(album_id, video_id, bits_str) one_video.task_id = task_id logging.info("one_video=[%d:%d:%d:%s]" % (one_video.task_id, one_video.album_id, one_video.video_id, one_video.bits_str)) self.video_queue.put(one_video) task_id_list.append(task_id) for task_id in task_id_list: one_sql = "update fiona.injection_task set status=%d where id=%d" % ( DB_STATUS.START_DOWNLOAD, task_id) logging.info("before_exec, sql=[%s]" % (one_sql)) #result = 1 result = self.the_db_1.execute(one_sql) if (result < 0): break self.the_db_1.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result
def scan_db_first(self): self.the_db_1 = db.DB_MYSQL() ret = self.the_db_1.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 video_num = 2 * config.PROCESS_NUM - self.video_queue.qsize() one_sql = "SELECT cit.CP_ALBUM_ID, cit.CP_TV_ID from CONT_INJECT_TASK cit,CONT_ALBUM am " \ "WHERE cit.CP_ALBUM_ID=am.CP_ALBUM_ID AND cit.CP_ID=am.CP_ID " \ 'AND am.UPDATE_TIME > "2014-07-28 00:00:00" AND cit.UPDATE_TIME > "2015-01-01 00:00:00" ' \ 'AND cit.TASK_STATUS in(%d,%d) AND am.IS_ONLINE in(1,2) AND am.IS_EFFECTIVE=1 ORDER BY cit.TASK_PRIORITY DESC LIMIT %d' % \ (DB_STATUS.PREPARE_INJECT, DB_STATUS.START_DOWNLOAD, video_num) logging.info("before_exec, sql=[%s]" % (one_sql)) result = self.the_db_1.execute(one_sql) logging.info("result=[%d], sql=[%s]" % (result, one_sql)) if (result < 0): return -1 video_id_list = [] for one_row in self.the_db_1.cur.fetchall(): album_id = one_row[0] video_id = one_row[1] bits_str = "" one_video = VIDEO_TASK(album_id, video_id, bits_str) logging.info( "one_video=[%d:%d:%s]" % (one_video.album_id, one_video.video_id, one_video.bits_str)) self.video_queue.put(one_video) video_id_list.append(video_id) for video_id in video_id_list: one_sql = "update CONT_INJECT_TASK set task_status=%d where cp_tv_id=%d" % ( DB_STATUS.START_DOWNLOAD, video_id) logging.info("before_exec, sql=[%s]" % (one_sql)) result = 1 result = self.the_db_1.execute(one_sql) if (result < 0): return -1 self.the_db_1.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result
def tag_clean_old(self, album_id, video_id): self.the_db_2 = db.DB_MYSQL() ret = self.the_db_2.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 # album_id actually is id(task_id) one_sql = "UPDATE fiona.injection_task set status=12 where vrs_tv_id=%d and id=%d" % ( video_id, album_id) logging.info("important! sql=[%s]" % (one_sql)) result = 1 #result = self.the_db_2.execute(one_sql) if (result < 0): return -1 #self.the_db_2.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result
def set_status_old(self, the_status): self.db_status = the_status self.the_db_2 = db.DB_MYSQL() ret = self.the_db_2.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 one_sql = "UPDATE fiona.injection_task set status=%d where id=%d" % ( the_status, self.task_id) logging.info("important! sql=[%s]" % (one_sql)) #result=1 result = self.the_db_2.execute(one_sql) if (result < 0): return -1 self.the_db_2.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result
def trigger_inject(self): album_id = self.album_id video_id = self.video_id self.the_db_2 = db.DB_MYSQL() ret = self.the_db_2.connect(config.DB_CONFIG.host, config.DB_CONFIG.port, config.DB_CONFIG.user, config.DB_CONFIG.password, config.DB_CONFIG.db) if (ret == False): return -1 #video_url = "ftp://%s:%s@%s:%d/%d/%d/index.m3u8" % (config.FTP_CONFIG.user, config.FTP_CONFIG.password, config.FTP_CONFIG.host, config.FTP_CONFIG.port, album_id, video_id) video_url = "ftp://%s:%s@%s:%d/%d/index.m3u8" % ( config.FTP_CONFIG.user, config.FTP_CONFIG.password, config.FTP_CONFIG.host, config.FTP_CONFIG.port, video_id) one_sql = "UPDATE CONT_TV set TV_STATUS=0 where CP_TV_ID=%d" % ( video_id) logging.info("important! sql=[%s]" % (one_sql)) #result=1 result = self.the_db_2.execute(one_sql) if (result < 0): return -1 self.the_db_2.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) self.db_status = DB_STATUS.DOWNLOAD_SUCCESS one_sql = "UPDATE CONT_INJECT_TASK set VIDEO_URL='%s',TASK_STATUS=%d where CP_TV_ID=%d" % ( video_url, self.db_status, video_id) logging.info("important! sql=[%s]" % (one_sql)) #result=1 result = self.the_db_2.execute(one_sql) if (result < 0): return -1 self.the_db_2.conn.commit() logging.info("result=[%d], sql=[%s]" % (result, one_sql)) return result