Skip to content

TraceMoe

Classes

TraceMoeItem

Bases: BaseSearchItem

Represents a single search result from the TraceMoe API.

This class contains detailed information about a matched anime scene, including metadata about the anime and specific timing information for the matched scene.

Attributes:

Name Type Description
origin dict

Raw response data from the API.

anime_info dict

Comprehensive anime metadata.

idMal int

MyAnimeList database ID.

title dict

Dictionary containing titles in various languages.

title_native str

Title in the original language.

title_english str

English title.

title_romaji str

Romanized title.

title_chinese str

Chinese title.

anilist int

AniList database ID.

synonyms list[str]

Alternative titles.

isAdult bool

Whether the content is adult-oriented.

type str

Media type classification.

format str

Content format (TV, Movie, OVA, etc.).

start_date dict

Anime start date information.

end_date dict

Anime end date information.

cover_image str

URL to the anime cover image.

filename str

Name of the file containing the matched scene.

episode int

Episode number of the match.

From float

Start timestamp of the matched scene.

To float

End timestamp of the matched scene.

similarity float

Match confidence percentage (0-100).

video str

URL to the preview video of the matched scene.

image str

URL to the preview image of the matched scene.

Source code in PicImageSearch/model/tracemoe.py
 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
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class TraceMoeItem(BaseSearchItem):
    """Represents a single search result from the TraceMoe API.

    This class contains detailed information about a matched anime scene, including
    metadata about the anime and specific timing information for the matched scene.

    Attributes:
        origin (dict): Raw response data from the API.
        anime_info (dict): Comprehensive anime metadata.
        idMal (int): MyAnimeList database ID.
        title (dict): Dictionary containing titles in various languages.
        title_native (str): Title in the original language.
        title_english (str): English title.
        title_romaji (str): Romanized title.
        title_chinese (str): Chinese title.
        anilist (int): AniList database ID.
        synonyms (list[str]): Alternative titles.
        isAdult (bool): Whether the content is adult-oriented.
        type (str): Media type classification.
        format (str): Content format (TV, Movie, OVA, etc.).
        start_date (dict): Anime start date information.
        end_date (dict): Anime end date information.
        cover_image (str): URL to the anime cover image.
        filename (str): Name of the file containing the matched scene.
        episode (int): Episode number of the match.
        From (float): Start timestamp of the matched scene.
        To (float): End timestamp of the matched scene.
        similarity (float): Match confidence percentage (0-100).
        video (str): URL to the preview video of the matched scene.
        image (str): URL to the preview image of the matched scene.
    """

    def __init__(
        self,
        data: dict[str, Any],
        mute: bool = False,
        size: Optional[str] = None,
    ):
        """Initializes a TraceMoeItem with data from a search result.

        Args:
            data (dict[str, Any]): A dictionary containing parsed response data for an individual result.
            mute (bool): Indicates whether to mute the video excerpt.
            size (Optional[str]): Size parameter for modifying video and image URLs.
        """
        super().__init__(data, mute=mute, size=size)

    def _parse_data(self, data: dict[str, Any], **kwargs: Any) -> None:
        """Parses raw API response data into structured attributes.

        Processes the raw JSON response and initializes all class attributes.
        Handles URL modifications for video and image previews based on size and mute preferences.

        Args:
            data (dict[str, Any]): Raw response dictionary from the TraceMoe API.
            **kwargs (Any): Additional parameters including:
                - size (str): Preview size modifier ('l', 'm', 's')
                - mute (bool): Whether to mute video previews

        Note:
            - Size parameter affects both video and image preview URLs
            - Mute parameter only affects video preview URLs
        """
        self.anime_info: dict[str, Any] = {}
        self.idMal: int = 0
        self.title: dict[str, str] = {}  # type: ignore
        self.title_native: str = ""
        self.title_english: str = ""
        self.title_romaji: str = ""
        self.title_chinese: str = ""
        self.anilist: int = data["anilist"]
        self.synonyms: list[str] = []
        self.isAdult: bool = False
        self.type: str = ""
        self.format: str = ""
        self.start_date: dict[str, Any] = {}
        self.end_date: dict[str, Any] = {}
        self.cover_image: str = ""
        self.filename: str = data["filename"]
        self.episode: int = data["episode"]
        self.From: float = data["from"]
        self.To: float = data["to"]
        self.similarity: float = float(f"{data['similarity'] * 100:.2f}")
        self.video: str = data["video"]
        self.image: str = data["image"]
        # Modify video and image URLs based on size
        size = kwargs.get("size")
        if size in ["l", "s", "m"]:
            self.video += f"&size={size}"
            self.image += f"&size={size}"
        # If muted, add mute parameter to video URL
        if kwargs.get("mute"):
            self.video += "&mute"

Functions

__init__(data, mute=False, size=None)

Initializes a TraceMoeItem with data from a search result.

Parameters:

Name Type Description Default
data dict[str, Any]

A dictionary containing parsed response data for an individual result.

required
mute bool

Indicates whether to mute the video excerpt.

False
size Optional[str]

Size parameter for modifying video and image URLs.

None
Source code in PicImageSearch/model/tracemoe.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def __init__(
    self,
    data: dict[str, Any],
    mute: bool = False,
    size: Optional[str] = None,
):
    """Initializes a TraceMoeItem with data from a search result.

    Args:
        data (dict[str, Any]): A dictionary containing parsed response data for an individual result.
        mute (bool): Indicates whether to mute the video excerpt.
        size (Optional[str]): Size parameter for modifying video and image URLs.
    """
    super().__init__(data, mute=mute, size=size)

TraceMoeMe

Represents user account information from the TraceMoe API.

This class encapsulates user-specific data including quotas, priorities, and usage statistics returned by the TraceMoe API.

Attributes:

Name Type Description
id str

User identifier (IP address for visitors or email for registered users).

priority int

User's priority level for request processing.

concurrency int

Maximum number of concurrent search requests allowed.

quota int

Total search quota allocated for the current month.

quotaUsed int

Number of searches consumed in the current month.

Source code in PicImageSearch/model/tracemoe.py
 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
class TraceMoeMe:
    """Represents user account information from the TraceMoe API.

    This class encapsulates user-specific data including quotas, priorities, and usage statistics
    returned by the TraceMoe API.

    Attributes:
        id (str): User identifier (IP address for visitors or email for registered users).
        priority (int): User's priority level for request processing.
        concurrency (int): Maximum number of concurrent search requests allowed.
        quota (int): Total search quota allocated for the current month.
        quotaUsed (int): Number of searches consumed in the current month.
    """

    def __init__(self, data: dict[str, Any]):
        """Initializes a TraceMoeMe with user-related data from TraceMoe response.

        Args:
            data (dict[str, Any]): A dictionary containing user-related data from TraceMoe.
        """
        self.id: str = data["id"]
        self.priority: int = data["priority"]
        self.concurrency: int = data["concurrency"]
        self.quota: int = data["quota"]
        self.quotaUsed: int = data["quotaUsed"]

Attributes

concurrency: int = data['concurrency'] instance-attribute
id: str = data['id'] instance-attribute
priority: int = data['priority'] instance-attribute
quota: int = data['quota'] instance-attribute
quotaUsed: int = data['quotaUsed'] instance-attribute

Functions

__init__(data)

Initializes a TraceMoeMe with user-related data from TraceMoe response.

Parameters:

Name Type Description Default
data dict[str, Any]

A dictionary containing user-related data from TraceMoe.

required
Source code in PicImageSearch/model/tracemoe.py
20
21
22
23
24
25
26
27
28
29
30
def __init__(self, data: dict[str, Any]):
    """Initializes a TraceMoeMe with user-related data from TraceMoe response.

    Args:
        data (dict[str, Any]): A dictionary containing user-related data from TraceMoe.
    """
    self.id: str = data["id"]
    self.priority: int = data["priority"]
    self.concurrency: int = data["concurrency"]
    self.quota: int = data["quota"]
    self.quotaUsed: int = data["quotaUsed"]

TraceMoeResponse

Bases: BaseSearchResponse[TraceMoeItem]

Represents the complete response from a TraceMoe search operation.

Encapsulates the entire search response including all matched scenes and metadata about the search operation itself.

Attributes:

Name Type Description
origin dict

Raw API response data.

raw list[TraceMoeItem]

List of processed search results.

frameCount int

Total number of frames analyzed during search.

error str

Error message if the search encountered issues.

url str

URL to the search results page.

Source code in PicImageSearch/model/tracemoe.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
class TraceMoeResponse(BaseSearchResponse[TraceMoeItem]):
    """Represents the complete response from a TraceMoe search operation.

    Encapsulates the entire search response including all matched scenes and metadata
    about the search operation itself.

    Attributes:
        origin (dict): Raw API response data.
        raw (list[TraceMoeItem]): List of processed search results.
        frameCount (int): Total number of frames analyzed during search.
        error (str): Error message if the search encountered issues.
        url (str): URL to the search results page.
    """

    def __init__(
        self,
        resp_data: dict[str, Any],
        resp_url: str,
        mute: bool,
        size: Optional[str],
    ):
        """Initializes with the response data.

        Args:
            resp_data (dict[str, Any]): A dictionary containing parsed response data from TraceMoe.
            resp_url (str): URL to the search result page.
            mute (bool): Flag for muting video excerpts in search results.
            size (Optional[str]): Size parameter for modifying video and image URLs.
        """
        super().__init__(resp_data, resp_url, mute=mute, size=size)

    def _parse_response(self, resp_data: dict[str, Any], **kwargs: Any) -> None:
        """Processes the raw API response into structured data.

        Converts raw JSON response into TraceMoeItem instances and extracts
        metadata about the search operation.

        Args:
            resp_data (dict[str, Any]): Raw response dictionary from the TraceMoe API.
            **kwargs (Any): Additional parameters including:
                - mute (bool): Whether to mute video previews
                - size (str): Preview size modifier

        Note:
            The parsed results are stored in the `raw` attribute as TraceMoeItem instances.
        """
        res_docs = resp_data["result"]
        self.raw.extend(
            [
                TraceMoeItem(
                    i,
                    mute=kwargs.get("mute", False),
                    size=kwargs.get("size"),
                )
                for i in res_docs
            ]
        )
        self.frameCount: int = resp_data["frameCount"]
        self.error: str = resp_data["error"]

Functions

__init__(resp_data, resp_url, mute, size)

Initializes with the response data.

Parameters:

Name Type Description Default
resp_data dict[str, Any]

A dictionary containing parsed response data from TraceMoe.

required
resp_url str

URL to the search result page.

required
mute bool

Flag for muting video excerpts in search results.

required
size Optional[str]

Size parameter for modifying video and image URLs.

required
Source code in PicImageSearch/model/tracemoe.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
def __init__(
    self,
    resp_data: dict[str, Any],
    resp_url: str,
    mute: bool,
    size: Optional[str],
):
    """Initializes with the response data.

    Args:
        resp_data (dict[str, Any]): A dictionary containing parsed response data from TraceMoe.
        resp_url (str): URL to the search result page.
        mute (bool): Flag for muting video excerpts in search results.
        size (Optional[str]): Size parameter for modifying video and image URLs.
    """
    super().__init__(resp_data, resp_url, mute=mute, size=size)