def resume_pending(): db = JobsDB(readonly=False) jobs = db.get_all() not_endeds = [job for job in jobs if job['status'] == "Pending" or job['status'] == 'Running'] for pending in not_endeds: if int(pending["type"]) == JobType.YDL_UPDATE: jobshandler.put((Actions.SET_STATUS, (pending["id"], Job.FAILED))) else: job = Job(pending["name"], Job.PENDING, "Queue stopped", int(pending["type"]), pending["format"], pending["url"]) job.id = pending["id"] jobshandler.put((Actions.RESUME, job))
def resume_pending(): db = JobsDB(readonly=False) jobs = db.get_all() not_endeds = [ job for job in jobs if job['status'] == "Pending" or job['status'] == 'Running' ] for pending in not_endeds: job = Job(pending["name"], Job.PENDING, "Queue stopped", pending["format"]) job.id = pending["id"] jobshandler.put((Actions.RESUME, job))
def api_queue_size(): db = JobsDB(readonly=True) jobs = db.get_all() return { "success": True, "stats": { "queue": ydlhandler.queue.qsize(), "pending": len([job for job in jobs if job['status'] == "Pending"]), "running": len([job for job in jobs if job['status'] == "Running"]), "completed": len([job for job in jobs if job['status'] == "Completed"]), "failed": len([job for job in jobs if job['status'] == "Failed"]) } }
def worker(dl_queue): db = JobsDB(readonly=False) while not done: action, job = queue.get() if action == Actions.PURGE_LOGS: db.purge_jobs() elif action == Actions.INSERT: db.insert_job(job) dl_queue.put(job) elif action == Actions.UPDATE: db.update_job(job) elif action == Actions.RESUME: db.update_job(job) dl_queue.put(job) queue.task_done()
async def api_queue_size(request): db = JobsDB(readonly=True) jobs = db.get_all(app_config["ydl_server"].get("max_log_entries", 100)) return JSONResponse({ "success": True, "stats": { "queue": request.app.state.ydlhandler.queue.qsize(), "pending": len([job for job in jobs if job["status"] == "Pending"]), "running": len([job for job in jobs if job["status"] == "Running"]), "completed": len([job for job in jobs if job["status"] == "Completed"]), "failed": len([job for job in jobs if job["status"] == "Failed"]), }, })
def resume_pending(self): db = JobsDB(readonly=False) jobs = db.get_all(self.app_config["ydl_server"].get( "max_log_entries", 100)) not_endeds = [ job for job in jobs if job["status"] == "Pending" or job["status"] == "Running" ] for pending in not_endeds: if int(pending["type"]) == JobType.YDL_UPDATE: self.jobshandler.put( (Actions.SET_STATUS, (pending["id"], Job.FAILED))) else: job = Job( pending["name"], Job.PENDING, "Queue stopped", int(pending["type"]), pending["format"], pending["url"], ) job.id = pending["id"] self.jobshandler.put((Actions.RESUME, job))
async def api_logs(request): db = JobsDB(readonly=True) return JSONResponse(db.get_all())
def worker(dl_queue): db = JobsDB(readonly=False) while not done: action, job = queue.get() if action == Actions.PURGE_LOGS: db.purge_jobs() elif action == Actions.INSERT: db.insert_job(job) dl_queue.put(job) elif action == Actions.UPDATE: db.update_job(job) elif action == Actions.RESUME: db.update_job(job) dl_queue.put(job) elif action == Actions.SET_NAME: job_id, name = job db.set_job_name(job_id, name) elif action == Actions.SET_LOG: job_id, log = job db.set_job_log(job_id, log) elif action == Actions.SET_STATUS: job_id, status = job db.set_job_status(job_id, status) queue.task_done()
def worker(self, dl_queue): db = JobsDB(readonly=False) while not self.done: action, job = self.queue.get() if action == Actions.PURGE_LOGS: db.purge_jobs() elif action == Actions.INSERT: db.clean_old_jobs(self.app_config['ydl_server'] .get('max_log_entries', 100)) db.insert_job(job) dl_queue.put(job) elif action == Actions.UPDATE: db.update_job(job) elif action == Actions.RESUME: db.update_job(job) dl_queue.put(job) elif action == Actions.SET_NAME: job_id, name = job db.set_job_name(job_id, name) elif action == Actions.SET_LOG: job_id, log = job db.set_job_log(job_id, log) elif action == Actions.SET_STATUS: job_id, status = job db.set_job_status(job_id, status) elif action == Actions.CLEAN_LOGS: db.clean_old_jobs() self.queue.task_done()
def api_logs(): db = JobsDB(readonly=True) return json.dumps(db.get_all())
print("Added url " + url + " to the download queue") return {"success": True, "url": url, "options": options} @app.route('/api/metadata', method='POST') def api_metadata_fetch(): url = request.forms.get("url") return ydlhandler.fetch_metadata(url) @app.route("/api/youtube-dl/update", method="GET") def ydl_update(): job = Job("Youtube-dl Update", Job.PENDING, "", JobType.YDL_UPDATE, None, None) jobshandler.put((Actions.INSERT, job)) return {"success": True} JobsDB.check_db_latest() JobsDB.init_db() ydlhandler.start() print("Started download thread") jobshandler.start(ydlhandler.queue) print("Started jobs manager thread") print("Updating youtube-dl to the newest version") job = Job("Youtube-dl Update", Job.PENDING, "", JobType.YDL_UPDATE, None, None) jobshandler.put((Actions.INSERT, job)) ydlhandler.resume_pending() app.run(host=app_config['ydl_server'].get('host'),
async def api_logs(request): db = JobsDB(readonly=True) return JSONResponse( db.get_all(app_config["ydl_server"].get("max_log_entries", 100)))
print("Added url " + url + " to the download queue") return {"success": True, "url": url, "options": options} @app.route('/api/youtube-dl/version') def ydl_version(): return {'version': youtube_dl.version.__version__} @app.route("/youtube-dl/update", method="GET") def ydl_update(): return ydlhandler.update() JobsDB.init_db() ydlhandler.start() print("Started download thread") jobshandler.start(ydlhandler.queue) print("Started jobs manager thread") ydlhandler.resume_pending() print("Updating youtube-dl to the newest version") updateResult = ydlhandler.update() print(updateResult["output"]) print(updateResult["error"]) app_vars = ChainMap(os.environ, app_defaults)