Update app.py
Browse files4 unmodified lines56789101129 unmodified lines4142434445464736 unmodified lines848586878889909192939495969798991001011021031041051064 unmodified linesimport loggingfrom flask import Flask, render_template, request, send_file, jsonifyfrom werkzeug.utils import secure_filenamefrom pydub import AudioSegmentapp = Flask(__name__)29 unmodified lineslogger.info(f"File saved: {filepath}")factor = int(request.form['factor'])is_decrypting = filename.lower().endswith('.mp3')logger.info(f"Processing file: {'decrypting' if is_decrypting else 'encrypting'} with factor {factor}")try:36 unmodified lineswav_output.setframerate(44100)wav_output.writeframes(struct.pack(f'{len(samples)}h', *samples))# Convert WAV to MP3output.seek(0)audio = AudioSegment.from_wav(output)mp3_output = io.BytesIO()audio.export(mp3_output, format="mp3")logger.info(f"Encryption complete. Output size: {mp3_output.getbuffer().nbytes} bytes")return mp3_output.getvalue(), 'encrypted.mp3', 'audio/mpeg'def decrypt_file(filepath, factor):logger.info(f"Decrypting file: {filepath}")audio = AudioSegment.from_mp3(filepath)wav_data = io.BytesIO()audio.export(wav_data, format="wav")wav_data.seek(0)with wave.open(wav_data, 'rb') as wav_file:params = wav_file.getparams()frames = wav_file.readframes(wav_file.getnframes())4 unmodified lines567891029 unmodified lines4041424344454636 unmodified lines8384858687888990919293944 unmodified linesimport loggingfrom flask import Flask, render_template, request, send_file, jsonifyfrom werkzeug.utils import secure_filenameapp = Flask(__name__)29 unmodified lineslogger.info(f"File saved: {filepath}")factor = int(request.form['factor'])is_decrypting = filename.lower().endswith('.wav')logger.info(f"Processing file: {'decrypting' if is_decrypting else 'encrypting'} with factor {factor}")try:36 unmodified lineswav_output.setframerate(44100)wav_output.writeframes(struct.pack(f'{len(samples)}h', *samples))logger.info(f"Encryption complete. Output size: {output.getbuffer().nbytes} bytes")return output.getvalue(), 'encrypted.wav', 'audio/wav'def decrypt_file(filepath, factor):logger.info(f"Decrypting file: {filepath}")with wave.open(filepath, 'rb') as wav_file:params = wav_file.getparams()frames = wav_file.readframes(wav_file.getnframes())
app.py+4-16