y2t added
This commit is contained in:
parent
3b93c9ffbf
commit
5e3d902471
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Y2T</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="root">
|
||||
|
||||
<form method="post" action="handler.php">
|
||||
<label for="url">URL:</label><br>
|
||||
<input type="text" id="url" name="url"><br>
|
||||
<label for="lang">Language:</label><br>
|
||||
<input type="text" id="lang" name="lang"><br><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
<script src="assets/js/vue.min.js"></script>
|
||||
<script src="assets/js/app.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,63 @@
|
|||
import youtube_dl
|
||||
import sys
|
||||
|
||||
url = sys.argv[1]
|
||||
lang = sys.argv[2]
|
||||
|
||||
ydl_opts = {
|
||||
'writesubtitles': True,
|
||||
'writeautomaticsub': True,
|
||||
'subtitlesformat': 'vtt',
|
||||
'subtitleslangs': [lang],
|
||||
'lkjsdlfkjsdf': 'sdflkj',
|
||||
'outtmpl': '%(id)s',
|
||||
'skip_download': True,
|
||||
'writethumbnail': True,
|
||||
'quiet': True
|
||||
}
|
||||
|
||||
ydl = youtube_dl.YoutubeDL(ydl_opts)
|
||||
|
||||
ydl.download([url])
|
||||
|
||||
info = ydl.extract_info(url, download=False)
|
||||
|
||||
creator = info['uploader']
|
||||
title = info['title']
|
||||
id = info['id']
|
||||
|
||||
subFn = id + "." + lang + ".vtt"
|
||||
|
||||
txt = ""
|
||||
|
||||
with open(subFn, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
for i in range(len(lines)):
|
||||
if i < len(lines) - 1 and ">" not in lines[i] and ":" not in lines[i] and lines[i].strip() != "" and lines[i + 1].strip() == "":
|
||||
txt += lines[i]
|
||||
|
||||
|
||||
txt = txt.replace("\n"," ")
|
||||
#print(txt)
|
||||
words = txt.split()
|
||||
|
||||
sList = []
|
||||
wCount = 0
|
||||
maxWordCount = 1000
|
||||
currentString = ""
|
||||
|
||||
for w in words:
|
||||
wCount +=1
|
||||
currentString += w + " "
|
||||
if wCount == maxWordCount:
|
||||
sList.append(currentString)
|
||||
wCount = 0
|
||||
currentString = ""
|
||||
if currentString:
|
||||
sList.append(currentString)
|
||||
|
||||
blocks = len(sList)
|
||||
|
||||
for i in range(blocks):
|
||||
print('This is part '+ str(i+1) +'/'+ str(blocks) + "of the transcript of a video named: "+ title)
|
Loading…
Reference in New Issue