-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathapp.py
208 lines (150 loc) · 4.46 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from flask import Flask, render_template, request, flash, redirect
from flask import send_file, url_for, after_this_request
from flask_session import Session
import requests
import sqlite3 as sql
import connection as cn
from config import Config
import os
import urllib
from dotenv import load_dotenv
from songs import oauth, ext_down
from anime import anime_download
load_dotenv()
DATABASE = cn.DATABASE
cn.get_db()
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__),"templates")
STATIC_DIR = os.path.join(os.path.dirname(__file__),"static")
app = Flask(__name__, template_folder=TEMPLATE_DIR, static_folder=STATIC_DIR)
app.config.from_object(Config)
session = Session()
session.init_app(app)
@app.route('/')
def main():
return render_template('index.html')
@app.route('/signup',methods=['POST','GET'])
def signup():
if request.method=='GET':
return render_template('Register.html')
try:
con = sql.connect(DATABASE)
fnm = request.form['firstname']
lnm = request.form['lastname']
email = request.form['email']
unm = request.form['username']
pwd = request.form['password']
cpwd = request.form['conf-password']
if pwd != cpwd:
msg = "Passwords did not match"
flash('Passwords do not match','invalid')
else:
cur = con.cursor()
result = cur.execute(
'SELECT * FROM users WHERE uname=?;',(unm,)
).fetchall()
if not result:
result = cur.execute(
'SELECT * FROM users WHERE email=?;',(email,)
).fetchall()
if not result:
cur.execute("INSERT INTO users " +
"(fname,lname, email, uname, password) " +
"VALUES (?,?,?,?,?)",(fnm,lnm,email,unm,pwd)
)
con.commit()
flash('Registered Successfully','valid')
msg = "Record successfully added"
else:
flash('Email ID already exists!','invalid')
else:
flash('Username exists!','invalid')
except:
con.rollback()
msg = "Error in Insert Operation"
con.close()
print(msg)
return render_template("aftersignup.html",msg=msg)
@app.route('/login',methods=['POST', 'GET'])
def login():
if request.method == 'POST':
email = request.form['email']
pwd = request.form['password']
con = sql.connect(DATABASE)
cur = con.cursor()
results = cur.execute(
"SELECT password FROM users WHERE email=?",(email,)
).fetchall()
if results:
for row in results:
if(row[0]==pwd):
flash("login succcessful")
return redirect("/profile")
else:
flash('Passwords do not match','invalid')
return redirect("/")
else:
flash('Username does not exist','invalid')
return redirect('/')
else:
return render_template('signin.html')
@app.route('/profile')
def profile():
return render_template('profile.html')
@app.route('/song')
def song_list():
song = request.args.get('song')
if song is None:
return render_template("songs.html")
results = ext_down.video_id(song)
URL = "http://localhost:5000/song_down?"
for ind,result in enumerate(results):
f = {
"id" : result["id"],
"title" : result["title"],
"song" : song
}
result["url"] = URL + urllib.parse.urlencode(f)
results[ind] = result
return render_template('songs.html', results=results)
@app.route('/song_down')
def song_down():
id = request.args.get('id')
name = request.args.get('title')
attachment = request.args.get('song') + ".mp3"
filename = ext_down.youtbe_dl_down(id,name)
return send_file(filename,as_attachment=True,attachment_filename=attachment)
@app.route('/anime')
def anime_list():
anime = request.args.get('anime')
result = anime_download.SearchAnime(anime)
if result["status"] == "success":
animes = []
for anime in result["links"]:
anime["link"] = url_for('anime_down',name=anime["name"],url=anime["url"])
animes.append(anime)
return render_template('anime.html',results=animes)
return result["status"]
@app.route('/anime/<name>')
def anime_down(name):
url = request.args.get('url')
print(url)
results = anime_download.getDownloadlinks(url)
if results["status"] == "success":
episodes = []
for ep in results["links"]:
ep["link"] = ep["url"]
episodes.append(ep)
return render_template('anime.html',results=episodes)
return results["status"]
@app.route('/oauth2callback')
def oauth2callback():
try:
code=request.args.get('code')
except:
return "Acces denied"
resp = oauth.ret_token(code)
@app.route('/logout')
def logout():
return render_template("index.html")
if __name__ == '__main__':
app.run(debug = True)