-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
67 lines (53 loc) · 1.69 KB
/
models.py
File metadata and controls
67 lines (53 loc) · 1.69 KB
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
"""
Data models: MatchSource enum, Theme, Chapter, AnalysisResult dataclasses.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional
class MatchSource(Enum):
"""Source of chapter timing match"""
AUDIO = "audio"
FALLBACK = "fallback"
MANUAL = "manual"
NONE = "none"
@dataclass
class Theme:
"""Anime theme song information"""
label: str
type: str # "OP" or "ED"
sequence: int
version: int
title: str
video_url: str
duration_ms: Optional[int] = None
episode_set: set[int] = field(default_factory=set)
@property
def full_label(self) -> str:
"""Get full label with version if applicable"""
if self.version > 1:
return f"{self.type}{self.sequence}v{self.version}"
return f"{self.type}{self.sequence}"
@dataclass
class Chapter:
"""Single chapter entry"""
timestamp_ms: int
name: str
source: MatchSource = MatchSource.NONE
@dataclass
class AnalysisResult:
"""Result of analyzing a single video"""
video_path: str
basename: str
episode: Optional[int]
video_duration_ms: Optional[int]
op_theme: Optional[Theme] = None
ed_theme: Optional[Theme] = None
op_start_ms: Optional[int] = None
op_end_ms: Optional[int] = None
op_source: MatchSource = MatchSource.NONE
ed_start_ms: Optional[int] = None
ed_end_ms: Optional[int] = None
ed_source: MatchSource = MatchSource.NONE
xml_path: Optional[str] = None
chapters: list[Chapter] = field(default_factory=list)