made uploading more dynamic

pull/1310/head
streetRAT 4 years ago
parent 6d07e36944
commit d30d715e6c

1
.gitignore vendored

@ -247,3 +247,4 @@ video_creation/data/videos.json
results/client_secrets.json results/client_secrets.json
results/client_secrets.json.template results/client_secrets.json.template
results/upload_video.py-oauth2.json results/upload_video.py-oauth2.json
results/*/*.mp4

@ -0,0 +1,13 @@
import urllib.request
def connect(host="http://google.com"):
try:
urllib.request.urlopen(host) # Python 3.x
return True
except:
return False
# test
print("connected" if connect() else "no internet!")

@ -179,10 +179,6 @@ def updateUploadedStatus(currIndex, time):
with open("..\\video_creation\\data\\videos.json", "w") as outfile: with open("..\\video_creation\\data\\videos.json", "w") as outfile:
outfile.write(json_obj) outfile.write(json_obj)
# print(datetime.datetime.now().isoformat())
# print(video_data[i - 1])
# print(video_data[i])
if __name__ == "__main__": if __name__ == "__main__":
@ -190,44 +186,42 @@ if __name__ == "__main__":
f = open("..\\video_creation\\data\\videos.json") f = open("..\\video_creation\\data\\videos.json")
# loads videos.json into a dictionary # loads videos.json into a dictionary
video_data = json.load(f) video_data = json.load(f)
descriptionBeginning = "r/askReddit | "
descriptionEnd = " 🔔 Hit the bell next to Subscribe so you never miss a video! ❤️ Like and Comment 🧍 Subscribe if you are new on the channel!"
# reddit​ #redditstories​ #askreddit​ #shorts​
titlebBeggining = "r/askReddit: " # 13 characters
options = {} options = {}
uploaded = 0 uploaded = 0
for i, video in enumerate(video_data): for i, video in enumerate(video_data):
if video["uploaded"] == False: if video["uploaded"] == False:
if uploaded < 2: if uploaded < 6:
prev_video = list(video_data)[i - 1] prev_video = list(video_data)[i - 1]
############# 2022-10-19 16:39:46.887878 ############# 2022-10-19 16:39:46.887878
format_data = "%Y-%m-%d %H:%M:%S" format_data = "%Y-%m-%d %H:%M:%S"
# print("prev_video", prev_video)
# print("video", video)
next_upload = datetime.strptime( next_upload = datetime.strptime(
prev_video["uploaded_at"], format_data prev_video["uploaded_at"], format_data
) + timedelta(hours=4) ) + timedelta(hours=4)
# print(next_upload) file_name = video["subreddit"] + "/" + video["filename"]
titleEnding = "..." title = "r/" + video["subreddit"] + " : " + video["reddit_title"]
if len(video["reddit_title"]) < 84: description = (
titleEnding = "?" "r/"
# print(len(video["reddit_title"])) + video["subreddit"]
+ " | "
+ video["reddit_title"]
+ "?"
+ " 🔔 Hit the bell next to Subscribe so you never miss a video! ❤️ Like and Comment 🧍 Subscribe if you are new on the channel!"
)
if len(title) >= 99:
title = title[0:96] + "..."
if len(title) <= 99:
title = title + "?"
options = { options = {
"file": video["filename"], "file": file_name,
"title": titlebBeggining "title": title,
+ video["reddit_title"][0:84] "description": description,
+ titleEnding,
"description": descriptionBeginning
+ video["reddit_title"]
+ descriptionEnd,
"category": "22", "category": "22",
"keywords": "reddit,shorts,askReddit", "keywords": "reddit,shorts,askReddit",
"privacyStatus": "private", "privacyStatus": "private",
"publishTime": next_upload.isoformat() "publishTime": next_upload.isoformat(),
# June 19th, 2022 at 8:20 AM
} }
args = argparser.parse_args() args = argparser.parse_args()
@ -236,14 +230,14 @@ if __name__ == "__main__":
print(options["file"]) print(options["file"])
exit("Please specify a valid file using the --file= parameter ") exit("Please specify a valid file using the --file= parameter ")
youtube = get_authenticated_service( youtube = get_authenticated_service(args)
args
) # args must be a new implementation of args object
try: try:
initialize_upload(youtube, options, i, next_upload) print(options)
# initialize_upload(youtube, options, i, next_upload)
uploaded += 1 uploaded += 1
print(options["title"]) # print(options["file"])
video["uploaded_at"] = next_upload.strftime(format_data) # print(options["title"])
# video["uploaded_at"] = next_upload.strftime(format_data)
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))

@ -45,7 +45,9 @@ def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int
def get_background_config(): def get_background_config():
"""Fetch the background/s configuration""" """Fetch the background/s configuration"""
try: try:
choice = str(settings.config["settings"]["background"]["background_choice"]).casefold() choice = str(
settings.config["settings"]["background"]["background_choice"]
).casefold()
except AttributeError: except AttributeError:
print_substep("No background selected. Picking random background'") print_substep("No background selected. Picking random background'")
choice = None choice = None
@ -54,7 +56,7 @@ def get_background_config():
# Default : pick random from supported background. # Default : pick random from supported background.
if not choice or choice not in background_options: if not choice or choice not in background_options:
choice = random.choice(list(background_options.keys())) choice = random.choice(list(background_options.keys()))
print(background_options[choice])
return background_options[choice] return background_options[choice]
@ -65,16 +67,20 @@ def download_background(background_config: Tuple[str, str, str, Any]):
uri, filename, credit, _ = background_config uri, filename, credit, _ = background_config
if Path(f"assets/backgrounds/{credit}-{filename}").is_file(): if Path(f"assets/backgrounds/{credit}-{filename}").is_file():
return return
print_step("We need to download the backgrounds videos. they are fairly large but it's only done once. 😎") print_step(
"We need to download the backgrounds videos. they are fairly large but it's only done once. 😎"
)
print_substep("Downloading the backgrounds videos... please be patient 🙏 ") print_substep("Downloading the backgrounds videos... please be patient 🙏 ")
print_substep(f"Downloading {filename} from {uri}") print_substep(f"Downloading {filename} from {uri}")
YouTube(uri, on_progress_callback=on_progress).streams.filter(res="1080p").first().download( YouTube(uri, on_progress_callback=on_progress).streams.filter(
"assets/backgrounds", filename=f"{credit}-{filename}" res="1080p"
) ).first().download("assets/backgrounds", filename=f"{credit}-{filename}")
print_substep("Background video downloaded successfully! 🎉", style="bold green") print_substep("Background video downloaded successfully! 🎉", style="bold green")
def chop_background_video(background_config: Tuple[str, str, str, Any], video_length: int, reddit_object: dict): def chop_background_video(
background_config: Tuple[str, str, str, Any], video_length: int, reddit_object: dict
):
"""Generates the background footage to be used in the video and writes it to assets/temp/background.mp4 """Generates the background footage to be used in the video and writes it to assets/temp/background.mp4
Args: Args:

@ -1 +1,179 @@
[] [
{
"id": "vog11p1",
"time": "1656620935",
"background_credit": "streetRAT",
"reddit_title": "People who are always late why dont you just leave earlier",
"filename": "People who are always late why dont you just leave earlier.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 00:39:46"
},
{
"subreddit": "AskReddit",
"id": "y8tz9q",
"time": "1666277840",
"background_credit": "bbswitzer",
"reddit_title": "What video game is an absolute 100% in your opinion",
"filename": "What video game is an absolute 100% in your opinion.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 04:39:46"
},
{
"subreddit": "AskReddit",
"id": "y89srw",
"time": "1666278430",
"background_credit": "bbswitzer",
"reddit_title": "What is some dark shit going on around the world right now that the public probably doesnt know about",
"filename": "What is some dark shit going on around the world right now that the public probably doesnt know about.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 08:39:46"
},
{
"subreddit": "AskReddit",
"id": "y8td31",
"time": "1666279106",
"background_credit": "bbswitzer",
"reddit_title": "What animated movie would you confidently say is a 1010 masterpiece",
"filename": "What animated movie would you confidently say is a 1010 masterpiece.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 10:00:00"
},
{
"subreddit": "AskReddit",
"id": "y8w042",
"time": "1666279715",
"background_credit": "bbswitzer",
"reddit_title": "People who are always late why dont you just leave earlier",
"filename": "People who are always late why dont you just leave earlier.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 14:00:00"
},
{
"subreddit": "AskReddit",
"id": "y88k7h",
"time": "1666280396",
"background_credit": "bbswitzer",
"reddit_title": "What vehicle is only driven by assholes",
"filename": "What vehicle is only driven by assholes.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 18:00:00"
},
{
"subreddit": "AskReddit",
"id": "y8wqb9",
"time": "1666307142",
"background_credit": "bbswitzer",
"reddit_title": "What is one thing ALL men agree to",
"filename": "What is one thing ALL men agree to.mp4",
"uploaded": true,
"uploaded_at": "2022-10-21 22:00:00"
},
{
"subreddit": "AskReddit",
"id": "y9a0xg",
"time": "1666342174",
"background_credit": "bbswitzer",
"reddit_title": "What is something debunked as propaganda that is still widely believed",
"filename": "What is something debunked as propaganda that is still widely believed.mp4",
"uploaded": true,
"uploaded_at": "2022-10-22 02:00:00"
},
{
"subreddit": "AskReddit",
"id": "y8xtse",
"time": "1666342717",
"background_credit": "bbswitzer",
"reddit_title": "People who married their better than nothing option hows your marriage going",
"filename": "People who married their better than nothing option hows your marriage going.mp4",
"uploaded": true,
"uploaded_at": "2022-10-22 06:00:00"
},
{
"subreddit": "AskReddit",
"id": "y95slv",
"time": "1666347990",
"background_credit": "bbswitzer",
"reddit_title": "What happened to the smartest kid at your high school",
"filename": "What happened to the smartest kid at your high school.mp4",
"uploaded": true,
"uploaded_at": "2022-10-22 10:00:00"
},
{
"subreddit": "AskReddit",
"id": "y9f5hj",
"time": "1666348676",
"background_credit": "bbswitzer",
"reddit_title": "What is the dumbest idea you had as a child that sounded completely reasonable to your child brain",
"filename": "What is the dumbest idea you had as a child that sounded completely reasonable to your child brain.mp4",
"uploaded": true,
"uploaded_at": "2022-10-22 14:00:00"
},
{
"subreddit": "AskReddit",
"id": "y93z8l",
"time": "1666349338",
"background_credit": "bbswitzer",
"reddit_title": "Which snacks do you avoid buying because you will literally eat the entire batch in one sitting",
"filename": "Which snacks do you avoid buying because you will literally eat the entire batch in one sitting.mp4",
"uploaded": true,
"uploaded_at": "2022-10-22 18:00:00"
},
{
"subreddit": "AskReddit",
"id": "y9oqp8",
"time": "1666359438",
"background_credit": "bbswitzer",
"reddit_title": "How do you feel about men who spend money on escortsprostitutesstrippers Do you look down on them",
"filename": "How do you feel about men who spend money on escortsprostitutesstrippers Do you look down on them.mp4",
"uploaded": true,
"uploaded_at": "2022-10-22 22:00:00"
},
{
"subreddit": "AskReddit",
"id": "y9rj5c",
"time": "1666360170",
"background_credit": "bbswitzer",
"reddit_title": "What is a conspiracy theory that you actually believe",
"filename": "What is a conspiracy theory that you actually believe.mp4",
"uploaded": true,
"uploaded_at": "2022-10-23 02:00:00"
},
{
"subreddit": "AskReddit",
"id": "y9qbi2",
"time": "1666360704",
"background_credit": "bbswitzer",
"reddit_title": "What would you do if your mother started an OnlyFans",
"filename": "What would you do if your mother started an OnlyFans.mp4",
"uploaded": true,
"uploaded_at": "2022-10-23 06:00:00"
},
{
"subreddit": "AskReddit",
"id": "y9q6y7",
"time": "1666361383",
"background_credit": "bbswitzer",
"reddit_title": "Whats something a lot of people see as hot or sexual but doesnt do anything for you",
"filename": "Whats something a lot of people see as hot or sexual but doesnt do anything for you.mp4",
"uploaded": true,
"uploaded_at": "2022-10-23 10:00:00"
},
{
"subreddit": "AskReddit",
"id": "yabrxc",
"time": "1666426085",
"background_credit": "bbswitzer",
"reddit_title": "Whats a subtle sign of low intelligence",
"filename": "Whats a subtle sign of low intelligence.mp4",
"uploaded": false
},
{
"subreddit": "AskReddit",
"id": "ya9vju",
"time": "1666426754",
"background_credit": "bbswitzer",
"reddit_title": "Pretend as of reading this post a meteor is an hour away from hitting the earth what was your last meal without realizing it",
"filename": "Pretend as of reading this post a meteor is an hour away from hitting the earth what was your last meal without realizing it.mp4",
"uploaded": false
}
]
Loading…
Cancel
Save