refactor(video.py): remove unnecessary print statement

refactor(montage.py): use os.path.join instead of string concatenation
refactor(thumbnail.py): use os.path.join instead of string concatenation
refactor(uploader.py): use os.path.join instead of string concatenation
refactor(uploader.py): add support for client_secret.json file with different names in credentials folder
docs(readme.md): update instructions for openai and unsplash keys
docs(readme.md): update instructions for google oauth client id json files
docs(readme.md): add information about channel.yaml file in each channel's folder
This commit is contained in:
Paillat
2023-06-25 17:40:01 +02:00
parent 268be54efe
commit 131e64eae0
5 changed files with 34 additions and 28 deletions

View File

@@ -18,7 +18,7 @@ if not unsplash_access:
unsplash_url = "https://api.unsplash.com/photos/random/?client_id=" + unsplash_access + "&query="
async def prepare(path):
with open(path + "/script.json", 'r', encoding='utf-8') as f:
with open(os.path.join(path, "script.json"), 'r', encoding='utf-8') as f:
script = json.load(f)
f.close()
if not os.path.exists(path + "/slides"): os.mkdir(path + "/slides")
@@ -70,7 +70,7 @@ async def prepare(path):
with open(path + "/slides/slide" + str(i) + ".md", 'w', encoding='utf-8') as f:
f.write(marp + "\n\n") # blank slide
for i in range(len(script)):
marrkdown_path = "./" + path + "/slides/slide" + str(i) + ".md"
marrkdown_path = os.path.join(path, f"slides/slide{i}.md")
if os.path.exists(f"./{path}/slides/slide{i}.png"):
#skip this slide
continue
@@ -134,6 +134,6 @@ async def mount(path, script):
with open (randpath.split(".")[0] + ".txt", 'r', encoding='utf-8') as f:
music_credit = f.read()
f.close()
return music_credit
return music_credit or ""
else:
return None

View File

@@ -5,6 +5,7 @@ from PIL import Image
from PIL import Image, ImageDraw, ImageFont
from utils.openaicaller import openai
from utils.misc import open_explorer_here
'''
Putpose of this file is to generate a miniature of the video.
It has a function that takes a path, title, and description and generates a miniature.
@@ -47,7 +48,7 @@ async def rand_gradient(image):
async def generate_thumbnail(path, title, description):
prmpt = prompt.replace("[TITLE]", title).replace("[DESCRIPTION]", description)
response = openai.generate_response(
response = await openai.generate_response(
model="gpt-4",
messages=[
{"role":"user","content":prmpt},
@@ -58,14 +59,18 @@ async def generate_thumbnail(path, title, description):
await generate_image(path, text1, text2)
async def generate_image(path, text1, text2):
path_to_bcg = path.split("/")[:-1]
path_to_bcg = "/".join(path_to_bcg)
# path_to_bcg = path.split("/")[:-1]
# path_to_bcg = "/".join(path_to_bcg)
#use os instead
path_to_bcg = os.path.dirname(os.path.dirname(path))
print(path_to_bcg)
if not os.path.exists(f"{path_to_bcg}/bcg.png"):
input("bcg.png not found. Please put bcg.png in the same folder as the video."+path_to_bcg)
input("bcg.png not found. Please put bcg.png in the folder that will open. Press enter to open the folder.")
open_explorer_here(path_to_bcg)
input("Press enter when you have put bcg.png in the folder.")
if not os.path.exists(f"{path_to_bcg}/bcg.png"):
input("bcg.png still not found. Exiting.")
exit()
raise FileNotFoundError("bcg.png not found")
bcg = Image.open(f"{path_to_bcg}/bcg.png")
img = Image.new('RGBA', (1920, 1080))
img, textcolor1, textcolor2 = await rand_gradient(img)