59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
"""
|
|
Source Adapter 抽象基类
|
|
"""
|
|
from abc import ABC, abstractmethod
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from models import Content
|
|
|
|
|
|
class SourceAdapter(ABC):
|
|
"""内容源适配器基类"""
|
|
|
|
@abstractmethod
|
|
def fetch_new(self, since: datetime, **kwargs) -> List[Content]:
|
|
"""
|
|
获取新内容
|
|
|
|
Args:
|
|
since: 起始时间,只获取该时间之后的内容
|
|
**kwargs: 额外的参数
|
|
|
|
Returns:
|
|
List[Content]: 新内容列表
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def extract_content(self, url: str, **kwargs) -> Optional[Content]:
|
|
"""
|
|
从URL提取内容
|
|
|
|
Args:
|
|
url: 内容URL
|
|
**kwargs: 额外的参数
|
|
|
|
Returns:
|
|
Optional[Content]: 内容对象,如果提取失败返回None
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_transcript(self, content: Content, **kwargs) -> Optional[str]:
|
|
"""
|
|
获取字幕/文本
|
|
|
|
Args:
|
|
content: 内容对象
|
|
**kwargs: 额外的参数
|
|
|
|
Returns:
|
|
Optional[str]: 字幕文本(SRT格式),如果没有字幕返回None
|
|
"""
|
|
pass
|
|
|
|
|
|
# 为向后兼容,提供 BaseSource 别名
|
|
BaseSource = SourceAdapter
|