Skip to content

delivery

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

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

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

        self._shared: ClientSharedObject = shared
        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._shared.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__(self, shared: ClientSharedObject, cdn_hash: str) special

Parameters:

Name Type Description Default
shared ClientSharedObject

The shared object.

required
cdn_hash str

The CDN hash as a string.

required
Source code in roblox/delivery.py
def __init__(self, shared: ClientSharedObject, cdn_hash: str):
    """
    Arguments:
        shared: The shared object.
        cdn_hash: The CDN hash as a string.
    """

    self._shared: ClientSharedObject = shared
    self.cdn_hash: str = cdn_hash

__repr__(self) special

Source code in roblox/delivery.py
def __repr__(self):
    return f"<{self.__class__.__name__} cdn_hash={self.cdn_hash}>"

get_cdn_number(self) -> int

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
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(self, site: str = 'rbxcdn.com') -> str

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.

'rbxcdn.com'

Returns:

Type Description
str

The computed URL from the given cdn_hash attribute.

Source code in roblox/delivery.py
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 (BaseCDNHash)

Represents a CDN hash on cX.rbxcdn.com.

Source code in roblox/delivery.py
class ContentCDNHash(BaseCDNHash):
    """
    Represents a CDN hash on cX.rbxcdn.com.
    """

    def __init__(self, shared: ClientSharedObject, cdn_hash: str):
        super().__init__(shared=shared, 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)

__init__(self, shared: ClientSharedObject, cdn_hash: str) special

Source code in roblox/delivery.py
def __init__(self, shared: ClientSharedObject, cdn_hash: str):
    super().__init__(shared=shared, cdn_hash=cdn_hash)

get_url(self, site: str = 'rbxcdn.com') -> str

Returns:

Type Description
str

This hash's URL.

Source code in roblox/delivery.py
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
class DeliveryProvider:
    """
    Provides CDN hashes and other delivery-related objects.
    """

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

    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(
            shared=self._shared,
            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(
            shared=self._shared,
            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(
            shared=self._shared,
            cdn_hash=cdn_hash
        )

__init__(self, shared: ClientSharedObject) special

Parameters:

Name Type Description Default
shared ClientSharedObject

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

required
Source code in roblox/delivery.py
def __init__(self, shared: ClientSharedObject):
    """
    Arguments:
        shared: The shared object, which is passed to all objects this client generates.
    """
    self._shared: ClientSharedObject = shared

get_cdn_hash(self, cdn_hash: str) -> BaseCDNHash

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
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(
        shared=self._shared,
        cdn_hash=cdn_hash
    )

get_cdn_hash_from_url(self, url: str, site: str = 'rbxcdn.com') -> BaseCDNHash

Parameters:

Name Type Description Default
url str

A CDN url.

required
site str

The site this cdn_hash is located at.

'rbxcdn.com'

Returns:

Type Description
BaseCDNHash

The CDN cdn_hash for the supplied CDN URL.

Source code in roblox/delivery.py
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(self, cdn_hash: str) -> ContentCDNHash

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
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(
        shared=self._shared,
        cdn_hash=cdn_hash
    )

get_thumbnail_cdn_hash(self, cdn_hash: str) -> ThumbnailCDNHash

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
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(
        shared=self._shared,
        cdn_hash=cdn_hash
    )

ThumbnailCDNHash (BaseCDNHash)

Represents a CDN hash on tX.rbxcdn.com.

Source code in roblox/delivery.py
class ThumbnailCDNHash(BaseCDNHash):
    """
    Represents a CDN hash on tX.rbxcdn.com.
    """

    def __init__(self, shared: ClientSharedObject, cdn_hash: str):
        super().__init__(shared=shared, 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)

__init__(self, shared: ClientSharedObject, cdn_hash: str) special

Source code in roblox/delivery.py
def __init__(self, shared: ClientSharedObject, cdn_hash: str):
    super().__init__(shared=shared, cdn_hash=cdn_hash)

get_url(self, site: str = 'rbxcdn.com') -> str

Returns this CDN hash's URL.

Source code in roblox/delivery.py
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: str) -> int

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
Source code in roblox/delivery.py
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