File: __init__.py

package info (click to toggle)
python-xbox-webapi 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,916 kB
  • sloc: python: 4,973; makefile: 79
file content (166 lines) | stat: -rw-r--r-- 5,531 bytes parent folder | download | duplicates (2)
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
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
126
127
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
"""
Gameclips - Get gameclip info
"""
from xbox.webapi.api.provider.baseprovider import BaseProvider
from xbox.webapi.api.provider.gameclips.models import GameclipsResponse


class GameclipProvider(BaseProvider):
    GAMECLIPS_METADATA_URL = "https://gameclipsmetadata.xboxlive.com"
    HEADERS_GAMECLIPS_METADATA = {"x-xbl-contract-version": "1"}

    async def get_recent_community_clips_by_title_id(
        self, title_id: str, **kwargs
    ) -> GameclipsResponse:
        """
        Get recent community clips by Title Id

        Args:
            title_id: Title Id to get clips for

        Returns:
            :class:`GameclipsResponse`: Game clip Response
        """
        url = self.GAMECLIPS_METADATA_URL + f"/public/titles/{title_id}/clips"
        params = {"qualifier": "created"}
        resp = await self.client.session.get(
            url, params=params, headers=self.HEADERS_GAMECLIPS_METADATA, **kwargs
        )
        resp.raise_for_status()
        return GameclipsResponse(**resp.json())

    async def get_recent_own_clips(
        self, title_id: str = None, skip_items: int = 0, max_items: int = 25, **kwargs
    ) -> GameclipsResponse:
        """
        Get own recent clips, optionally filter for title Id

        Args:
            title_id: Title ID to filter
            skip_items: Item count to skip
            max_items: Maximum item count to load

        Returns:
            :class:`GameclipsResponse`: Game clip Response
        """
        url = self.GAMECLIPS_METADATA_URL + "/users/me"
        if title_id:
            url += f"/titles/{title_id}"
        url += "/clips"

        params = {"skipItems": skip_items, "maxItems": max_items}
        resp = await self.client.session.get(
            url, params=params, headers=self.HEADERS_GAMECLIPS_METADATA, **kwargs
        )
        resp.raise_for_status()
        return GameclipsResponse(**resp.json())

    async def get_recent_clips_by_xuid(
        self,
        xuid: str,
        title_id: str = None,
        skip_items: int = 0,
        max_items: int = 25,
        **kwargs,
    ) -> GameclipsResponse:
        """
        Get clips by XUID, optionally filter for title Id

        Args:
            xuid: XUID of user to get clips from
            title_id: Optional title id filter
            skip_items: Item count to skip
            max_items: Maximum item count to load

        Returns:
            :class:`GameclipsResponse`: Game clip Response
        """
        url = self.GAMECLIPS_METADATA_URL + f"/users/xuid({xuid})"
        if title_id:
            url += f"/titles/{title_id}"
        url += "/clips"

        params = {"skipItems": skip_items, "maxItems": max_items}
        resp = await self.client.session.get(
            url, params=params, headers=self.HEADERS_GAMECLIPS_METADATA, **kwargs
        )
        resp.raise_for_status()
        return GameclipsResponse(**resp.json())

    async def get_saved_community_clips_by_title_id(
        self, title_id: str, **kwargs
    ) -> GameclipsResponse:
        """
        Get saved community clips by Title Id

        Args:
            title_id: Title Id to get screenshots for

        Returns:
            :class:`GameclipsResponse`: Game clip Response
        """
        url = self.GAMECLIPS_METADATA_URL + f"/public/titles/{title_id}/clips/saved"
        params = {"qualifier": "created"}
        resp = await self.client.session.get(
            url, params=params, headers=self.HEADERS_GAMECLIPS_METADATA, **kwargs
        )
        resp.raise_for_status()
        return GameclipsResponse(**resp.json())

    async def get_saved_own_clips(
        self, title_id: str = None, skip_items: int = 0, max_items: int = 25, **kwargs
    ) -> GameclipsResponse:
        """
        Get own saved clips, optionally filter for title Id an

        Args:
            title_id: Optional Title ID to filter
            skip_items: Item count to skip
            max_items: Maximum item count to load

        Returns:
            :class:`GameclipsResponse`: Game clip Response
        """
        url = self.GAMECLIPS_METADATA_URL + "/users/me"
        if title_id:
            url += f"/titles/{title_id}"
        url += "/clips/saved"

        params = {"skipItems": skip_items, "maxItems": max_items}
        resp = await self.client.session.get(
            url, params=params, headers=self.HEADERS_GAMECLIPS_METADATA, **kwargs
        )
        resp.raise_for_status()
        return GameclipsResponse(**resp.json())

    async def get_saved_clips_by_xuid(
        self,
        xuid: str,
        title_id: str = None,
        skip_items: int = 0,
        max_items: int = 25,
        **kwargs,
    ) -> GameclipsResponse:
        """
        Get saved clips by XUID, optionally filter for title Id

        Args:
            xuid: XUID of user to get screenshots from
            title_id: Optional title id filter
            skip_items: Item count to skip
            max_items: Maximum item count to load

        Returns:
            :class:`GameclipsResponse`: Game clip Response
        """
        url = self.GAMECLIPS_METADATA_URL + f"/users/xuid({xuid})"
        if title_id:
            url += f"/titles/{title_id}"
        url += "/clips/saved"

        params = {"skipItems": skip_items, "maxItems": max_items}
        resp = await self.client.session.get(
            url, params=params, headers=self.HEADERS_GAMECLIPS_METADATA, **kwargs
        )
        resp.raise_for_status()
        return GameclipsResponse(**resp.json())