92 lines
3.5 KiB
Python
92 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import package.utils as utils
|
|
|
|
from package.config import TZ as TZ
|
|
from package.config import DB as DB
|
|
from package.hash_tags import get_top_nouns as get_top_nouns
|
|
from package.youtube.uploader import upload_video as upload_video
|
|
from package.youtube.uploader import CategoryId as CategoryId
|
|
|
|
from package.database import TwitchVideo, YoutubeInfo, Data
|
|
|
|
def process_shorts():
|
|
shorts = DB.get_unuploaded_shorts()
|
|
data = DB.get_data()
|
|
meta_data: Data = data[0]
|
|
|
|
release_time = meta_data.date_shorts
|
|
|
|
|
|
current_time = datetime.now(TZ)
|
|
release_time = datetime.strptime(release_time, "%Y-%m-%d %H:%M:%S%z")
|
|
|
|
if current_time > release_time:
|
|
release_time = current_time
|
|
release_time = release_time.replace(hour=12, minute=0, second=0, microsecond=0)
|
|
|
|
for short in shorts:
|
|
original_path = f"download/clips/{short.id}/{short.id}.mp4"
|
|
file_path = f"download/clips/{short.id}/{short.id}_gaussian_9_16.mp4"
|
|
file_csv = f"download/clips/{short.id}/{short.id}_{meta_data.name}.csv"
|
|
if not os.path.exists(file_path):
|
|
file_path = f"download/clips/{short.id}/{short.id}_black_9_16.mp4"
|
|
if not os.path.exists(file_path):
|
|
continue
|
|
|
|
short.title = short.title
|
|
created_at = datetime.strptime(short.created_at, "%Y-%m-%d %H:%M:%S%z")
|
|
created_at = created_at.astimezone(TZ)
|
|
categoryId = CategoryId.GAMING
|
|
description = f"Game: {short.game_name}, Clipped By: {short.creator_name}, on {created_at.strftime("%Y-%m-%d %H:%M:%S %Z (%:z)")}, #Shorts #Clips #Twitch Every Friday and Sunday @7:30 ET https://twitch.tv/teampgp"
|
|
privatcyStatus = 'private'
|
|
tags = ['shorts', 'gaming', 'TeamPGP', f'{short.game_name}', f'{short.creator_name}', 'twitch_clips', 'clips', 'Level1Techs', 'twitch']
|
|
|
|
tags.extend(get_top_nouns(f"download/clips/{short.id}/{short.id}.srt"))
|
|
|
|
youtube_info = DB.get_youtube_info(short.id)
|
|
|
|
if not youtube_info:
|
|
youtube_info = YoutubeInfo()
|
|
|
|
if os.path.exists(original_path):
|
|
yt_video_id = None
|
|
if (youtube_info.id == short.id and youtube_info.yt_short_id is not None) or (yt_video_id := upload_video(original_path, short.title, categoryId, description, 'unlisted', tags)):
|
|
if youtube_info.id == short.id:
|
|
yt_video_id = youtube_info.yt_short_id
|
|
|
|
data_csv = [yt_video_id, current_time]
|
|
release_time += timedelta(days=1)
|
|
|
|
# Assign / Update values on the object
|
|
youtube_info.id = short.id
|
|
youtube_info.yt_id = yt_video_id
|
|
youtube_info.yt_date = datetime.now(TZ)
|
|
|
|
if yt_video_id := upload_video(file_path, short.title, categoryId, f"{description} Original Full size @ https://youtu.be/{yt_video_id}", privatcyStatus, tags, release_time):
|
|
data_csv.extend([yt_video_id, release_time])
|
|
DB.mark_as_uploaded_yt(short.id)
|
|
DB.mark_as_uploaded_shorts(short.id)
|
|
utils.write_csv([data_csv], file_csv)
|
|
|
|
youtube_info.yt_short_id = yt_video_id
|
|
youtube_info.yt_short_date = datetime.now(TZ)
|
|
|
|
DB.insert(youtube_info)
|
|
else:
|
|
break
|
|
|
|
DB.update_date_shorts(release_time)
|
|
|
|
def process_chats():
|
|
pass
|
|
|
|
def process_uploads():
|
|
process_shorts()
|
|
#process_chats()
|
|
|
|
if __name__ == "__main__":
|
|
pass |