Skip to content

delivery

Contains classes and functions related to Roblox asset delivery.

BaseCDNHash

Represents a cdn_hash on a Roblox content delivery network.

Attributes:

Name Type Description
cdn_hash str

The CDN hash as a string.

Source code in roblox/delivery.py
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
class BaseCDNHash:
    """
    Represents a cdn_hash on a Roblox content delivery network.

    Attributes:
        cdn_hash: The CDN hash as a string.
    """

    def __init__(self, client: Client, cdn_hash: str):
        """
        Arguments:
            client: The Client object.
            cdn_hash: The CDN hash as a string.
        """

        self._client: Client = client
        self.cdn_hash: str = cdn_hash

    def __repr__(self):
        return f"<{self.__class__.__name__} cdn_hash={self.cdn_hash}>"

    def get_cdn_number(self) -> int:
        """
        Returns the CDN number of this CDN hash.

        Returns:
            The computed number of the given cdn_hash
        """

        return get_cdn_number(self.cdn_hash)

    def _get_url(self, prefix: str, site: str = cdn_site) -> str:
        cdn_number: int = self.get_cdn_number()
        return self._client.url_generator.get_url(f"{prefix}{cdn_number}", self.cdn_hash, site)

    def get_url(self, site: str = cdn_site) -> str:
        """
        Gets the cdn_hash's URL. This should be implemented by subclasses.

        Arguments:
            site: Represents the URL for what site it should target, be it rbxcdn.com, or roblox.com etc.

        Returns:
            The computed URL from the given cdn_hash attribute.
        """

        raise NotImplementedError

__init__(client, cdn_hash)

Parameters:

Name Type Description Default
client Client

The Client object.

required
cdn_hash str

The CDN hash as a string.

required
Source code in roblox/delivery.py
39
40
41
42
43
44
45
46
47
def __init__(self, client: Client, cdn_hash: str):
    """
    Arguments:
        client: The Client object.
        cdn_hash: The CDN hash as a string.
    """

    self._client: Client = client
    self.cdn_hash: str = cdn_hash

get_cdn_number()

Returns the CDN number of this CDN hash.

Returns:

Type Description
int

The computed number of the given cdn_hash

Source code in roblox/delivery.py
52
53
54
55
56
57
58
59
60
def get_cdn_number(self) -> int:
    """
    Returns the CDN number of this CDN hash.

    Returns:
        The computed number of the given cdn_hash
    """

    return get_cdn_number(self.cdn_hash)

get_url(site=cdn_site)

Gets the cdn_hash's URL. This should be implemented by subclasses.

Parameters:

Name Type Description Default
site str

Represents the URL for what site it should target, be it rbxcdn.com, or roblox.com etc.

cdn_site

Returns:

Type Description
str

The computed URL from the given cdn_hash attribute.

Source code in roblox/delivery.py
66
67
68
69
70
71
72
73
74
75
76
77
def get_url(self, site: str = cdn_site) -> str:
    """
    Gets the cdn_hash's URL. This should be implemented by subclasses.

    Arguments:
        site: Represents the URL for what site it should target, be it rbxcdn.com, or roblox.com etc.

    Returns:
        The computed URL from the given cdn_hash attribute.
    """

    raise NotImplementedError

ContentCDNHash

Bases: BaseCDNHash

Represents a CDN hash on cX.rbxcdn.com.

Source code in roblox/delivery.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
class ContentCDNHash(BaseCDNHash):
    """
    Represents a CDN hash on cX.rbxcdn.com.
    """

    def __init__(self, client: Client, cdn_hash: str):
        super().__init__(client=client, cdn_hash=cdn_hash)

    def get_url(self, site: str = cdn_site) -> str:
        """
        Returns:
            This hash's URL.
        """

        return self._get_url("c", cdn_site)

get_url(site=cdn_site)

Returns:

Type Description
str

This hash's URL.

Source code in roblox/delivery.py
104
105
106
107
108
109
110
def get_url(self, site: str = cdn_site) -> str:
    """
    Returns:
        This hash's URL.
    """

    return self._get_url("c", cdn_site)

DeliveryProvider

Provides CDN hashes and other delivery-related objects.

Source code in roblox/delivery.py
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
class DeliveryProvider:
    """
    Provides CDN hashes and other delivery-related objects.
    """

    def __init__(self, client: Client):
        """
        Arguments:
            client: The client object, which is passed to all objects this client generates.
        """
        self._client: Client = client

    def get_cdn_hash(self, cdn_hash: str) -> BaseCDNHash:
        """
        Gets a Roblox CDN cdn_hash.

        Arguments:
            cdn_hash: The cdn_hash.

        Returns:
            A BaseCDNHash.
        """

        return BaseCDNHash(
            client=self._client,
            cdn_hash=cdn_hash
        )

    def get_cdn_hash_from_url(self, url: str, site: str = cdn_site) -> BaseCDNHash:
        """
        todo: turn this into something that actually splits into path.

        Arguments:
            url: A CDN url.
            site: The site this cdn_hash is located at.

        Returns:
            The CDN cdn_hash for the supplied CDN URL.
        """

        return self.get_cdn_hash(
            cdn_hash=url.split(f".{site}/")[1]
        )

    def get_thumbnail_cdn_hash(self, cdn_hash: str) -> ThumbnailCDNHash:
        """
        Gets a Roblox CDN cdn_hash.

        Arguments:
            cdn_hash: The cdn_hash.

        Returns:
            A ThumbnailCDNHash.
        """

        return ThumbnailCDNHash(
            client=self._client,
            cdn_hash=cdn_hash
        )

    def get_content_cdn_hash(self, cdn_hash: str) -> ContentCDNHash:
        """
        Gets a Roblox CDN cdn_hash.

        Arguments:
            cdn_hash: The cdn_hash.

        Returns:
            A ContentCDNHash.
        """

        return ContentCDNHash(
            client=self._client,
            cdn_hash=cdn_hash
        )

__init__(client)

Parameters:

Name Type Description Default
client Client

The client object, which is passed to all objects this client generates.

required
Source code in roblox/delivery.py
118
119
120
121
122
123
def __init__(self, client: Client):
    """
    Arguments:
        client: The client object, which is passed to all objects this client generates.
    """
    self._client: Client = client

get_cdn_hash(cdn_hash)

Gets a Roblox CDN cdn_hash.

Parameters:

Name Type Description Default
cdn_hash str

The cdn_hash.

required

Returns:

Type Description
BaseCDNHash

A BaseCDNHash.

Source code in roblox/delivery.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def get_cdn_hash(self, cdn_hash: str) -> BaseCDNHash:
    """
    Gets a Roblox CDN cdn_hash.

    Arguments:
        cdn_hash: The cdn_hash.

    Returns:
        A BaseCDNHash.
    """

    return BaseCDNHash(
        client=self._client,
        cdn_hash=cdn_hash
    )

get_cdn_hash_from_url(url, site=cdn_site)

Parameters:

Name Type Description Default
url str

A CDN url.

required
site str

The site this cdn_hash is located at.

cdn_site

Returns:

Type Description
BaseCDNHash

The CDN cdn_hash for the supplied CDN URL.

Source code in roblox/delivery.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def get_cdn_hash_from_url(self, url: str, site: str = cdn_site) -> BaseCDNHash:
    """
    todo: turn this into something that actually splits into path.

    Arguments:
        url: A CDN url.
        site: The site this cdn_hash is located at.

    Returns:
        The CDN cdn_hash for the supplied CDN URL.
    """

    return self.get_cdn_hash(
        cdn_hash=url.split(f".{site}/")[1]
    )

get_content_cdn_hash(cdn_hash)

Gets a Roblox CDN cdn_hash.

Parameters:

Name Type Description Default
cdn_hash str

The cdn_hash.

required

Returns:

Type Description
ContentCDNHash

A ContentCDNHash.

Source code in roblox/delivery.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def get_content_cdn_hash(self, cdn_hash: str) -> ContentCDNHash:
    """
    Gets a Roblox CDN cdn_hash.

    Arguments:
        cdn_hash: The cdn_hash.

    Returns:
        A ContentCDNHash.
    """

    return ContentCDNHash(
        client=self._client,
        cdn_hash=cdn_hash
    )

get_thumbnail_cdn_hash(cdn_hash)

Gets a Roblox CDN cdn_hash.

Parameters:

Name Type Description Default
cdn_hash str

The cdn_hash.

required

Returns:

Type Description
ThumbnailCDNHash

A ThumbnailCDNHash.

Source code in roblox/delivery.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def get_thumbnail_cdn_hash(self, cdn_hash: str) -> ThumbnailCDNHash:
    """
    Gets a Roblox CDN cdn_hash.

    Arguments:
        cdn_hash: The cdn_hash.

    Returns:
        A ThumbnailCDNHash.
    """

    return ThumbnailCDNHash(
        client=self._client,
        cdn_hash=cdn_hash
    )

ThumbnailCDNHash

Bases: BaseCDNHash

Represents a CDN hash on tX.rbxcdn.com.

Source code in roblox/delivery.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class ThumbnailCDNHash(BaseCDNHash):
    """
    Represents a CDN hash on tX.rbxcdn.com.
    """

    def __init__(self, client: Client, cdn_hash: str):
        super().__init__(client=client, cdn_hash=cdn_hash)

    def get_url(self, site: str = cdn_site) -> str:
        """
        Returns this CDN hash's URL.
        """

        return self._get_url("t", cdn_site)

get_url(site=cdn_site)

Returns this CDN hash's URL.

Source code in roblox/delivery.py
88
89
90
91
92
93
def get_url(self, site: str = cdn_site) -> str:
    """
    Returns this CDN hash's URL.
    """

    return self._get_url("t", cdn_site)

get_cdn_number(cdn_hash)

Gets the number in the CDN where number represents X in tX.rbxcdn.com

Parameters:

Name Type Description Default
cdn_hash str

The CDN cdn_hash to generate a CDN number for.

required

Returns:

Type Description
int

The CDN number for the supplied cdn_hash.

Source code in roblox/delivery.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def get_cdn_number(cdn_hash: str) -> int:
    """
    Gets the number in the CDN where number represents X in tX.rbxcdn.com

    Arguments:
        cdn_hash: The CDN cdn_hash to generate a CDN number for.

    Returns: 
        The CDN number for the supplied cdn_hash.
    """
    i = 31
    for char in cdn_hash[:32]:
        i ^= ord(char)  # i ^= int(char, 16) also works
    return i % 8