Added and fixed a whole bunch of things

This commit is contained in:
Paillat
2023-05-15 15:35:08 +02:00
parent 393600ad94
commit da257e7b39
9 changed files with 69 additions and 41 deletions

BIN
bcg.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 514 KiB

View File

@@ -5,18 +5,23 @@ from dotenv import load_dotenv
load_dotenv() load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY") openai.api_key = os.getenv("OPENAI_API_KEY")
subject = os.getenv("SUBJECT")
with open('prompts/ideas.txt') as f: with open('prompts/ideas.txt') as f:
prompt = f.read().replace('[subject]', subject) prompt = f.read()
f.close() f.close()
async def generate_ideas(path): async def generate_ideas(path, subject):
with open(f'{path}/ideas.json', 'r') as f: prmpt = prompt.replace('[subject]', subject)
ideas = f.read() try:
ides_json = json.loads(ideas) with open(f'{path}/ideas.json', 'r') as f:
f.close() ideas = f.read()
prmpt = prompt.replace('[existing ideas]', ideas) ides_json = json.loads(ideas)
f.close()
except:
ides_json = []
ideas = "There are no existing ideas."
prmpt = prmpt.replace('[existing ideas]', ideas)
print(prmpt)
response = await openai.ChatCompletion.acreate( response = await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo", model="gpt-3.5-turbo",
messages=[ messages=[

View File

@@ -61,7 +61,15 @@ def generate_miniature(path, title, description):
generate_image(path, text1, text2) generate_image(path, text1, text2)
def generate_image(path, text1, text2): def generate_image(path, text1, text2):
bcg = Image.open("bcg.png") path_to_bcg = path.split("/")[:-1]
path_to_bcg = "/".join(path_to_bcg)
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)
if not os.path.exists(f"{path_to_bcg}/bcg.png"):
input("bcg.png still not found. Exiting.")
exit()
bcg = Image.open(f"{path_to_bcg}/bcg.png")
img = Image.new('RGBA', (1920, 1080)) img = Image.new('RGBA', (1920, 1080))
img, textcolor1, textcolor2 = rand_gradient(img) img, textcolor1, textcolor2 = rand_gradient(img)
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
@@ -108,5 +116,3 @@ def generate_image(path, text1, text2):
img.paste(imgtext2, (0, 0), imgtext2) img.paste(imgtext2, (0, 0), imgtext2)
img.save(path + "/miniature.png") img.save(path + "/miniature.png")
return path + "/miniature.png" return path + "/miniature.png"
generate_image("test", "Master python loops", "Effortlessly")

View File

@@ -28,7 +28,8 @@ RETRIABLE_STATUS_CODES = [500, 502, 503, 504]
CLIENT_SECRETS_FILE = 'env/client_secret.json' CLIENT_SECRETS_FILE = 'env/client_secret.json'
SCOPES = ['https://www.googleapis.com/auth/youtube.upload', 'POST https://www.googleapis.com/upload/youtube/v3/thumbnails/set', 'https://www.googleapis.com/auth/youtube.force-ssl'] #SCOPES = ['https://www.googleapis.com/auth/youtube.upload', 'https://www.googleapis.com/upload/youtube/v3/thumbnails/set', 'https://www.googleapis.com/auth/youtube.force-ssl']
SCOPES = ['https://www.googleapis.com/auth/youtube']
API_SERVICE_NAME = 'youtube' API_SERVICE_NAME = 'youtube'
API_VERSION = 'v3' API_VERSION = 'v3'
@@ -36,9 +37,9 @@ VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
# Authorize the request and store authorization credentials. # Authorize the request and store authorization credentials.
def get_authenticated_service(): def get_authenticated_service(credentialsPath=""):
if os.path.exists('env/credentials.json'): if os.path.exists(f'{credentialsPath}/credentials.json'):
with open('env/credentials.json') as json_file: with open(f'{credentialsPath}/credentials.json') as json_file:
data = json.load(json_file) data = json.load(json_file)
credentials = google.oauth2.credentials.Credentials( credentials = google.oauth2.credentials.Credentials(
token=data['token'], token=data['token'],
@@ -52,7 +53,7 @@ def get_authenticated_service():
flow = InstalledAppFlow.from_client_secrets_file( flow = InstalledAppFlow.from_client_secrets_file(
CLIENT_SECRETS_FILE, SCOPES) CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_local_server() credentials = flow.run_local_server()
with open('env/credentials.json', 'w') as outfile: with open(f'{credentialsPath}/credentials.json', 'w') as outfile:
outfile.write(credentials.to_json()) outfile.write(credentials.to_json())
return build(API_SERVICE_NAME, API_VERSION, credentials=credentials) return build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
@@ -67,10 +68,12 @@ def initialize_upload(youtube, options):
title=options['title'], title=options['title'],
description=options['description'], description=options['description'],
tags=tags, tags=tags,
categoryId=options['category'] categoryId=options['category'],
defaultLanguage='en'
), ),
status=dict( status=dict(
privacyStatus=options['privacyStatus'] privacyStatus=options['privacyStatus'],
selfDeclaredMadeForKids=False
) )
) )
@@ -81,7 +84,8 @@ def initialize_upload(youtube, options):
media_body=MediaFileUpload(options['file'], chunksize=-1, resumable=True) media_body=MediaFileUpload(options['file'], chunksize=-1, resumable=True)
) )
resumable_upload(insert_request) videoid = resumable_upload(insert_request)
return videoid
def resumable_upload(request): def resumable_upload(request):
@@ -96,6 +100,7 @@ def resumable_upload(request):
if 'id' in response: if 'id' in response:
print('Video id "%s" was successfully uploaded.' % print('Video id "%s" was successfully uploaded.' %
response['id']) response['id'])
return response['id']
else: else:
exit('The upload failed with an unexpected response: %s' % response) exit('The upload failed with an unexpected response: %s' % response)
except HttpError as e: except HttpError as e:
@@ -118,20 +123,25 @@ def resumable_upload(request):
print('Sleeping %f seconds and then retrying...' % sleep_seconds) print('Sleeping %f seconds and then retrying...' % sleep_seconds)
time.sleep(sleep_seconds) time.sleep(sleep_seconds)
def upload_video(path, title, description, category, keywords, privacyStatus='private', credentials_path=""):
if __name__ == '__main__': options = {
sample_options = { 'file': path +"/montage.mp4",
'file': './test.mp4', 'title': title,
'title': 'Test Title', 'description': description,
'description': 'Test Description', 'category': category,
'category': 22, 'keywords': keywords,
'keywords': 'test, video', 'privacyStatus': privacyStatus
'privacyStatus': 'private'
} }
youtube = get_authenticated_service(credentials_path)
youtube = get_authenticated_service()
try: try:
initialize_upload(youtube, sample_options) videoid = initialize_upload(youtube, options)
except HttpError as e: except HttpError as e:
print('An HTTP error %d occurred:\n%s' % (e.resp.status, e.content)) print('An HTTP error %d occurred:\n%s' % (e.resp.status, e.content))
upload_thumbnail(videoid, path + "/miniature.png", credentials_path)
def upload_thumbnail(video_id, file, credentials_path=""):
youtube = get_authenticated_service(credentials_path)
youtube.thumbnails().set(
videoId=video_id,
media_body=file
).execute()

View File

@@ -7,10 +7,12 @@ from generators.ideas import generate_ideas
from generators.script import generate_script from generators.script import generate_script
from generators.montage import mount, prepare, translate from generators.montage import mount, prepare, translate
from generators.miniature import generate_miniature from generators.miniature import generate_miniature
from generators.uploader import upload_video
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
async def main(): async def main():
if not os.path.exists('videos'): os.makedirs('videos')
with open('env/subjects.txt', 'r', encoding='utf-8') as f: with open('env/subjects.txt', 'r', encoding='utf-8') as f:
subjects = f.read().splitlines() subjects = f.read().splitlines()
f.close() f.close()
@@ -18,11 +20,11 @@ async def main():
print(str(i) + ". " + subjects[i]) print(str(i) + ". " + subjects[i])
subject = int(input("Which subject do you want to generate ideas for? (enter the number): ")) subject = int(input("Which subject do you want to generate ideas for? (enter the number): "))
subject = subjects[subject] subject = subjects[subject]
subjectdirpath = subject[:25].replace(" ", "_").replace(":", "") subjectdirpath = "videos/" + subject[:25].replace(" ", "_").replace(":", "")
if not os.path.exists(subjectdirpath): os.makedirs(subjectdirpath) if not os.path.exists(subjectdirpath): os.makedirs(subjectdirpath)
if input("Do you want to generate new ideas? (y/n)") == "y": if input("Do you want to generate new ideas? (y/n)") == "y":
await generate_ideas(subjectdirpath) await generate_ideas(subjectdirpath, subject)
with open('ideas/ideas.json', 'r', encoding='utf-8') as f: with open(subjectdirpath + '/ideas.json', 'r', encoding='utf-8') as f:
ideas = json.load(f) ideas = json.load(f)
f.close() f.close()
for i in range(len(ideas)): for i in range(len(ideas)):
@@ -55,6 +57,7 @@ async def main():
f.write(f"Titre: {transtitle}\nDescription: {transdesc}\nCrédits musicaux: {credits}") f.write(f"Titre: {transtitle}\nDescription: {transdesc}\nCrédits musicaux: {credits}")
f.close() f.close()
generate_miniature(path, title=idea['title'], description=idea['description']) generate_miniature(path, title=idea['title'], description=idea['description'])
upload_video(path, idea['title'], idea['description'], 28, "", "private", subjectdirpath)
print(f"Your video is ready! You can find it in {path}.") print(f"Your video is ready! You can find it in {path}.")
if __name__ == "__main__": if __name__ == "__main__":

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 331 KiB

View File

@@ -6,12 +6,12 @@ Here is an example of the output:
``` ```
[ [
{ {
"title": "Python Tutorial for Beginners", "title": "TITLE OF THE VIDEO",
"description": "A video for beginners to learn Python. The following topics are covered: variables, data types, functions, classes, and more." "description": "A video about something. Concept1 and concept2 are explained. Concept3 is also explained a bit."
}, },
{ {
"title": "DRAMA: MrBeast did WHAT?!", "title": "TITLE OF THE VIDEO",
"description": "MrBeast did something crazy. You won't believe what he did. Watch the video to find out." "description": "A video about something. Concept1 and concept2 are explained. Concept3 is also explained a bit."
} }
] ]
``` ```

View File

@@ -27,6 +27,10 @@ Your video will be detailed, long and very complete. Here is an example:
{ {
"spoken":"This is a latex formula wich is very important. It is the formula of the integral of x squared from 0 to infinity. You can see it on the screen.", "spoken":"This is a latex formula wich is very important. It is the formula of the integral of x squared from 0 to infinity. You can see it on the screen.",
"markdown":"$$\n\\int_0^\\infty x^2 dx\n$$" "markdown":"$$\n\\int_0^\\infty x^2 dx\n$$"
},
{
"spoken":"tHanks for watching this video. If you liked it, please like, share and subscribe. See you in the next video.",
"image":"thanks+goodbye"
} }
] ]