def index(): form = DownloadForm(request.form) task = getnpop("task") # are we processing a task already? if request.method == "POST" and form.validate_on_submit(): folder = str(uuid1()) # folder where to save the file # list of tasks to process tasks = [download.s(folder, form.video_url.data)] if form.convert.data in ("mp3", "mp4"): # schedule file convertion to mp3 or mp4 tasks.append(convert.s(form.convert.data)) # start the chain and save the id in session for later ajax polling task_chain = chain(*tasks).apply_async() session["task"] = {"folder": folder, "task_id": task_chain.id} # schedule file removal in 30 min, whatever the result is delete.s(folder).set(countdown=1800).apply_async() return redirect(url_for("index")) return render_template("index.html", form=form, task=task)
def download_file(): form = DownloadForm() if form.validate_on_submit(): filename = secure_filename(form.filename.data) file_path = os.path.join(app.config["UPLOAD_FOLDER"], 'files') if os.path.exists(os.path.join(file_path, filename)): return send_from_directory(file_path, filename, as_attachment=True) return gettext("file [{0}] is not exists!".format(filename)) return render_template('download.html', form=form)
def download(_id): _replay = Replay.query.filter(Replay.id == _id).first() if _replay is None: flash("Replay {} not found.".format(_id), "danger") return redirect(request.referrer or url_for("index")) if _replay.get_s3_file() is None: if _replay.state != 'ARCHIVED': flash("Replay {} not yet stored in Dotabank.".format(_id), "danger") else: flash( "Replay file for replay {} is missing. This issue has been reported to the site admins and will be investigated." .format(_id), "danger") return redirect(request.referrer or url_for("index")) form = DownloadForm() key = _replay.get_s3_file() expires_at = (datetime.utcnow() + timedelta( seconds=current_app.config["REPLAY_DOWNLOAD_TIMEOUT"])).ctime() name = key.name md5 = key.etag.replace("\"", "") filesize = key.size if form.validate_on_submit( ) or _replay.league_id in current_app.config['CAPTCHA_LEAGUE_EXCEPTIONS']: url = key.generate_url(current_app.config["REPLAY_DOWNLOAD_TIMEOUT"]) download_log_entry = ReplayDownload( _replay.id, current_user.get_id() if current_user else None) db.session.add(download_log_entry) db.session.commit() return render_template("replays/download_granted.html", title="Download replay {} - Dotabank".format( _replay.id), replay=_replay, expires_at=expires_at, name=name, md5=md5, filesize=filesize, url=url) return render_template("replays/download.html", title="Download replay {} - Dotabank".format( _replay.id), replay=_replay, name=name, md5=md5, filesize=filesize, form=form)
def downloads_new(): download = Download() form = DownloadForm(request.form, download) if form.validate_on_submit(): f = request.files['url'] if f: filename = secure_filename(f.filename) f.save(os.path.join(neobug.config['UPLOAD_FOLDER'], filename)) form.populate_obj(download) download.url = 'static/uploads/' + filename download.save() return redirect('/downloads') return render_template('downloads_new.html', form=form)
def download(_id): _replay = Replay.query.filter(Replay.id == _id).first() if _replay is None: flash("Replay {} not found.".format(_id), "danger") return redirect(request.referrer or url_for("index")) if _replay.get_s3_file() is None: if _replay.state != 'ARCHIVED': flash("Replay {} not yet stored in Dotabank.".format(_id), "danger") else: flash("Replay file for replay {} is missing. This issue has been reported to the site admins and will be investigated.".format(_id), "danger") return redirect(request.referrer or url_for("index")) form = DownloadForm() key = _replay.get_s3_file() expires_at = (datetime.utcnow() + timedelta(seconds=current_app.config["REPLAY_DOWNLOAD_TIMEOUT"])).ctime() name = key.name md5 = key.etag.replace("\"", "") filesize = key.size if form.validate_on_submit() or _replay.league_id in current_app.config['CAPTCHA_LEAGUE_EXCEPTIONS']: url = key.generate_url(current_app.config["REPLAY_DOWNLOAD_TIMEOUT"]) download_log_entry = ReplayDownload( _replay.id, current_user.get_id() if current_user else None ) db.session.add(download_log_entry) db.session.commit() return render_template("replays/download_granted.html", title="Download replay {} - Dotabank".format(_replay.id), replay=_replay, expires_at=expires_at, name=name, md5=md5, filesize=filesize, url=url) return render_template("replays/download.html", title="Download replay {} - Dotabank".format(_replay.id), replay=_replay, name=name, md5=md5, filesize=filesize, form=form)
def download(): form = DownloadForm(request.form) if form.validate_on_submit(): config = { 'format': '%s+bestaudio/best' % form.download_format.data, 'outtmpl': '%(format_id)s-%(id)s.%(ext)s', 'merge_output_format': 'mkv' } with youtube_dl.YoutubeDL(config) as ydl: with suppress(youtube_dl.DownloadError): info = ydl.extract_info(form.download_url.data, download=True) filename = '%(format_id)s-%(id)s.mkv' % info attachment_filename = '%(title)s.mkv' % info return send_file(filename, as_attachment=True, attachment_filename=attachment_filename) return redirect('/')
def index(): form = DownloadForm(request.form) if request.method == 'POST' and form.validate_on_submit(): url = form.url.data media_format = form.media_format.data download_token = form.download_token.data if media_format == 'video': filename = download_video(url) else: filename = download_music(url) response = make_response( send_from_directory('./data', filename, as_attachment=True)) response.set_cookie('download_token', download_token) return response return render_template('index.html', form=form, redirect_url=url_for('index'))
def index(): ''' Index function ''' global file_downloaded global file_cid form = DownloadForm() #In the case that a download is already started returning the page that shows the graphs if file_downloaded != 0: return render_template('plot.html', file_cid=file_cid) #If the request is a POST an user requests a download if request.method == 'POST': if form.validate_on_submit(): #Getting the CID of the content from the form file_cid = request.form['file_cid'] #Starting file download in another thread to not wait for the response thread = threading.Thread(target=get_file, args=(file_cid, )) thread.start() #Returning the page that shows the graphs return render_template('plot.html', file_cid=file_cid) else: #If the request is a GET returning the index page file_downloaded = 0 return render_template('index.html', form=form)