-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
359 lines (251 loc) · 8.73 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
import datetime
import os
import subprocess
from pytube.extract import LiveStreamError
from ytapi import api
app = ""
try:
import flask_cors
from flask_cors import CORS, cross_origin
from flask import Flask, render_template, request
#from flask_restx import Api, Resource, reqparse
app = Flask(__name__)
app.register_blueprint(api, url_prefix='/api')
#api = Api(app, version='1.0', title='API 문서', description="DELIMUSIC API 문서", doc="/api/docs")
#user_api = api.namespace('user', description='유저 API')
CORS(app, resources={r'*': {'origins': '*'}})
except ModuleNotFoundError:
os.system('pip install flask')
os.system('pip install flask[async]')
os.system('pip install flask_cors')
os.system('pip install flask_restx')
import flask_cors
from flask_cors import CORS, cross_origin
from flask import Flask, render_template, request
app = Flask(__name__)
app.register_blueprint(api, url_prefix='/api')
CORS(app, resources={r'*': {'origins': '*'}})
try:
import firebase_admin
from firebase_admin import auth
from firebase_admin import credentials
from firebase_admin import storage
from firebase import Firebase
import requests
import scrapetube
import youtube_transcript_api
import uyts
from pytube import YouTube
from pytube import Channel
from youtubesearchpython import VideosSearch
from ytmusicapi import YTMusic
from pytube import Playlist
from art import *
from youtube_transcript_api import YouTubeTranscriptApi
firebaseConfig = {
"apiKey": "AIzaSyCAPx_GfSFjGtWo08nuaPEd0RmWL-ar_-Y",
"authDomain": "dely-music.firebaseapp.com",
"projectId": "dely-music",
"storageBucket": "dely-music.appspot.com",
"messagingSenderId": "247613470910",
"appId": "1:247613470910:web:d570f395749ef1da95c6ef",
"measurementId": "G-2J7WX0YP24",
"databaseURL": "https://dely-music-default-rtdb.firebaseio.com/"
};
#파이어베이스 서비스 세팅
cred = credentials.Certificate('./cert/firebase-service-account.json')
default_app = firebase_admin.initialize_app(cred, {"databaseURL": "https://dely-music-default-rtdb.firebaseio.com/"})
Auth = Firebase(firebaseConfig).auth()
Storage = Firebase(firebaseConfig).storage()
except ModuleNotFoundError:
os.system('pip install unlimited-youtube-search')
os.system('pip install youtube-search-python')
os.system('pip install ytmusicapi')
os.system('pip install pytube')
os.system('pip install art')
os.system('pip install youtube-transcript-api')
os.system('pip install scrapetube')
os.system('pip install firebase')
os.system('pip install firebase_admin')
import json
import urllib
# search_results = ytmusic.search("뉴진스", "albums")
# print(search_results)
#HTLM 뿌리는곳
@app.route('/player')
def player():
return render_template("player.html")
@app.route('/index')
def index():
return render_template("index.html")
@app.route('/')
def main():
return render_template("main.html")
@app.route('/Register')
def join():
return render_template("join.html")
@app.route('/list/khot')
def khot():
return render_template("khot.html")
@app.route('/Login')
def login():
return render_template("login.html")
@app.route('/Profile')
def profile():
return render_template("profile.html")
@app.route('/Search')
def search():
return render_template("search.html")
@app.route('/detail')
def detail():
return render_template("detail.html")
@app.route("/test")
def hello_world(): # put application's code here
"""search = ytmusic.search("we're good", ["songs"], limit=2)
print(search)
title = []
id = []
channel = []
thumbnail = []
duration = []
desc = []
videosSearch = VideosSearch('오르막길')
amount = len(videosSearch.result()['result'])
for data in videosSearch.result()['result']:
if (data['type'] == "video"):
title.append(data['title'])
id.append(data['id'])
channel.append(data['channel'])
thumbnail.append(data['thumbnails'])
duration.append(data['duration'])
desc.append(data['descriptionSnippet'])"""
return render_template("test.html")
# HTML 뿌리는곳 끝
#유저 관리구역 시작
#로그인
@app.route("/User/Login", methods=["POST"])
async def user_login():
email = request.form['email']
password = request.form['password']
try:
Auth.sign_in_with_email_and_password(email, password)
except requests.exceptions.HTTPError as erra:
#HTTP 에러가 발생한 경우
#오류 가져오기 json.loads(str(erra).split("]")[1].split('"errors": [\n')[1])['message']
return json.loads(str(erra).split("]")[1].split('"errors": [\n')[1])['message']
currentuser = Auth.current_user
user = requests.get(
url='https://2gseogdrb1.execute-api.ap-northeast-2.amazonaws.com/default2/user',
json={'Id':currentuser['localId']}
)
user.encoding = "UTF-8"
return json.loads(user.text)['id']
#
@app.route("/User/Register", methods=["POST"])
async def user_create():
now = datetime.now()
email = request.form['email']
password = request.form['password']
nickname = request.form['nickname']
#이메일이 공란이면
if(len(email) == 0):
return "MISSING_EMAIL"
#비번이 공란이면
if(len(password) == 0):
return "MISSING_PASSWORD"
else:
#비번이 6자리 이하이면
if(len(password) <= 6):
return "PASSWORD_TOO_SHORT"
else:
#비번에 4글자이상 중복되는 글자가 있으면
if(re.search('(([a-zA-Z0-9])\\2{5,})', password)):
return "TOO_MANY_DUPICATE"
#닉네임이 공란이면
if(len(nickname) == 0):
return "MISSING_NICKNAME"
try:
#파이어베이스의 유저만드는거 사용
a = Auth.create_user_with_email_and_password(email, password)
except requests.exceptions.HTTPError as erra:
#HTTP 에러가 발생한 경우
#오류 가져오기 json.loads(str(erra).split("]")[1].split('"errors": [\n')[1])['message']
return json.loads(str(erra).split("]")[1].split('"errors": [\n')[1])['message']
#유저의 고유 아이디 (UniqueID)
id = a['localId']
data = {
'email':email,
'Id':id,
'Nickname':nickname,
'Created_At':str(now)
}
try:
c = requests.post(
url = 'https://2gseogdrb1.execute-api.ap-northeast-2.amazonaws.com/default2/user',
json=data
)._content
except requests.exceptions.RequestException as erra:
print( erra)
return erra
if(str(c).split("\"")[1].split("\"")[0] == "Status Code : 200 | OK : Successfully added data "):
return "OK"
print(c)
return c['errorMessage']
#유저 정보
@app.route("/User", methods=["POST"])
async def get_user():
id = request.form['id']
user = requests.get(
url='https://2gseogdrb1.execute-api.ap-northeast-2.amazonaws.com/default2/user',
json={'Id':id}
)
user.encoding = "UTF-8"
return json.loads(user.text)
#아이디 조회
@app.route("/User/FindID", methods=["POST"])
async def FindID():
name = request.form['name']
phone = request.form['phone']
birthday = request.form['birthday']
json1 = {
'name' : name,
'phone' : phone,
'birthday' : birthday
}
ID = requests.get(
url='https://2gseogdrb1.execute-api.ap-northeast-2.amazonaws.com/default2/user/findid',
json=json1
)
ID.encoding = "UTF-8"
return json.loads(ID.text)
#비번 초기화 이메일 보내기
@app.route("/User/ResetPW", methods=["POST"])
async def RSTPW():
email = request.form['email']
try:
Auth.send_password_reset_email(email)
except requests.exceptions.HTTPError as err:
#print(json.loads(str(err).split("]")[1].split('"errors": [\n')[1])['message'])
return json.loads(str(err).split("]")[1].split('"errors": [\n')[1])['message']
return "DONE"
#유저 삭제
@app.route("/User", methods=["DELETE"])
async def deleteuser():
id = request.form['id']
email = request.form['email']
json1 = {
'id':id,
'email':email
}
try:
res = requests.delete(
url='https://2gseogdrb1.execute-api.ap-northeast-2.amazonaws.com/default2/user',
json=json1
)
except requests.exceptions.RequestException as error:
return error
auth.delete_user(id)
return "OK"
#유저 관리 끝
if __name__ == '__main__':
app.run('0.0.0.0', port=81, debug=True)