Converter arquivos

File Converter

File Converter

body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f0f0f0; }.container { background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; }h1 { margin-bottom: 20px; }form { display: flex; flex-direction: column; }label { margin-top: 10px; }input, select, button { margin-top: 10px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; }button { background-color: #28a745; color: white; border: none; cursor: pointer; }button:hover { background-color: #218838; }from flask import Flask, render_template, request, send_file import os import subprocessapp = Flask(__name__)UPLOAD_FOLDER = ‘uploads’ CONVERTED_FOLDER = ‘converted’os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(CONVERTED_FOLDER, exist_ok=True)@app.route(‘/’) def index(): return render_template(‘index.html’)@app.route(‘/convert’, methods=[‘POST’]) def convert_file(): file = request.files[‘file’] format = request.form[‘format’] filename = file.filename filepath = os.path.join(UPLOAD_FOLDER, filename) file.save(filepath) output_filename = os.path.splitext(filename)[0] + ‘.’ + format output_filepath = os.path.join(CONVERTED_FOLDER, output_filename) convert_command = f”ffmpeg -i {filepath} {output_filepath}” subprocess.run(convert_command, shell=True) return send_file(output_filepath, as_attachment=True)if __name__ == ‘__main__’: app.run(debug=True)