diff --git a/.gitignore b/.gitignore index e4b0aa2..f5bfdaa 100755 --- a/.gitignore +++ b/.gitignore @@ -129,3 +129,12 @@ dmypy.json .pyre/ config.ini +videos/ +*.mp4 +*.webm +*.mkv +*.avi +*.ogv +*.ogg +*.mp3 +*.flac \ No newline at end of file diff --git a/mail.py b/mail.py index 5f4ec2d..ad2f7e6 100755 --- a/mail.py +++ b/mail.py @@ -1,4 +1,8 @@ -import configparser, email, os, smtplib, ssl +import configparser +import email +import os +import smtplib +import ssl from email import encoders from email.mime.base import MIMEBase @@ -8,39 +12,40 @@ from email.mime.text import MIMEText config = configparser.ConfigParser() config.read('config.ini') + def send_email(destination, attachment): subject = 'Your modified video' body = 'You have recently used our service to modify a video. The result is attached.' sender_email = config.get('Mail', 'Username') receiver_email = destination password = config.get('Mail', 'Password') - + # Create a multipart message and set headers message = MIMEMultipart() message['From'] = sender_email message['To'] = receiver_email message['Subject'] = subject - + # Add body to email message.attach(MIMEText(body, 'plain')) with open(attachment, 'rb') as file: part = MIMEBase('application', 'octet-stream') part.set_payload(file.read()) - + # Encode file in ASCII characters to send by email encoders.encode_base64(part) - + # Add header as key/value pair to attachment part part.add_header( 'Content-Disposition', f'attachment; filename= {os.path.normpath(attachment)}', ) - + # Add attachment to message and convert message to string message.attach(part) text = message.as_string() - + # Log in to server using secure context and send email if config.getboolean('Mail', 'SSL'): context = ssl.create_default_context() diff --git a/main.py b/main.py index a1fcda6..988300b 100755 --- a/main.py +++ b/main.py @@ -10,12 +10,15 @@ import moviepy.editor as moviepy app = Flask(__name__) ALLOWED_UPLOAD_EXTENSIONS = {'mp4', 'webm', 'mkv', 'avi', 'ogv'} -ALLOWED_CONVERT_EXTENSIONS = {'mp4', 'webm', 'mkv', 'avi', 'ogv', 'ogg', 'mp3', 'flac'} +ALLOWED_CONVERT_EXTENSIONS = {'mp4', 'webm', + 'mkv', 'avi', 'ogv', 'ogg', 'mp3', 'flac'} AUDIO_EXTENSIONS = {'ogg', 'mp3', 'flac'} -ALLOWED_WATERMARK_EXTENSIONS = {'bmp', 'png', 'jpg', 'jpeg', 'tiff', 'tga', 'svg'} +ALLOWED_WATERMARK_EXTENSIONS = { + 'bmp', 'png', 'jpg', 'jpeg', 'tiff', 'tga', 'svg'} percentages = {} + class BarLogger(ProgressBarLogger): global percentages id = None @@ -27,12 +30,14 @@ class BarLogger(ProgressBarLogger): super(self.__class__, self).__init__() self.id = id + def is_integer(n): try: return float(n).is_integer() except ValueError: return False + def getExtension(filename, isWatermark=False): if not '.' in filename: return False @@ -44,6 +49,7 @@ def getExtension(filename, isWatermark=False): else: return False + @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST' and 'video' in request.files: @@ -59,12 +65,15 @@ def index(): return render_template('index.html') + @app.route('/video', methods=['GET', 'POST']) def video(): error = '' changed = False audio = None id = request.args.get('id') + if id == None: + abort(400) path = os.path.join('videos', id) if id != None and os.path.isfile(path): clip = moviepy.VideoFileClip(path) @@ -101,20 +110,23 @@ def video(): else: watermarkExtension = getExtension(file.filename, True) if watermarkExtension: - watermarkPath = os.path.join('videos', id + '-watermark' + '.' + watermarkExtension) + watermarkPath = os.path.join( + 'videos', id + '-watermark' + '.' + watermarkExtension) file.save(watermarkPath) formatter = {'PNG': 'RGBA', 'JPEG': 'RGB'} img = Image.open(watermarkPath) - rgbimg = Image.new(formatter.get(img.format, 'RGB'), img.size) + rgbimg = Image.new(formatter.get( + img.format, 'RGB'), img.size) rgbimg.paste(img) rgbimg.save(watermarkPath, format=img.format) watermark = (moviepy.ImageClip(watermarkPath) - .set_duration(clip.duration) - .set_pos(('right', 'bottom'))) + .set_duration(clip.duration) + .set_pos(('right', 'bottom'))) - clip = moviepy.CompositeVideoClip([clip, watermark]) + clip = moviepy.CompositeVideoClip( + [clip, watermark]) os.remove(watermarkPath) changed = True else: @@ -133,10 +145,11 @@ def video(): os.remove(path) return render_template('success.html', error=error) - return render_template('video.html', id=id, length=int(clip.duration), error=error) + return render_template('video.html', length=int(clip.duration), error=error) else: abort(404) + @app.route('/progress', methods=['GET']) def progress(): id = request.args.get('id') @@ -146,6 +159,7 @@ def progress(): else: abort(404) + if __name__ == '__main__': if not os.path.isdir('videos'): os.mkdir('videos') diff --git a/templates/index.html b/templates/index.html index 555ccb8..a88c864 100755 --- a/templates/index.html +++ b/templates/index.html @@ -1,8 +1,10 @@ +
{{ error | safe }}
@@ -13,5 +15,5 @@ - - + +