feat: ads a check to see if the video has already been done as suggested in #12

closes #12
pull/418/head
Jason 3 years ago
parent 80653eab7c
commit 8b5670a8eb

@ -44,8 +44,11 @@ In its current state, this bot does exactly what it needs to do. However, lots o
I have tried to simplify the code so anyone can read it and start contibuting at any skill level. Don't be shy :) contribute!
- [ ] Creating better documentation and adding a command line interface.
- [x] Allowing users to choose a reddit thread instead of being randomized.
- [x] Allowing users to choose a background that is picked instead of the Minecraft one.
- [x] Allowing users to choose between any subreddit.
- [x] Allowing users to change voice.
- [ ] Creating better documentation and adding a command line interface.
- [x] Checks if a video has already been created
- [x] Light and Dark modes
- [x] Nsfw post filter

@ -6,6 +6,8 @@ import random
from dotenv import load_dotenv
from os import getenv, environ
from utils.videos import check_done
def ascifi(text):
regrex_pattern = re.compile(pattern="["
@ -45,12 +47,13 @@ def get_subreddit_threads():
else:
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
submission = check_done(submission)
print(submission)
print_substep(
f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)')
environ["VIDEO_TITLE"] = str(ascifi(submission.title))
environ["VIDEO_ID"] = str(ascifi(submission.id))
try:
content["thread_url"] = submission.url

@ -0,0 +1,22 @@
import inspect
import json
from os import getenv
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
"""params:
reddit_object: The Reddit Object you received in askreddit.py"""
if getenv('POST_ID'):
print_step(
'You already have done this video but since it was declared specifically in the .env file the program will continue')
return redditobj
with open('./video_creation/data/videos.json', 'r') as done_vids_raw:
done_videos = json.load(done_vids_raw)
for video in done_videos:
if video['id'] == str(redditobj):
print_step('Getting new post as the current one has already been done')
from reddit.subreddit import get_subreddit_threads
return get_subreddit_threads() # recursive func
return redditobj

@ -65,9 +65,8 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
b64d = base64.b64decode(vstr)
out = open(filename, "wb")
with open(filename, "wb") as out:
out.write(b64d)
out.close()
@staticmethod
def randomvoice():

@ -0,0 +1,23 @@
[
{
"id": "ult7el",
"time": "1654117088",
"background_credit": "Orbital Gameplay",
"reddit_title": "What famous place is not worth visiting?",
"filename": "What famous place is not worth....mp4"
},
{
"id": "v2hup1",
"time": "1654118137",
"background_credit": "bbswitzer",
"reddit_title": "What job interview question do you think is pointless?",
"filename": "What job interview question do....mp4"
},
{
"id": "v2nqiu",
"time": "1654118543",
"background_credit": "bbswitzer",
"reddit_title": "What is a fact that people are not ready to hear?",
"filename": "What is a fact that people are....mp4"
}
]

@ -1,4 +1,6 @@
import json
import os
import time
from moviepy.editor import (VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips,
CompositeAudioClip, CompositeVideoClip)
@ -44,8 +46,22 @@ def make_final_video(number_of_clips):
else:
return title[0:30] + "..."
final.write_videofile(f"results/{get_video_title()}.mp4", fps=30, audio_codec="aac", audio_bitrate="192k")
filename = f'{get_video_title()}.mp4'
def save_data():
with open('./video_creation/data/videos.json', 'r+') as raw_vids:
done_vids = json.load(raw_vids)
if str(os.getenv("VIDEO_ID")) in [video['id'] for video in done_vids]:
return # video already done but was specified to continue anyway in the .env file
payload = {"id": str(os.getenv("VIDEO_ID")), 'time': str(int(time.time())),
"background_credit": str(os.getenv('background_credit')),
"reddit_title": str(os.getenv('VIDEO_TITLE')), "filename": filename}
done_vids.append(payload)
raw_vids.seek(0)
json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4)
save_data()
final.write_videofile(f"results/{filename}", fps=30, audio_codec="aac", audio_bitrate="192k")
print_step("Removing temporary files 🗑")
cleanups = cleanup()
print_substep(f"Removed {cleanups} temporary files 🗑")

Loading…
Cancel
Save