refactored using black

pull/520/head
Jason 2 years ago
parent dcb42a4939
commit d1faf4824c

@ -2,6 +2,12 @@ from gtts import gTTS
class GTTS: class GTTS:
def tts(self, req_text: str = "Google Text To Speech", filename: str = "title.mp3", random_speaker=False, censer=False): def tts(
self,
req_text: str = "Google Text To Speech",
filename: str = "title.mp3",
random_speaker=False,
censer=False,
):
tts = gTTS(text=req_text, lang="en", slow=False) tts = gTTS(text=req_text, lang="en", slow=False)
tts.save(f"{filename}") tts.save(f"{filename}")

@ -70,11 +70,11 @@ class TikTok: # TikTok Text-to-Speech Wrapper
self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=" self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker="
def tts( def tts(
self, self,
req_text: str = "TikTok Text To Speech", req_text: str = "TikTok Text To Speech",
filename: str = "title.mp3", filename: str = "title.mp3",
random_speaker: bool = False, random_speaker: bool = False,
censer=False, censer=False,
): ):
req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and") req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and")
if censer: if censer:
@ -92,7 +92,7 @@ class TikTok: # TikTok Text-to-Speech Wrapper
audio_clips = [] audio_clips = []
cbn = sox.Combiner() cbn = sox.Combiner()
#cbn.set_input_format(file_type=["mp3" for _ in chunks]) # cbn.set_input_format(file_type=["mp3" for _ in chunks])
chunkId = 0 chunkId = 0
for chunk in chunks: for chunk in chunks:
@ -130,7 +130,7 @@ class TikTok: # TikTok Text-to-Speech Wrapper
for clip in audio_clips: for clip in audio_clips:
i = audio_clips.index(clip) # get the index of the clip i = audio_clips.index(clip) # get the index of the clip
audio_clips = ( audio_clips = (
audio_clips[:i] + [AudioFileClip(clip)] + audio_clips[i + 1:] audio_clips[:i] + [AudioFileClip(clip)] + audio_clips[i + 1 :]
) # replace the clip with an AudioFileClip ) # replace the clip with an AudioFileClip
audio_concat = concatenate_audioclips(audio_clips) audio_concat = concatenate_audioclips(audio_clips)
audio_composite = CompositeAudioClip([audio_concat]) audio_composite = CompositeAudioClip([audio_concat])

@ -5,16 +5,16 @@ from dotenv import load_dotenv
from TTS.GTTS import GTTS from TTS.GTTS import GTTS
from TTS.TikTok import TikTok from TTS.TikTok import TikTok
CHOICE_DIR = { CHOICE_DIR = {"tiktok": TikTok, "gtts": GTTS}
'tiktok': TikTok,
'gtts': GTTS
}
class TTS: class TTS:
def __new__(cls): def __new__(cls):
load_dotenv() load_dotenv()
CHOICE = getenv('TTsChoice').casefold() CHOICE = getenv("TTsChoice").casefold()
valid_keys = [key.lower() for key in CHOICE_DIR.keys()] valid_keys = [key.lower() for key in CHOICE_DIR.keys()]
if CHOICE not in valid_keys: if CHOICE not in valid_keys:
raise ValueError(f'{CHOICE} is not valid. Please use one of these {valid_keys} options') raise ValueError(
f"{CHOICE} is not valid. Please use one of these {valid_keys} options"
)
return CHOICE_DIR.get(CHOICE)() return CHOICE_DIR.get(CHOICE)()

@ -2,8 +2,18 @@
from dotenv import dotenv_values from dotenv import dotenv_values
DEFAULTS = {'SUBREDDIT': "AskReddit", 'ALLOW_NSFW': "False", 'POST_ID': "", 'THEME': "DARK", 'REDDIT_2FA': "no", DEFAULTS = {
'TIMES_TO_RUN': "", 'MAX_COMMENT_LENGTH': "500", 'OPACITY': "1", 'VOICE': "en_us_001", 'STORYMODE': "False"} "SUBREDDIT": "AskReddit",
"ALLOW_NSFW": "False",
"POST_ID": "",
"THEME": "DARK",
"REDDIT_2FA": "no",
"TIMES_TO_RUN": "",
"MAX_COMMENT_LENGTH": "500",
"OPACITY": "1",
"VOICE": "en_us_001",
"STORYMODE": "False",
}
class Config: class Config:

@ -1,4 +1,3 @@
# Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it. # Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it.
# Although, it is edited to use less threads. # Although, it is edited to use less threads.

@ -3,6 +3,7 @@ import json
from os import getenv from os import getenv
from utils.console import print_substep from utils.console import print_substep
def get_subreddit_undone(submissions: List, subreddit): def get_subreddit_undone(submissions: List, subreddit):
""" """
recursively checks if the top submission in the list was already done. recursively checks if the top submission in the list was already done.

@ -4,7 +4,9 @@ from os import getenv
from utils.console import print_step from utils.console import print_step
def check_done(redditobj): # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack def check_done(
redditobj,
): # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack
"""params: """params:
reddit_object: The Reddit Object you received in askreddit.py""" reddit_object: The Reddit Object you received in askreddit.py"""
with open("./video_creation/data/videos.json", "r") as done_vids_raw: with open("./video_creation/data/videos.json", "r") as done_vids_raw:

@ -7,6 +7,7 @@ from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
def get_start_and_end_times(video_length, length_of_clip): def get_start_and_end_times(video_length, length_of_clip):
random_time = randrange(180, int(length_of_clip) - int(video_length)) random_time = randrange(180, int(length_of_clip) - int(video_length))
return random_time, random_time + video_length return random_time, random_time + video_length
@ -17,11 +18,11 @@ def download_background():
Path("./assets/backgrounds/").mkdir(parents=True, exist_ok=True) Path("./assets/backgrounds/").mkdir(parents=True, exist_ok=True)
background_options = [ # uri , filename , credit background_options = [ # uri , filename , credit
("https://www.youtube.com/watch?v=n_Dv4JMiwK8", "parkour.mp4", "bbswitzer"), ("https://www.youtube.com/watch?v=n_Dv4JMiwK8", "parkour.mp4", "bbswitzer"),
#( # (
# "https://www.youtube.com/watch?v=2X9QGY__0II", # "https://www.youtube.com/watch?v=2X9QGY__0II",
# "rocket_league.mp4", # "rocket_league.mp4",
# "Orbital Gameplay", # "Orbital Gameplay",
#), # ),
] ]
# note: make sure the file name doesn't include an - in it # note: make sure the file name doesn't include an - in it
if not len(listdir("./assets/backgrounds")) <= len( if not len(listdir("./assets/backgrounds")) <= len(
@ -32,7 +33,7 @@ def download_background():
) )
print_substep("Downloading the backgrounds videos... please be patient 🙏 ") print_substep("Downloading the backgrounds videos... please be patient 🙏 ")
for uri, filename, credit in background_options: for uri, filename, credit in background_options:
if Path(f'assets/backgrounds/{credit}-{filename}').is_file(): if Path(f"assets/backgrounds/{credit}-{filename}").is_file():
continue # adds check to see if file exists before downloading continue # adds check to see if file exists before downloading
print_substep(f"Downloading {filename} from {uri}") print_substep(f"Downloading {filename} from {uri}")
YouTube(uri).streams.filter(res="1080p").first().download( YouTube(uri).streams.filter(res="1080p").first().download(

@ -88,7 +88,7 @@ def make_final_video(number_of_clips, length):
.resize(width=W - 100) .resize(width=W - 100)
.set_opacity(float(opacity)), .set_opacity(float(opacity)),
) )
#if os.path.exists("assets/mp3/posttext.mp3"): # if os.path.exists("assets/mp3/posttext.mp3"):
# image_clips.insert( # image_clips.insert(
# 0, # 0,
# ImageClip("assets/png/title.png") # ImageClip("assets/png/title.png")
@ -97,16 +97,13 @@ def make_final_video(number_of_clips, length):
# .resize(width=W - 100) # .resize(width=W - 100)
# .set_opacity(float(opacity)), # .set_opacity(float(opacity)),
# ) # )
#else: # else:
image_clips.insert( image_clips.insert(
0, 0,
ImageClip("assets/temp/png/title.png") ImageClip("assets/temp/png/title.png").set_duration(audio_clips[0].duration)
.set_duration(audio_clips[0].duration) # .set_duration(audixc vcco_clips[0].duration)
#.set_duration(audixc vcco_clips[0].duration) .set_position("center").resize(width=W - 100).set_opacity(float(opacity)),
.set_position("center") )
.resize(width=W - 100)
.set_opacity(float(opacity)),
)
image_concat = concatenate_videoclips(image_clips).set_position( image_concat = concatenate_videoclips(image_clips).set_position(
("center", "center") ("center", "center")
) )

Loading…
Cancel
Save