- Video title, description & tags generation. - Automating video upload to youtubepull/2058/head
parent
50935a5d28
commit
98aaffd865
@ -0,0 +1,36 @@
|
||||
from simple_youtube_api.Channel import Channel
|
||||
from simple_youtube_api.LocalVideo import LocalVideo
|
||||
|
||||
from video_data_generation import gemini
|
||||
|
||||
|
||||
# logging into the channel
|
||||
channel = Channel()
|
||||
channel.login("./utils/client_secret.json", "./utils/credentials.storage")
|
||||
|
||||
def upload_video_to_youtube(video_path, data, thumbnail):
|
||||
# setting up the video that is going to be uploaded
|
||||
video = LocalVideo(file_path=video_path)
|
||||
|
||||
# setting snippet
|
||||
video.set_title(data['title'])
|
||||
video.set_description(data["description"])
|
||||
tags = data["tags"].split(', ')
|
||||
if len(tags) == 1: tags = tags[0].split(',')
|
||||
video.set_tags(tags)
|
||||
# video.set_category("gaming")
|
||||
video.set_default_language("en-US")
|
||||
|
||||
# setting status
|
||||
video.set_embeddable(True)
|
||||
video.set_license("youtube")
|
||||
video.set_privacy_status("public")
|
||||
video.set_public_stats_viewable(True)
|
||||
|
||||
# setting thumbnail
|
||||
if thumbnail is not None: video.set_thumbnail_path(thumbnail)
|
||||
|
||||
# uploading video and printing the results
|
||||
video = channel.upload_video(video)
|
||||
print(video.id)
|
||||
print(video)
|
@ -0,0 +1,76 @@
|
||||
import json
|
||||
import google.generativeai as genai
|
||||
from utils import settings
|
||||
|
||||
|
||||
genai.configure(api_key=settings.config["settings"]["gemini"]["gemini_api_key"])
|
||||
|
||||
prompt1 = """I make some youtube videos where I get subreddits about ghost stories and make a video of it.
|
||||
I will send a post to you and you should generate a YouTube video title, tags and description for it.
|
||||
Only respond with the following:
|
||||
title::: "The video title"
|
||||
description::: "The video description"
|
||||
tags::: "The video tags" without hashtags and separated by commas
|
||||
|
||||
Here is the post:
|
||||
"""
|
||||
|
||||
prompt2 = """Describe a thumbnail for a youtube video about ghosts and ghost stories.
|
||||
Only respond with the thumbnail description.
|
||||
The description should be clear for an AI image generator model to generate it.
|
||||
|
||||
The video tags are:
|
||||
"""
|
||||
|
||||
model = genai.GenerativeModel('gemini-pro')
|
||||
|
||||
def get_data(post):
|
||||
response = model.generate_content(prompt1 + post)
|
||||
|
||||
text = response.text.split('\n')
|
||||
data = {i.split(':::')[0].strip(): i.split(':::')[1].strip() for i in text}
|
||||
return data
|
||||
|
||||
def get_thumbnail(post):
|
||||
thumbnail_response = model.generate_content(prompt2+post)
|
||||
return thumbnail_response.text
|
||||
|
||||
def get_video_data(post):
|
||||
data = None
|
||||
thumbnail = None
|
||||
print("Generating video title & description...")
|
||||
for i in range(2):
|
||||
if i != 0: print("Try:", i+1)
|
||||
try:
|
||||
if data is None: data = get_data(post)
|
||||
if data and thumbnail is None:
|
||||
thumbnail = get_thumbnail(data['tags'])
|
||||
break
|
||||
except Exception as e:
|
||||
# print(e)
|
||||
continue
|
||||
return data, thumbnail
|
||||
|
||||
if __name__ == '__main__':
|
||||
post = """
|
||||
|
||||
This is my dads story. With all of the weirdest things that have happened, this one takes the cake.
|
||||
|
||||
My dad doesn't really speak of many paranormal experiences. This one freaked him out enough though, that he told me. One night, he went to bed with my mom and their dogs. My dad falls asleep pretty fast but for some reason that night, he couldn't.
|
||||
|
||||
Some background info: My parents at the time had two cats, Sweetpea and Baby Princess( my sister named her when she was 6) Their cats would sometimss go into their room when they were sleeping. My parents always slept with their door open(I could never, creeps me out). Their room is the first room when you would reach the top of the steps.
|
||||
|
||||
Anyways, my dad was laying in bed tossing and turning. He flipped on his back and closed his eyes. When he was laying there, he felt a pressure going up his legs. He figured the cats were walking up his legs. He then realized the pressure was going up his legs and ended up to his chest. He couldn't move a muscle. That's when he started to choke. His eyes popped open and he looked over and there was a figure standing over him with his hands around my dads throat.
|
||||
|
||||
According to my dad, the figure had a black WW2 Nazi uniform on with the black uniform hat that had a swastika on it. The choking lasted for some time until my dad told it to get the fuck off of him, then it disappeared. My dad was freaked out. He got up and checked inside all of our bedrooms and throughout the house but couldn't find anyone anywhere. Everyone was asleep.
|
||||
|
||||
I asked my dad why he thought the Nazi was choking him. He said he wasn't sure why, maybe he was an old angry relative. My grandma grew up in Germany through the war and my grandmas dad was a Nazi. So to say the least, we had some relatives that were in the war. I'm not sure why this ghost attacked my dad, maybe because he was the strongest in the house? Who knows.
|
||||
|
||||
My dad isn't one to make up stories like this, so I believe him. He's a very strong and brave man, and it takes a lot for him to get scared. He told me that this really got to him and that he was scared for us and this is why he got up and searched throughout the house. Usually, if paranormal things happen, he doesn't say much because he didn't want to scare us when we were kids.
|
||||
|
||||
I know that some of you might think that he had sleep paralysis when this happened, but my dad did not suffer from this. He told me that this was the first and only time that he couldn't move like this.
|
||||
|
||||
Thank you for reading! Let me know what you guys think :)
|
||||
"""
|
||||
for i in get_video_data(post):
|
||||
print(i, end="\n\n")
|
@ -0,0 +1,66 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
s = requests.session()
|
||||
|
||||
def renew_connection():
|
||||
csrf_url = "https://image.plus/"
|
||||
payload = {}
|
||||
|
||||
csrf_headers = {
|
||||
'Host': 'image.plus',
|
||||
'Sec-Ch-Ua': '"Chromium";v="121", "Not A(Brand";v="99"',
|
||||
'Sec-Ch-Ua-Mobile': '?0',
|
||||
'Sec-Ch-Ua-Platform': '"Windows"',
|
||||
'Upgrade-Insecure-Requests': '1',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.160 Safari/537.36',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
'Sec-Fetch-Site': 'none',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-User': '?1',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept-Language': 'en-US,en;q=0.9',
|
||||
'Priority': 'u=0, i',
|
||||
'Connection': 'close'
|
||||
}
|
||||
|
||||
s.cookies.clear()
|
||||
response = s.request("GET", csrf_url, headers=csrf_headers)
|
||||
print(response.status_code)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
return soup.find("meta", {"name":"csrf-token"})['content']
|
||||
|
||||
|
||||
def generate_image(csrf_token, prompt=None):
|
||||
url = "https://image.plus/images/generate"
|
||||
|
||||
prompt = "A ghost flying with a person sitting scared on a couch."
|
||||
payload = f"prompt={prompt.replace(' ', '+')}&negative_prompt=&model=1&style=cinematic&samples=1&size=1152x896"
|
||||
headers = {
|
||||
'Host': 'image.plus',
|
||||
'Content-Length': '106',
|
||||
'Sec-Ch-Ua': '"Chromium";v="121", "Not A(Brand";v="99"',
|
||||
'Sec-Ch-Ua-Mobile': '?0',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.160 Safari/537.36',
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Sec-Ch-Ua-Platform': '"Windows"',
|
||||
'Origin': 'https://image.plus',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Referer': 'https://image.plus/',
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept-Language': 'en-US,en;q=0.9',
|
||||
'Priority': 'u=1, i',
|
||||
'X-Csrf-Token': csrf_token,
|
||||
}
|
||||
|
||||
response = s.request("POST", url, headers=headers, data=payload)
|
||||
return response.json()
|
||||
|
||||
image = generate_image(renew_connection())
|
||||
print(image)
|
Loading…
Reference in new issue