This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathvideoscript.py
62 lines (50 loc) · 1.79 KB
/
videoscript.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
from datetime import datetime
from moviepy.editor import AudioFileClip
import voiceover
MAX_WORDS_PER_COMMENT = 100
MIN_COMMENTS_FOR_FINISH = 4
MIN_DURATION = 20
MAX_DURATION = 58
class VideoScript:
title = ""
fileName = ""
titleSCFile = ""
url = ""
totalDuration = 0
frames = []
def __init__(self, url, title, fileId) -> None:
self.fileName = f"{datetime.today().strftime('%Y-%m-%d')}-{fileId}"
self.url = url
self.title = title
self.titleAudioClip = self.__createVoiceOver("title", title)
def canBeFinished(self) -> bool:
return (len(self.frames) > 0) and (self.totalDuration > MIN_DURATION)
def canQuickFinish(self) -> bool:
return (len(self.frames) >= MIN_COMMENTS_FOR_FINISH) and (self.totalDuration > MIN_DURATION)
def addCommentScene(self, text, commentId) -> None:
wordCount = len(text.split())
if (wordCount > MAX_WORDS_PER_COMMENT):
return True
frame = ScreenshotScene(text, commentId)
frame.audioClip = self.__createVoiceOver(commentId, text)
if (frame.audioClip == None):
return True
self.frames.append(frame)
def getDuration(self):
return self.totalDuration
def getFileName(self):
return self.fileName
def __createVoiceOver(self, name, text):
file_path = voiceover.create_voice_over(f"{self.fileName}-{name}", text)
audioClip = AudioFileClip(file_path)
if (self.totalDuration + audioClip.duration > MAX_DURATION):
return None
self.totalDuration += audioClip.duration
return audioClip
class ScreenshotScene:
text = ""
screenShotFile = ""
commentId = ""
def __init__(self, text, commentId) -> None:
self.text = text
self.commentId = commentId