Compare commits
3
Commits
f4c366f9aa
...
228cf37eba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
228cf37eba | ||
|
|
26bb38c2aa | ||
|
|
efba28a7b5 |
@@ -1,3 +1,4 @@
|
||||
/secrets.json
|
||||
/client_secrets.json
|
||||
/clips_database.db
|
||||
__pycache__/uploader.cpython-313.pyc
|
||||
|
||||
@@ -4,6 +4,9 @@ import sqlite3
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
import uploader
|
||||
from uploader import CategoryId
|
||||
|
||||
CHANNEL_NAME = 'teampgp' # Replace with the streamer's username
|
||||
|
||||
# Stores data locally
|
||||
@@ -52,10 +55,33 @@ def download_clips():
|
||||
print(f"Slug: {slug} | Was successfully downloaded.")
|
||||
mark_as_downloaded(slug)
|
||||
else:
|
||||
print(f"Slug: {slug} | Process failed.")
|
||||
|
||||
print(f"Slug: {slug} | Download Process failed.")
|
||||
|
||||
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):
|
||||
"""Executes a Linux command, waits for completion, and returns output."""
|
||||
try:
|
||||
@@ -65,6 +91,14 @@ def run_linux_command(command: str):
|
||||
return {"success": True, "stdout": result.stdout, "stderr": result.stderr}
|
||||
except subprocess.CalledProcessError as e:
|
||||
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):
|
||||
"""Flags a specific clip row record to downloaded (1)."""
|
||||
@@ -74,6 +108,13 @@ def mark_as_downloaded(slug: str):
|
||||
)
|
||||
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():
|
||||
"""Retrieves all clip rows remaining to be captured."""
|
||||
CURSOR.execute(
|
||||
@@ -187,4 +228,5 @@ if __name__ == "__main__":
|
||||
create_database()
|
||||
get_channel_clips(CHANNEL_NAME)
|
||||
download_clips()
|
||||
upload_clips()
|
||||
close_database()
|
||||
+45
-4
@@ -2,6 +2,7 @@
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
from enum import Enum, auto, unique
|
||||
from google.oauth2.credentials import Credentials
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from google.auth.transport.requests import Request
|
||||
@@ -9,6 +10,41 @@ from googleapiclient.discovery import build
|
||||
from googleapiclient.http import MediaFileUpload
|
||||
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():
|
||||
"""Load credentials from secrets.json"""
|
||||
try:
|
||||
@@ -36,13 +72,17 @@ def load_credentials():
|
||||
print(f"Error loading credentials: {str(e)}")
|
||||
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
|
||||
|
||||
Args:
|
||||
file_path (str): Path to the video file
|
||||
title (str): Title of the Video
|
||||
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:
|
||||
# Check if file exists
|
||||
@@ -66,15 +106,16 @@ def upload_video(file_path, description):
|
||||
'snippet': {
|
||||
'title': title,
|
||||
'description': description,
|
||||
'tags': [],
|
||||
'categoryId': '22' # Default to 'People & Blogs' category
|
||||
'tags': tags,
|
||||
'categoryId': str(category.value) # Default to 'People & Blogs' category
|
||||
},
|
||||
'status': {
|
||||
'privacyStatus': 'private', # Default to private
|
||||
'privacyStatus': privacyStatus, # Default to private
|
||||
'selfDeclaredMadeForKids': False
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Create media file upload
|
||||
media = MediaFileUpload(
|
||||
file_path,
|
||||
|
||||
Reference in New Issue
Block a user