🥏 Fixes and auto-upload

pull/632/head
CoasterFreakDE 3 years ago
parent 8d54e373df
commit 5cbd62054d
No known key found for this signature in database
GPG Key ID: 05AC02A2DB97BC3A

@ -4,6 +4,10 @@ REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME=""
REDDIT_PASSWORD=""
TIKTOK_EMAIL=""
TIKTOK_PASSWORD=""
TIKTOK_TAGS="#AskReddit"
# If no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: "no"
RANDOM_THREAD="no"

1
.gitignore vendored

@ -241,3 +241,4 @@ reddit-bot-351418-5560ebc49cac.json
*.pyc
video_creation/data/videos.json
video_creation/data/envvars.txt
video_creation/data/tiktok.cookie

@ -39,7 +39,7 @@ The only original thing being done is the editing and gathering of all materials
## Installation 👩‍💻
1. Clone this repository
2. 2a **Automatic Install**: Run `python main.py` and type 'yes' to activate the setup assistant.
2. 2a **Automatic Install**: Run `python setup.py` and type 'yes' to activate the setup assistant.
2b **Manual Install**: Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication.
@ -89,3 +89,5 @@ HarryDaDev (hrvyy#9677) - https://github.com/ImmaHarry
LukaHietala (Pix.#0001) - https://github.com/LukaHietala
Freebiell (Freebie#6429) - https://github.com/FreebieII
CoasterFreakDE (CoasterFreak | Benni#3306) - https://github.com/CoasterFreakDE (Automatic Upload)

@ -1,3 +1,4 @@
import asyncio
import time
from subprocess import Popen
@ -5,11 +6,12 @@ from dotenv import load_dotenv
from os import getenv, name
from reddit.subreddit import get_subreddit_threads
from utils.cleanup import cleanup
from utils.console import print_markdown, print_step
from utils.console import print_markdown, print_step, print_substep
# from utils.checker import envUpdate
from video_creation.background import download_background, chop_background_video
from video_creation.final_video import make_final_video
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.video_uploader import upload_video_to_tiktok
from video_creation.voices import save_text_to_mp3
VERSION = 2.1
print(
@ -35,6 +37,8 @@ client_secret = getenv("REDDIT_CLIENT_SECRET")
username = getenv("REDDIT_USERNAME")
password = getenv("REDDIT_PASSWORD")
reddit2fa = getenv("REDDIT_2FA")
tiktok_email = getenv("TIKTOK_EMAIL")
tiktok_password = getenv("TIKTOK_PASSWORD")
def main():
@ -50,7 +54,10 @@ def main():
download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background()
chop_background_video(length)
make_final_video(number_of_comments, length)
video_file_name = make_final_video(number_of_comments, length)
loop = asyncio.get_event_loop()
loop.run_until_complete(upload_video_to_tiktok(video_file_name))
loop.close()
def run_many(times):

@ -8,3 +8,6 @@ pytube==12.1.0
requests==2.28.0
rich==12.4.4
sox==1.4.1
selenium
undetected-chromedriver
fake_useragent

@ -18,6 +18,9 @@ def download_background():
Path("./assets/backgrounds/").mkdir(parents=True, exist_ok=True)
background_options = [ # uri , filename , credit
("https://www.youtube.com/watch?v=n_Dv4JMiwK8", "parkour.mp4", "bbswitzer"),
("https://www.youtube.com/watch?v=hf3r9TNSsyY", "sailing.mp4", "loopylongplays"),
("https://www.youtube.com/watch?v=p4jroQX6Hwk", "witcher.mp4", "loopylongplays"),
("https://www.youtube.com/watch?v=c03fwcx1fEQ", "valheim.mp4", "loopylongplays"),
# (
# "https://www.youtube.com/watch?v=2X9QGY__0II",
# "rocket_league.mp4",
@ -50,7 +53,7 @@ def chop_background_video(video_length):
background = VideoFileClip(f"assets/backgrounds/{choice}")
start_time, end_time = get_start_and_end_times(video_length, background.duration)
start_time, end_time = get_start_and_end_times(video_length + 1, background.duration)
ffmpeg_extract_subclip(
f"assets/backgrounds/{choice}",
start_time,

@ -1 +1,58 @@
[]
[
{
"id": "vgeixb",
"time": "1655721481",
"background_credit": "bbswitzer",
"reddit_title": "Whats an opinion you have thats considered unacceptable by societal standards",
"filename": "Whats an opinion you have that....mp4"
},
{
"id": "vg1q2d",
"time": "1655727334",
"background_credit": "loopylongplays",
"reddit_title": "Whats a middle life crisis for people who could never afford a sports car",
"filename": "Whats a middle life crisis for....mp4"
},
{
"id": "vfxpph",
"time": "1655727738",
"background_credit": "bbswitzer",
"reddit_title": "What unimpressive things are people idiotically proud of",
"filename": "What unimpressive things are p....mp4"
},
{
"id": "vfyy54",
"time": "1655728587",
"background_credit": "loopylongplays",
"reddit_title": "What do you find oddly attractive",
"filename": "What do you find oddly attractive.mp4"
},
{
"id": "vg321p",
"time": "1655728930",
"background_credit": "loopylongplays",
"reddit_title": "If you could multiply anything by 10x what would it be",
"filename": "If you could multiply anything....mp4"
},
{
"id": "vg822j",
"time": "1655731883",
"background_credit": "loopylongplays",
"reddit_title": "Whats a job that people really underestimate the importance of",
"filename": "Whats a job that people really....mp4"
},
{
"id": "vgj2ie",
"time": "1655744382",
"background_credit": "loopylongplays",
"reddit_title": "What is the thing you never imagined youd be able to do it until you did it",
"filename": "What is the thing you never im....mp4"
},
{
"id": "vgmldg",
"time": "1655744683",
"background_credit": "loopylongplays",
"reddit_title": "How does someone politely end a conversation with a person who wont stop talking",
"filename": "How does someone politely end ....mp4"
}
]

@ -148,3 +148,4 @@ def make_final_video(number_of_clips, length):
print_step(
f"Reddit title: {os.getenv('VIDEO_TITLE')} \n Background Credit: {os.getenv('background_credit')}"
)
return filename

@ -0,0 +1,76 @@
from asyncio import sleep
import asyncio
import json
from os import getenv
import os
from pathlib import Path
import pickle
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import selenium.common
from playwright.async_api import async_playwright
import undetected_chromedriver.v2 as uc
from fake_useragent import UserAgent, FakeUserAgentError
from utils.console import print_step, print_substep
import json
from rich.console import Console
console = Console()
storymode = False
async def upload_video_to_tiktok(videofile):
"""Uploads the video to tiktok.
Args:
videofile: The video file you want to upload inside of /results.
"""
print_step("Uploading video to tiktok...")
# ! Make sure the reddit screenshots folder exists
Path("results").mkdir(parents=True, exist_ok=True)
async with async_playwright() as p:
print_substep("Launching Headless Browser...")
options = uc.ChromeOptions()
options.add_argument("--user-agent=" + UserAgent().random)
options.add_argument("--headless")
browser = uc.Chrome(options=options)
browser.delete_all_cookies()
# Get the thread screenshot
browser.get("https://www.tiktok.com/login")
await asyncio.sleep(3)
cookie_file = open("./video_creation/data/tiktok.cookie", "rb")
cookie_data = pickle.load(cookie_file)
for cookie in cookie_data:
if 'sameSite' in cookie:
if cookie['sameSite'] == 'None':
cookie['sameSite'] = 'Strict'
browser.add_cookie(cookie)
browser.refresh()
await asyncio.sleep(3)
print_substep("Logged in...")
browser.get('https://www.tiktok.com/upload')
await asyncio.sleep(5)
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.TAG_NAME, "iframe")))
abs_path = os.path.join(os.getcwd(), f'results/{videofile}')
browser.switch_to.frame(0)
browser.implicitly_wait(1)
browser.find_elements(By.XPATH, '//*[@id="root"]/div/div/div/div/div[2]/div[1]/div/input')[0].send_keys(abs_path)
print_substep("Uploading video...")
await asyncio.sleep(10)
browser.find_elements(By.XPATH, '//*[@id="root"]/div/div/div/div/div[2]/div[2]/div[7]/div[2]/button')[0].click()
await asyncio.sleep(5)
print_substep("Video uploaded Successfully.", style="bold green")
Loading…
Cancel
Save