-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (29 loc) · 979 Bytes
/
Copy pathapp.py
File metadata and controls
38 lines (29 loc) · 979 Bytes
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
from flask import Flask,render_template,request
from youtube_transcript_api import YouTubeTranscriptApi
import re
#import pafy
from pytube import extract
app = Flask(__name__)
@app.route('/')
def form():
return render_template('form.html')
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/result',methods = ['POST', 'GET'])
def result():
if request.method == 'POST':
result = request.form.get("yt_url")
source_video_id = extract.video_id(result)
script = ""
try:
transcript = YouTubeTranscriptApi.get_transcript(source_video_id)
for text in transcript:
t = text["text"]
if t != '[Music]':
script += t + " "
return render_template("result.html", script=script)
except:
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)