Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
228cf37eba | ||
|
|
26bb38c2aa | ||
|
|
efba28a7b5 |
@@ -1,3 +1,4 @@
|
|||||||
/secrets.json
|
/secrets.json
|
||||||
/client_secrets.json
|
/client_secrets.json
|
||||||
/clips_database.db
|
/clips_database.db
|
||||||
|
__pycache__/uploader.cpython-313.pyc
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import sqlite3
|
|||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import uploader
|
||||||
|
from uploader import CategoryId
|
||||||
|
|
||||||
CHANNEL_NAME = 'teampgp' # Replace with the streamer's username
|
CHANNEL_NAME = 'teampgp' # Replace with the streamer's username
|
||||||
|
|
||||||
# Stores data locally
|
# Stores data locally
|
||||||
@@ -52,10 +55,33 @@ def download_clips():
|
|||||||
print(f"Slug: {slug} | Was successfully downloaded.")
|
print(f"Slug: {slug} | Was successfully downloaded.")
|
||||||
mark_as_downloaded(slug)
|
mark_as_downloaded(slug)
|
||||||
else:
|
else:
|
||||||
print(f"Slug: {slug} | Process failed.")
|
print(f"Slug: {slug} | Download Process failed.")
|
||||||
|
|
||||||
print("Finished Downloading Clips...")
|
print("Finished Downloading Clips...")
|
||||||
|
|
||||||
|
def upload_clips():
|
||||||
|
"""Loops over the downloaded videos entries and uploaded them to youtube."""
|
||||||
|
print("Uploading Clips...")
|
||||||
|
|
||||||
|
unpuloaded_clips = get_unuploaded_clips()
|
||||||
|
|
||||||
|
for slug, record_date, title, game_name, clip_by, views, downloaded, uploaded_yt in unpuloaded_clips:
|
||||||
|
print(f"Slug: {slug} | Date: {record_date} | Game: {game_name} | By: {clip_by} | Views: {views} | Title: {title}")
|
||||||
|
|
||||||
|
file_path = f"save/clips/{slug}/{slug}.mp4"
|
||||||
|
title = title
|
||||||
|
description = f"Game: {game_name}, Cliped By: {clip_by}, on {record_date}"
|
||||||
|
categoryId = CategoryId.SHORTS
|
||||||
|
privatcyStatus = 'private'
|
||||||
|
tags = ['#SHORT', '#GAMING', '#TeamPGP', f'#{game_name}', f'#{clip_by}']
|
||||||
|
|
||||||
|
if (uploader.upload_video(file_path, title, description, categoryId, privatcyStatus, tags) is True):
|
||||||
|
print(f"Slug: {slug} | Was successfully uploaded.")
|
||||||
|
|
||||||
|
mark_as_uploaded(slug)
|
||||||
|
else:
|
||||||
|
print(f"Slug: {slug} | Upload Process failed.")
|
||||||
|
|
||||||
def run_linux_command(command: str):
|
def run_linux_command(command: str):
|
||||||
"""Executes a Linux command, waits for completion, and returns output."""
|
"""Executes a Linux command, waits for completion, and returns output."""
|
||||||
try:
|
try:
|
||||||
@@ -66,6 +92,14 @@ def run_linux_command(command: str):
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
return {"success": False, "stdout": e.stdout, "stderr": e.stderr}
|
return {"success": False, "stdout": e.stdout, "stderr": e.stderr}
|
||||||
|
|
||||||
|
def mark_as_uploaded(slug: str):
|
||||||
|
"""Flags a specific clip row record to uploaded (1)."""
|
||||||
|
CURSOR.execute(
|
||||||
|
"UPDATE clips SET uploaded_yt = 1 WHERE slug = ?",
|
||||||
|
(slug,)
|
||||||
|
)
|
||||||
|
CONN.commit()
|
||||||
|
|
||||||
def mark_as_downloaded(slug: str):
|
def mark_as_downloaded(slug: str):
|
||||||
"""Flags a specific clip row record to downloaded (1)."""
|
"""Flags a specific clip row record to downloaded (1)."""
|
||||||
CURSOR.execute(
|
CURSOR.execute(
|
||||||
@@ -74,6 +108,13 @@ def mark_as_downloaded(slug: str):
|
|||||||
)
|
)
|
||||||
CONN.commit()
|
CONN.commit()
|
||||||
|
|
||||||
|
def get_unuploaded_clips():
|
||||||
|
"""Retrieves all clip rows remaining to be uploaded."""
|
||||||
|
CURSOR.execute(
|
||||||
|
"SELECT slug, date, title, gamename, clip_by, view_count, downloaded, uploaded_yt FROM clips WHERE downloaded = 1 AND uploaded_yt = 0"
|
||||||
|
)
|
||||||
|
return CURSOR.fetchall()
|
||||||
|
|
||||||
def get_undownloaded_clips():
|
def get_undownloaded_clips():
|
||||||
"""Retrieves all clip rows remaining to be captured."""
|
"""Retrieves all clip rows remaining to be captured."""
|
||||||
CURSOR.execute(
|
CURSOR.execute(
|
||||||
@@ -187,4 +228,5 @@ if __name__ == "__main__":
|
|||||||
create_database()
|
create_database()
|
||||||
get_channel_clips(CHANNEL_NAME)
|
get_channel_clips(CHANNEL_NAME)
|
||||||
download_clips()
|
download_clips()
|
||||||
|
upload_clips()
|
||||||
close_database()
|
close_database()
|
||||||
+45
-4
@@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
|
from enum import Enum, auto, unique
|
||||||
from google.oauth2.credentials import Credentials
|
from google.oauth2.credentials import Credentials
|
||||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||||
from google.auth.transport.requests import Request
|
from google.auth.transport.requests import Request
|
||||||
@@ -9,6 +10,41 @@ from googleapiclient.discovery import build
|
|||||||
from googleapiclient.http import MediaFileUpload
|
from googleapiclient.http import MediaFileUpload
|
||||||
from googleapiclient.errors import HttpError
|
from googleapiclient.errors import HttpError
|
||||||
|
|
||||||
|
@unique
|
||||||
|
class CategoryId(Enum):
|
||||||
|
FILM_ANIMATION = 1
|
||||||
|
AUTOS_VEHICLES = 2
|
||||||
|
MUSIC = 10
|
||||||
|
PETS_ANIMALS = 15
|
||||||
|
SPORTS = 17
|
||||||
|
SHORT_MOVIES = 18
|
||||||
|
TRAVEL_EVENTS = 19
|
||||||
|
GAMING = 20
|
||||||
|
VIDEOBLOGGING = 21
|
||||||
|
PEOPLE_BLOGS = 22
|
||||||
|
COMEDY = 23
|
||||||
|
ENTERTAINMENT = 24
|
||||||
|
NEWS_POLITICS = 25
|
||||||
|
HOWTO_STYLE = 26
|
||||||
|
EDUCATION = 27
|
||||||
|
SCIENCE_TECHNOLOGY = 28
|
||||||
|
NONPROFITS_ACTIVISM = 29
|
||||||
|
MOVIES = 30
|
||||||
|
ANIME_ANIMATION = 31
|
||||||
|
ACTION_ADVENTURE = 32
|
||||||
|
CLASSICS = 33
|
||||||
|
COMEDY_MOVIE = 34 # Renamed to avoid name collision
|
||||||
|
DOCUMENTARY = 35
|
||||||
|
DRAMA = 36
|
||||||
|
FAMILY = 37
|
||||||
|
FOREIGN = 38
|
||||||
|
HORROR = 39
|
||||||
|
SCI_FI_FANTASY = 40
|
||||||
|
THRILLER = 41
|
||||||
|
SHORTS = 42
|
||||||
|
SHOWS = 43
|
||||||
|
TRAILERS = 44
|
||||||
|
|
||||||
def load_credentials():
|
def load_credentials():
|
||||||
"""Load credentials from secrets.json"""
|
"""Load credentials from secrets.json"""
|
||||||
try:
|
try:
|
||||||
@@ -36,13 +72,17 @@ def load_credentials():
|
|||||||
print(f"Error loading credentials: {str(e)}")
|
print(f"Error loading credentials: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def upload_video(file_path, description):
|
def upload_video(file_path: str, title: str, description: str, category: CategoryId, privacyStatus: str = 'private', tags: list = []):
|
||||||
"""
|
"""
|
||||||
Upload a video to YouTube
|
Upload a video to YouTube
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_path (str): Path to the video file
|
file_path (str): Path to the video file
|
||||||
|
title (str): Title of the Video
|
||||||
description (str): Video description
|
description (str): Video description
|
||||||
|
categoryId (str): categoryId of the video
|
||||||
|
privacyStatus (str): privacyStatus of the video
|
||||||
|
tags (str): tags to be use on the video
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Check if file exists
|
# Check if file exists
|
||||||
@@ -66,15 +106,16 @@ def upload_video(file_path, description):
|
|||||||
'snippet': {
|
'snippet': {
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'tags': [],
|
'tags': tags,
|
||||||
'categoryId': '22' # Default to 'People & Blogs' category
|
'categoryId': str(category.value) # Default to 'People & Blogs' category
|
||||||
},
|
},
|
||||||
'status': {
|
'status': {
|
||||||
'privacyStatus': 'private', # Default to private
|
'privacyStatus': privacyStatus, # Default to private
|
||||||
'selfDeclaredMadeForKids': False
|
'selfDeclaredMadeForKids': False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Create media file upload
|
# Create media file upload
|
||||||
media = MediaFileUpload(
|
media = MediaFileUpload(
|
||||||
file_path,
|
file_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user