2023-05-15 10:11:04 +02:00
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
import asyncio
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
from generators.ideas import generate_ideas
|
|
|
|
|
from generators.script import generate_script
|
2023-05-22 10:40:33 +02:00
|
|
|
from generators.montage import mount, prepare
|
2023-05-15 10:11:04 +02:00
|
|
|
from generators.miniature import generate_miniature
|
2023-05-15 15:35:08 +02:00
|
|
|
from generators.uploader import upload_video
|
2023-05-15 10:11:04 +02:00
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
async def main():
|
2023-05-15 15:35:08 +02:00
|
|
|
if not os.path.exists('videos'): os.makedirs('videos')
|
2023-05-15 11:50:33 +02:00
|
|
|
with open('env/subjects.txt', 'r', encoding='utf-8') as f:
|
|
|
|
|
subjects = f.read().splitlines()
|
|
|
|
|
f.close()
|
|
|
|
|
for i in range(len(subjects)):
|
|
|
|
|
print(str(i) + ". " + subjects[i])
|
|
|
|
|
subject = int(input("Which subject do you want to generate ideas for? (enter the number): "))
|
|
|
|
|
subject = subjects[subject]
|
2023-05-15 15:35:08 +02:00
|
|
|
subjectdirpath = "videos/" + subject[:25].replace(" ", "_").replace(":", "")
|
2023-05-15 16:53:31 +02:00
|
|
|
if not os.path.exists(subjectdirpath):
|
|
|
|
|
os.makedirs(subjectdirpath)
|
|
|
|
|
input("It looks like it is the first time you are generating ideas for this subject. The requiered folder has been created. Press enter to continue.")
|
|
|
|
|
input("Please put all the requiered google credentials files in that folder. Press enter to continue.")
|
|
|
|
|
input("Please put a file called bcg.png in that folder. It will be used as the background of the thumbnails. Press enter to continue.")
|
2023-05-28 11:26:13 +02:00
|
|
|
if input("Do you want to generate new ideas? (y/N): ") == "y":
|
2023-05-15 15:35:08 +02:00
|
|
|
await generate_ideas(subjectdirpath, subject)
|
|
|
|
|
with open(subjectdirpath + '/ideas.json', 'r', encoding='utf-8') as f:
|
2023-05-15 10:11:04 +02:00
|
|
|
ideas = json.load(f)
|
|
|
|
|
f.close()
|
2023-05-28 11:26:13 +02:00
|
|
|
existing = []
|
|
|
|
|
new = []
|
|
|
|
|
for i in ideas:
|
|
|
|
|
if os.path.exists(subjectdirpath + "/" + i['title'][:25].replace(" ", "_").replace(":", "") + "/script.json"):
|
|
|
|
|
existing.append(i)
|
|
|
|
|
else:
|
|
|
|
|
new.append(i)
|
|
|
|
|
print("Existing ideas:")
|
|
|
|
|
for i in range(len(existing)):
|
|
|
|
|
print(str(i) + ". " + existing[i]['title'])
|
|
|
|
|
print("New ideas:")
|
|
|
|
|
for i in range(len(new)):
|
|
|
|
|
print(str(i + len(existing)) + ". " + new[i]['title'])
|
2023-05-15 10:11:04 +02:00
|
|
|
idea = int(input("Which idea do you want to generate a script for? (enter the number): "))
|
2023-05-28 11:26:13 +02:00
|
|
|
if idea < len(existing):
|
|
|
|
|
idea = existing[idea]
|
|
|
|
|
else:
|
|
|
|
|
idea = new[idea - len(existing)]
|
2023-05-15 10:11:04 +02:00
|
|
|
title = idea['title']
|
|
|
|
|
title = title[:25]
|
|
|
|
|
i = 0
|
2023-05-15 11:50:33 +02:00
|
|
|
path = subjectdirpath + "/" + title
|
2023-05-15 10:11:04 +02:00
|
|
|
path = path.replace(" ", "_").replace(":", "")
|
|
|
|
|
if not os.path.exists(path + "/script.json"):
|
|
|
|
|
script = await generate_script(idea['title'], idea['description'])
|
|
|
|
|
if os.path.exists(path) and os.path.exists(path + "/script.json"):
|
|
|
|
|
if input("There is already a script for this idea. Do you want to overwrite it? (y/n)") != "y":
|
|
|
|
|
print("Exiting...")
|
|
|
|
|
exit(1)
|
|
|
|
|
if not os.path.exists(path): os.makedirs(path)
|
|
|
|
|
with open(path + "/script.json", 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(script)
|
|
|
|
|
f.close()
|
|
|
|
|
script = prepare(path)
|
|
|
|
|
credits = mount(path, script)
|
2023-05-15 16:29:22 +02:00
|
|
|
description = f"{idea['description']}\n\nMusic credits: {credits}"
|
2023-05-25 21:47:11 +02:00
|
|
|
if credits != None:
|
|
|
|
|
with open(path + "/meta.txt", 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(description)
|
|
|
|
|
f.close()
|
2023-05-15 10:11:04 +02:00
|
|
|
generate_miniature(path, title=idea['title'], description=idea['description'])
|
2023-05-15 16:29:22 +02:00
|
|
|
upload_video(path, idea['title'], description, 28, "", "private", subjectdirpath)
|
2023-05-15 10:11:04 +02:00
|
|
|
print(f"Your video is ready! You can find it in {path}.")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
asyncio.run(main())
|