66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
"""
|
|
Base uploader class for all social media platforms
|
|
"""
|
|
from abc import ABC, abstractmethod
|
|
from pathlib import Path
|
|
from typing import List, Optional, Dict, Any, Union
|
|
from datetime import datetime
|
|
|
|
|
|
class BaseUploader(ABC):
|
|
"""Base class for all platform uploaders"""
|
|
|
|
def __init__(
|
|
self,
|
|
title: str,
|
|
file_path: str,
|
|
tags: List[str],
|
|
publish_date: Optional[datetime] = None,
|
|
account_file: Optional[str] = None,
|
|
description: str = ""
|
|
):
|
|
"""
|
|
Initialize base uploader
|
|
|
|
Args:
|
|
title: Video title
|
|
file_path: Path to video file
|
|
tags: List of tags/hashtags
|
|
publish_date: Scheduled publish time (None = publish immediately)
|
|
account_file: Path to account cookie/credentials file
|
|
description: Video description
|
|
"""
|
|
self.title = title
|
|
self.file_path = Path(file_path)
|
|
self.tags = tags
|
|
self.publish_date = publish_date if publish_date else 0 # 0 = immediate
|
|
self.account_file = account_file
|
|
self.description = description
|
|
|
|
@abstractmethod
|
|
async def main(self) -> Dict[str, Any]:
|
|
"""
|
|
Main upload method - must be implemented by subclasses
|
|
|
|
Returns:
|
|
dict: Upload result with keys:
|
|
- success (bool): Whether upload succeeded
|
|
- message (str): Result message
|
|
- url (str, optional): URL of published video
|
|
"""
|
|
pass
|
|
|
|
def _get_timestamp(self, dt: Union[datetime, int]) -> int:
|
|
"""
|
|
Convert datetime to Unix timestamp
|
|
|
|
Args:
|
|
dt: datetime object or 0 for immediate publish
|
|
|
|
Returns:
|
|
int: Unix timestamp or 0
|
|
"""
|
|
if dt == 0:
|
|
return 0
|
|
return int(dt.timestamp())
|