update to the process_uploads upload.py and new database table called data
This commit is contained in:
1 parent
afe6490d20
commit
2773200a94
17 files changed
+245
-70
No files matched your search
@@ -2,7 +2,7 @@
|
||||
import os
|
||||
import argparse
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.http import MediaFileUpload
|
||||
@@ -29,7 +29,7 @@ class CategoryId(Enum):
|
||||
SCIENCE_AND_TECHNOLOGY = "28"
|
||||
NONPROFITS_AND_ACTIVISM = "29"
|
||||
|
||||
def upload_video(file_path: str, title: str, category: CategoryId, description: str = "", privacyStatus: str = 'private', tags: list = None, release_time: datetime = None) -> bool:
|
||||
def upload_video(file_path: str, title: str, category: CategoryId, description: str = "", privacyStatus: str = 'private', tags: list = None, release_time: datetime = None) -> str | None:
|
||||
"""
|
||||
Upload a video to YouTube
|
||||
|
||||
@@ -51,11 +51,12 @@ def upload_video(file_path: str, title: str, category: CategoryId, description:
|
||||
# Check if file exists
|
||||
if not os.path.exists(file_path):
|
||||
print(f"❌ Error: File not found: {file_path}")
|
||||
return False
|
||||
return None
|
||||
|
||||
# Load credentials
|
||||
if not config.CREDENTIALS:
|
||||
return False
|
||||
print("❌ Error: YouTube API credentials not configured.")
|
||||
return None
|
||||
|
||||
# Create YouTube API client
|
||||
youtube = build('youtube', 'v3', credentials=config.CREDENTIALS)
|
||||
@@ -71,7 +72,8 @@ def upload_video(file_path: str, title: str, category: CategoryId, description:
|
||||
|
||||
# If release_time is passed, YouTube forces privacyStatus to 'private'
|
||||
status_body['privacyStatus'] = 'private'
|
||||
status_body['publishAt'] = release_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
|
||||
#status_body['publishAt'] = release_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
|
||||
status_body['publishAt'] = release_time.isoformat()
|
||||
print(f"Configuring timed release for: {status_body['publishAt']}")
|
||||
else:
|
||||
# Standard immediate upload
|
||||
@@ -121,14 +123,14 @@ def upload_video(file_path: str, title: str, category: CategoryId, description:
|
||||
else:
|
||||
print(f"Current Privacy Status: {response['status']['privacyStatus']}")
|
||||
|
||||
return True
|
||||
return response['id']
|
||||
|
||||
except HttpError as e:
|
||||
print(f"An HTTP error occurred: {str(e)}")
|
||||
return False
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
return False
|
||||
return None
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Upload a video to YouTube')
|
||||
|
||||
Reference in new issue
Block a user