-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
41 lines (31 loc) · 1.28 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask, render_template, request, send_file, session
import helper
app = Flask(__name__)
app.secret_key = 'change-this-lelmao'
@app.errorhandler(404)
def not_found(error):
return render_template('not_found.html')
@app.errorhandler(500)
def internal(error):
return render_template('internal.html')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/mp3/<variable>')
def mp3(variable):
additive = (request.full_path).replace("/mp3/", "")
session['url'] = "https://youtube.com/" + additive
session['title'] = helper.retrieve_title(session['url'])
if session['title'] == 'Error Occurred':
return render_template('internal.html')
while session['title'] == 'YouTube':
session['title'] = helper.retrieve_title(session['url'])
length = helper.retrieve_length(session['url'])
thumbnail_url = helper.retrieve_thumbnail(session['url'])
return render_template('mp3.html', title = session['title'], length = length, thumbnail_url = thumbnail_url)
@app.route('/download/')
def final():
helper.download(session['title'])
return send_file('{}.mp3'.format(session['title']), as_attachment = True, attachment_filename = '{}.mp3'.format(session['title']) )
if __name__ == "__main__":
app.run()