-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (31 loc) · 1.21 KB
/
main.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
"""A web-based front end for pytube"""
# Import dependencies
from flask import Flask, render_template, request, send_file
from downloader import Downloader
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def start_page():
"""Main page"""
if request.method == 'POST':
# Get form data from HTMl file
url = request.form.get('video_url')
dl_format = request.form.get('btnradio')
# Set download path
dl_path = 'download'
# Check how the video will be downloaded
if dl_format == "video":
# Create a Downloader object and set download folder
dl = Downloader(url, dl_path)
dl.download_video()
# Send downloaded video to the client
return send_file(dl.full_path('mp4'), as_attachment=True)
elif dl_format == "audio":
# Create a Downloader object and set download folder
dl = Downloader(url, dl_path)
dl.download_audio()
# Send downloaded video to the client
return send_file(dl.full_path('webm'), as_attachment=True)
# Display the main page
return render_template('index.html')
if __name__ == "__main__":
app.run(debug=True)