File size: 1,911 Bytes
b5df735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Download models
"""

from dataclasses import dataclass
from typing import Optional, Dict, Any
from enum import Enum

from .base import BaseRequest, BaseResponse, OperationStatus


class PodcastPlatform(str, Enum):
    """Supported podcast platforms"""
    APPLE_PODCAST = "apple_podcast"
    XIAOYUZHOU = "xiaoyuzhou"


@dataclass
class DownloadRequest(BaseRequest):
    """Request model for podcast download"""
    url: str
    platform: PodcastPlatform
    output_directory: Optional[str] = None
    auto_transcribe: bool = False
    enable_speaker_diarization: bool = False


@dataclass
class DownloadResponse(BaseResponse):
    """Response model for podcast download"""
    original_url: str = ""
    audio_file_path: Optional[str] = None
    file_size_mb: Optional[float] = None
    duration_seconds: Optional[float] = None
    
    @classmethod
    def success(
        cls,
        original_url: str,
        audio_file_path: str,
        file_size_mb: Optional[float] = None,
        duration_seconds: Optional[float] = None,
        message: str = "下载成功"
    ) -> "DownloadResponse":
        """Create successful response"""
        return cls(
            status=OperationStatus.SUCCESS,
            message=message,
            original_url=original_url,
            audio_file_path=audio_file_path,
            file_size_mb=file_size_mb,
            duration_seconds=duration_seconds
        )
    
    @classmethod
    def failed(
        cls,
        original_url: str,
        error_message: str,
        error_code: str = "DOWNLOAD_ERROR",
        error_details: Optional[Dict[str, Any]] = None
    ) -> "DownloadResponse":
        """Create failed response"""
        return cls(
            status=OperationStatus.FAILED,
            message=error_message,
            error_code=error_code,
            error_details=error_details,
            original_url=original_url
        )