-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScorchAI.py
112 lines (94 loc) · 4.18 KB
/
ScorchAI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import Youtube
import Twitch
import argparse
import os
import shutil
import API.TwitchAPI as TwitchAPI
VERSION = 3.1
prog = "scorchai"
CLIPS_FOLDER = './videos/clips/'
PREP_STAGE = './videos/prepstage/'
READY_STAGE = './videos/ready_to_upload/'
UPLOADED_STAGE = './videos/uploaded_clips/'
parser = argparse.ArgumentParser(prog=prog, description='Uses scorchai to process videos')
parser.add_argument('-g', '--generate', action='store_true', help='Generate when no clip is found, doesnt do anything on its own')
parser.add_argument('-u', '--upload', action='store_true', help='Upload clip')
parser.add_argument('-s', '--short', action='store_true', help='Make shorts')
parser.add_argument('-c', '--compile', type=int, help='Compile clips', default=0)
parser.add_argument('-ch', '--channel', type=str, default="Default")
parser.add_argument('-i', '--id', type=str)
parser.add_argument('-v', '--version', action='version', version=f'{prog} {VERSION}')
args = parser.parse_args()
def runAI():
channel = args.channel
if not doesChannelExist(channel):
print("Channel does not exist. Making a new one!")
shutil.copytree(f"./assets/Channels/Default", f"./assets/Channels/{channel}")
print("Please edit your files how you want it and click on enter!")
input()
if args.id:
print(TwitchAPI.getChannelID(args.id))
exit()
cleanFolder(CLIPS_FOLDER)
cleanFolder(PREP_STAGE)
cleanFolder(UPLOADED_STAGE)
compile(args.compile)
if args.short:
if getVideoReadyAmount() < 1: Twitch.generateClips(1, channel)
vid = getNextVideo()
shutil.move(READY_STAGE+vid, PREP_STAGE+vid)
os.system(f'ffmpeg -i {PREP_STAGE+vid} -vf "pad=iw:2*trunc(iw*16/18):(ow-iw)/2:(oh-ih)/2,setsar=1" -c:a copy {READY_STAGE+vid}')
if args.upload:
Youtube.uploadClip(args.generate, channel)
def compile(compileAmount):
if compileAmount > 0:
setupCompile(compileAmount)
os.system("ffmpeg -y -f concat -safe 0 -i {PREP_STAGE}input.txt -c copy {UPLOADED_STAGE}output.mp4")
uploadCompilation()
afterCompile()
def afterCompile():
cleanFolder(CLIPS_FOLDER)
cleanFolder(PREP_STAGE)
def uploadCompilation():
video = "{UPLOADED_STAGE}output.mp4"
title = generateCompilationTitle()
tags = ""
description = "ScorchAI Compilation! \n\nEXPAND ME\n\n "
bcs = []
for path, subdirs, files in os.walk(PREP_STAGE):
for filename in files:
if filename.endswith(".mp4"):
clipID = filename.split(".mp4")[0]
bcs.append(Youtube.getBroadcaster(clipID))
bcs = list(dict.fromkeys(bcs))
for bc in bcs:
description += f"Watch {bc} on https://www.twitch.tv/{bc} \n"
with open("./assets/description.txt", encoding="utf8") as file:
description += file.read()
Youtube.uploadVideo(video, title, description, tags)
def generateCompilationTitle():
bcs = []
for path, subdirs, files in os.walk(PREP_STAGE):
for filename in files:
if filename.endswith(".mp4"):
clipID = filename.split(".mp4")[0]
bcs.append(Youtube.getBroadcaster(clipID))
bcs = list(dict.fromkeys(bcs))
return f"{bcs[0]}, {bcs[1]} and {bcs[2]} (ScorchAI Compilation)"
def setupCompile(amount):
vidAmount = len(getVideos(CLIPS_FOLDER))
Twitch.generateClips(amount - vidAmount, channel)
a = open("{PREP_STAGE}input.txt", "w")
for path, subdirs, files in os.walk(CLIPS_FOLDER):
for filename in files:
if filename.endswith(".mp4"):
os.system(f"ffmpeg -y -i {CLIPS_FOLDER+filename} -filter:v fps=60 -vcodec libx264 -ar 44100 -preset ultrafast {PREP_STAGE+filename}")
a.write(f"file {filename}\n")
a.close()
def getVideos(folder): return [getVideoName(video) for video in os.listdir(folder)]
def getVideoName(video): return video.split(".mp4")[0]
def getNextVideo(): return getVideos(READY_STAGE)[0] + ".mp4"
def getVideoReadyAmount(): return len(getVideos(READY_STAGE))
def cleanFolder(folder): [os.remove(folder+f) for f in os.listdir(folder)]
def doesChannelExist(channel): return os.path.exists(f"./assets/Channels/{channel}")
runAI()