-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.py
65 lines (45 loc) · 1.41 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
from youtube2notion.youtube2notion import Youtube2notion
from flask import Flask, request
from os.path import exists
from shutil import rmtree
from os import environ
import googlecloudprofiler
app = Flask(__name__)
@app.route('/')
def index():
return {}
@app.route('/upload', methods=['POST'])
def upload():
req = request.get_json()
video_id = req.get('video_id')
notion_token_v2 = req.get('notion_token_v2')
notion_page_url = req.get('notion_page_url')
subtitle_language = req.get('subtitle_language')
if not video_id:
return {'msg': 'invalid video_id'}, 400
output_dir = './tmp/%s/' % video_id
y2n = Youtube2notion(
video_id=video_id,
output_dir=output_dir,
notion_token_v2=notion_token_v2,
notion_page_url=notion_page_url,
subtitle_language=subtitle_language)
try:
y2n.execute()
except Exception as e:
return {'msg': type(e).__name__ + str(e)}, 400
finally:
if exists(output_dir):
rmtree(output_dir)
return {}
def shouldProfile() -> bool:
return environ.get('SHOULD_PROFILE') == 'true'
def setUpProfiler(serviceName: str):
googlecloudprofiler.start(service=serviceName)
def main():
serviceName: str = 'youtube2notion'
if shouldProfile():
setUpProfiler(serviceName)
app.run(host='0.0.0.0', port='5000', debug=True)
if __name__ == "__main__":
main()