-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
111 lines (88 loc) · 3.9 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from flask import Flask,render_template,request,send_from_directory,send_file,redirect
import os
from pytube import YouTube
from io import BytesIO
from helpers import channel_details
from helpers import all_video_details
from helpers import get_individual_video_details
from helpers import insert_all_video_details_to_snowflakes
from helpers import comments_central
from helpers import comments_counter_df
from helpers import mongodb
from helpers import display
from helpers import empty_databases
from helpers import comments_reader
from helpers import upload_to_s3
app=Flask(__name__)
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path,'static'),'favicon.ico',mimetype='images/favicon.png')
@app.route('/')
@app.route('/homepage',methods=['GET','POST'])
def homepage():
if request.method=='GET':
return render_template ('homepage.html')
if request.method=='POST':
return render_template ('homepage.html')
@app.route('/channelpage',methods=['POST'])
def channelpage():
channel_url=request.form.get('channel_url')
try:
channel_id_name_logo=channel_details.channel_details_gather(channel_url)
return render_template ('channelpage.html',channel_id_name_logo=channel_id_name_logo)
except:
return render_template('wrong_credentials.html')
@app.route('/top50_videos',methods=['POST'])
def top50_videos():
channel_id=request.form.get('channel_id')
channel_name=request.form.get('channel_name')
channel_logo=request.form.get('channel_logo')
number_of_videos=request.form.get('number_of_videos')
channel_id_name_logo=request.form.get('channel_id_name_logo')
all_videos_id_title_thumbnail=all_video_details.get_vid_details(channel_id,number_of_videos)
list_of_video_ids=[]
list_of_video_ids=[video_details['video_id'] for video_details in all_videos_id_title_thumbnail]
individual_video_id_author_duration_likes_views=get_individual_video_details.details(list_of_video_ids)
parent_comments,reply_comments=comments_central.main(list_of_video_ids)
df=comments_counter_df.comment_counter(parent_comments,reply_comments)
df3=insert_all_video_details_to_snowflakes.merging(all_videos_id_title_thumbnail,individual_video_id_author_duration_likes_views,channel_id_name_logo,df)
mongodb.mongo_connector(parent_comments,reply_comments,df3)
top_details=display.main(list_of_video_ids)
all_thumbnails=display.mongo(top_details)
zipped=zip(top_details,all_thumbnails)
return render_template('display_all_videos.html',details=zipped)
@app.route('/deletedatabases',methods=['POST'])
def delete_databases():
empty_databases.main()
return render_template ('successfull.html')
@app.route('/comments',methods=['POST'])
def comments():
video_id=request.form.get('vid_id')
print(video_id)
final_comments=comments_reader.main(video_id)
return render_template('comments_print.html',comments=final_comments)
@app.route('/download',methods=['POST'])
def download():
video_id=request.form.get('vid_id')
buffer = BytesIO()
url = 'https://www.youtube.com/watch?v='+video_id
yt = YouTube(url)
video = yt.streams.get_lowest_resolution()
video.stream_to_buffer(buffer)
buffer.seek(0)
return send_file(buffer, as_attachment = True, download_name= 'video.mp4')
@app.route('/awsuploadconfirm',methods=['POST'])
def awsuploadconfirm():
video_id=request.form.get('vid_id')
return render_template('awsconfirmation.html',video_id=video_id)
@app.route('/upload',methods=['POST'])
def upload():
password=request.form.get('aws_pass')
if password==os.environ['AWS_UPLOAD_PASSWORD']:
video_id=request.form.get('vid_id')
upload_to_s3.main(video_id)
return render_template ('successfull.html')
else:
return render_template ('wrong_credentials.html')
if __name__=='__main__':
app.run(debug=True)