├── .gitignore ├── LICENSE ├── README.md ├── requirements.txt ├── setup.py └── steamgrid ├── __init__.py ├── asset.py ├── author.py ├── enums.py ├── game.py ├── http.py └── steamgrid.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | venv* 110 | ENV/ 111 | env.bak/ 112 | venv.bak/ 113 | 114 | # Spyder project settings 115 | .spyderproject 116 | .spyproject 117 | 118 | # Rope project settings 119 | .ropeproject 120 | 121 | # mkdocs documentation 122 | /site 123 | 124 | # mypy 125 | .mypy_cache/ 126 | .dmypy.json 127 | dmypy.json 128 | 129 | # Pyre type checker 130 | .pyre/ 131 | 132 | test.py -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Zebco 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-steamgriddb 2 | A Python API wrapper for SteamGridDB.com 3 | 4 | [![PyPI](https://img.shields.io/pypi/v/python-steamgriddb?style=for-the-badge)](https://pypi.python.org/pypi/python-steamgriddb) 5 | ![APM](https://img.shields.io/apm/l/github?style=for-the-badge) 6 | 7 | ### Installation 8 | ```shell 9 | pip install -U python-steamgriddb 10 | ``` 11 | or 12 | ```shell 13 | pip install -U git+https://github.com/ZebcoWeb/python-steamgriddb.git 14 | ``` 15 | 16 | ## Getting Started 17 | #### Get your API key: 18 | [You can generate an API key on your user preferences page.](https://www.steamgriddb.com/profile/preferences) 19 | 20 | 21 | Initialize the SteamGridDB using your API key to connect with API 22 | ```python 23 | from steamgrid import SteamGridDB 24 | 25 | sgdb = SteamGridDB('AuthKey') 26 | ``` 27 | 28 | #### Search for a game: 29 | ```python 30 | # Search for Witcher game 31 | result = sgdb.search_game('Witcher') 32 | ``` 33 | 34 | #### Get a game object without searching: 35 | ```python 36 | # Get a game using a Game ID 37 | game = sgdb.get_game_by_gameid(1234) 38 | 39 | # Get a game using Steam App ID 40 | game = sgdb.get_game_by_steam_appid(567890) 41 | 42 | # Returning the game as JSONObject 43 | game.to_json() 44 | ``` 45 | 46 | #### Do something with a game object: 47 | ```python 48 | # Return the game name 49 | game_name = game.name 50 | 51 | # Return the game release date as datetime 52 | game_release_date = game.release_date 53 | ``` 54 | 55 | #### Get Assets: 56 | ```python 57 | from steamgrid import StyleType, PlatformType, MimeType, ImageType 58 | 59 | # Get grids list without filter 60 | grids = sgdb.get_grids_by_gameid([1234]) 61 | 62 | # Get grids list by filter (Multiple filters are allowed) 63 | grids = sgdb.get_grids_by_gameid(game_ids=[1234], styles=[StyleType.Alternate], mimes=[MimeType.PNG], types=[ImageType.Static], is_nsfw=True) 64 | 65 | # Get list grids using platform 66 | grids = sgdb.get_grids_by_platform(game_ids=[1234], platform=PlatformType.origin) 67 | ``` 68 | 69 | #### Do something with a grid object: 70 | ```python 71 | # Return object of grid's author 72 | grid_author = grid.author 73 | 74 | # Return grid's score 75 | grid_score = grid.score 76 | ``` 77 | 78 | #### Some grid object methods: 79 | ```python 80 | # Return true if grid be nsfw 81 | grid_is_nsfw = grid.is_nsfw() 82 | 83 | # Returning the grid as JSONObject 84 | grid.to_json() 85 | ``` 86 | 87 | #### Delete a grid 88 | ```python 89 | # Delete a grid with its object 90 | grid.delete() 91 | 92 | # Delete a grid with its ID 93 | sgdb.delete_grid([230227]) 94 | ``` 95 | 96 | ### Star History 97 | 98 | [![Star History Chart](https://api.star-history.com/svg?repos=ZebcoWeb/python-steamgriddb&type=Date)](https://star-history.com/#ZebcoWeb/python-steamgriddb&Date) 99 | 100 | ### Donate address: 101 | 102 | **BTC:** *bc1q8ngvcph2mwtlza8w452dxcjc08wgqa0pdnmndz* 103 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZebcoWeb/python-steamgriddb/a7fb9e006bb119893d5c2be48053bae4fb633efa/requirements.txt -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | 7 | setuptools.setup( 8 | name="python-steamgriddb", 9 | version="1.0.5", 10 | author="Zebco", 11 | author_email="zebco1382@gmail.com", 12 | description="A Python wrapper for SteamGridDB's API", 13 | long_description=long_description, 14 | long_description_content_type="text/markdown", 15 | url="https://github.com/ZebcoWeb/python-steamgriddb", 16 | packages=setuptools.find_packages(), 17 | license="MIT", 18 | keywords=['steamgriddb', 'steamgrid', 'steam', 'grid', 'db', 'api', 'wrapper'], 19 | install_requires=['requests'], 20 | classifiers=( 21 | "Programming Language :: Python :: 3", 22 | "License :: OSI Approved :: MIT License", 23 | "Operating System :: OS Independent", 24 | ), 25 | ) 26 | -------------------------------------------------------------------------------- /steamgrid/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | from .steamgrid import * 22 | from .enums import * 23 | from .asset import * 24 | from .game import * 25 | from .author import * -------------------------------------------------------------------------------- /steamgrid/asset.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | from typing import Tuple, Iterator, Any 22 | 23 | from .http import HTTPClient 24 | from .author import Author 25 | from .enums import AssetType 26 | 27 | __all__ = ( 28 | 'Grid', 29 | 'Hero', 30 | 'Logo', 31 | 'Icon', 32 | ) 33 | 34 | class Asset: 35 | """Base class for all assets. 36 | 37 | Depending on the way this object was created, some of the attributes can 38 | have a value of ``None``. 39 | 40 | .. container:: operations 41 | .. describe:: x == y 42 | Checks if two asset are the same. 43 | .. describe:: x != y 44 | Checks if two asset are not the same. 45 | .. describe:: iter(x) 46 | Returns an iterator of ``(field, value)`` pairs. This allows this class 47 | to be used as an iterable in list/dict/etc constructions. 48 | .. describe:: str(x) 49 | Returns a string representation of the asset. 50 | 51 | 52 | Attributes 53 | ----------- 54 | id: :class:`str` 55 | The asset's ID. 56 | author: :class:`Author` 57 | The author of the asset. 58 | score: :class:`int` 59 | The asset's score. 60 | width: :class:`int` 61 | The asset's width. 62 | height: :class:`int` 63 | The asset's width. 64 | style: :class:`str` 65 | The style of the asset. 66 | notes: Optional[:class:`str`] 67 | Notes about the asset. 68 | mime: :class:`str` 69 | The MIME type of the asset. 70 | language: :class:`str` 71 | The language of the asset. 72 | url: :class:`str` 73 | The URL of the asset. 74 | thumbnail: :class:`str` 75 | The URL of the asset's thumbnail. 76 | type: :class:`AssetType` 77 | The type of the asset. 78 | """ 79 | 80 | __slots__: Tuple[str, ...] = ( 81 | '_payload', 82 | '_http', 83 | 'id', 84 | 'score', 85 | 'width', 86 | 'height', 87 | 'style', 88 | '_nsfw', 89 | '_humor', 90 | 'notes', 91 | 'mime', 92 | 'language', 93 | 'url', 94 | 'thumbnail', 95 | '_lock', 96 | '_epilepsy', 97 | 'type', 98 | 'author' 99 | ) 100 | 101 | def __init__(self, payload: dict, type: AssetType, http: HTTPClient) -> None: 102 | self._payload = payload 103 | self._http = http 104 | self._from_data(payload) 105 | self.type = type 106 | 107 | def _from_data(self, asset: dict): 108 | self.id = asset.get('id') 109 | self.author: Author = Author(asset['author']) 110 | self.score = asset.get('score') 111 | self.width = asset.get('width') 112 | self.height = asset.get('height') 113 | self.style = asset.get('style') 114 | self._nsfw = asset.get('nsfw') 115 | self._humor = asset.get('humor') 116 | self.notes = asset.get('notes', None) 117 | self.mime = asset.get('mime') 118 | self.language = asset.get('language') 119 | self.url = asset.get('url') 120 | self.thumbnail = asset.get('thumb') 121 | self._lock = asset.get('lock') 122 | self._epilepsy = asset.get('epilepsy') 123 | self.upvotes = asset.get('upvotes') 124 | self.downvotes = asset.get('downvotes') 125 | 126 | def __str__(self) -> str: 127 | return self.url 128 | 129 | def __eq__(self, other) -> bool: 130 | return self.id == other.id 131 | 132 | def __ne__(self, other) -> bool: 133 | return self.id != other.id 134 | 135 | def __iter__(self) -> Iterator[Tuple[str, Any]]: 136 | for attr in self.__slots__: 137 | if attr[0] != '_': 138 | value = getattr(self, attr, None) 139 | if value is not None: 140 | yield (attr, value) 141 | 142 | def to_json(self) -> dict: 143 | return self._payload 144 | 145 | def is_lock(self) -> bool: 146 | """:class:`bool`: Returns whether the asset is locked.""" 147 | return self.lock 148 | 149 | def is_humor(self) -> bool: 150 | """:class:`bool`: Returns whether the asset is a humor asset.""" 151 | return self.humor 152 | 153 | def is_nsfw(self) -> bool: 154 | """:class:`bool`: Returns whether the asset is NSFW.""" 155 | return self.nsfw 156 | 157 | def is_epilepsy(self) -> bool: 158 | """:class:`bool`: Returns whether the asset is epilepsy-inducing.""" 159 | return self.is_epilepsy 160 | 161 | 162 | class Grid(Asset): 163 | def __init__(self, payload: dict, http: HTTPClient) -> None: 164 | super().__init__( 165 | payload, 166 | AssetType.Grid, 167 | http 168 | ) 169 | 170 | def __repr__(self) -> str: 171 | return f'' 172 | 173 | def delete(self) -> None: 174 | """Delete the grid.""" 175 | self._http.delete_grid([self.id]) 176 | 177 | class Hero(Asset): 178 | def __init__(self, payload: dict, http: HTTPClient) -> None: 179 | super().__init__( 180 | payload, 181 | AssetType.Hero, 182 | http 183 | ) 184 | 185 | def __repr__(self) -> str: 186 | return f'' 187 | 188 | def delete(self) -> None: 189 | """Delete the hero.""" 190 | self._http.delete_hero([self.id]) 191 | 192 | class Logo(Asset): 193 | def __init__(self, payload: dict, http: HTTPClient) -> None: 194 | super().__init__( 195 | payload, 196 | AssetType.Logo, 197 | http 198 | ) 199 | 200 | def __repr__(self) -> str: 201 | return f'' 202 | 203 | def delete(self) -> None: 204 | """Delete the logo.""" 205 | self._http.delete_logo([self.id]) 206 | 207 | class Icon(Asset): 208 | def __init__(self, payload: dict, http: HTTPClient) -> None: 209 | super().__init__( 210 | payload, 211 | AssetType.Icon, 212 | http 213 | ) 214 | 215 | def __repr__(self) -> str: 216 | return f'' 217 | 218 | def delete(self) -> None: 219 | """Delete the icon.""" 220 | self._http.delete_icon([self.id]) -------------------------------------------------------------------------------- /steamgrid/author.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | from typing import Iterator, Tuple, Any 22 | 23 | __all__ = ( 24 | 'Author', 25 | ) 26 | 27 | class Author: 28 | """Represents a custom author. 29 | 30 | Depending on the way this object was created, some of the attributes can 31 | have a value of ``None``. 32 | 33 | .. container:: operations 34 | .. describe:: x == y 35 | Checks if two author are the same. 36 | .. describe:: x != y 37 | Checks if two author are not the same. 38 | .. describe:: iter(x) 39 | Returns an iterator of ``(field, value)`` pairs. This allows this class 40 | to be used as an iterable in list/dict/etc constructions. 41 | .. describe:: str(x) 42 | Returns a string representation of the author. 43 | 44 | 45 | Attributes 46 | ----------- 47 | name: :class:`str` 48 | The name of the author. 49 | steam64: :class:`str` 50 | The author's steam64 ID. 51 | avatar: :class:`str` 52 | The author's avatar URL. 53 | 54 | """ 55 | 56 | __slots__: Tuple[str, ...] = ( 57 | '_payload', 58 | 'name', 59 | 'steam64', 60 | 'avatar', 61 | ) 62 | 63 | def __init__(self, payload: dict) -> None: 64 | self._payload = payload 65 | self._from_data(payload) 66 | 67 | def _from_data(self, author: dict): 68 | self.name = author.get('name') 69 | self.steam64 = author.get('steam64') 70 | self.avatar = author.get('avatar') 71 | 72 | def __str__(self) -> str: 73 | return self.name 74 | 75 | def __repr__(self) -> str: 76 | return f'' 77 | 78 | def __eq__(self, other) -> bool: 79 | return self.name == other.name 80 | 81 | def __ne__(self, other) -> bool: 82 | return self.name != other.name 83 | 84 | def __iter__(self) -> Iterator[Tuple[str, Any]]: 85 | for attr in self.__slots__: 86 | if attr[0] != '_': 87 | value = getattr(self, attr, None) 88 | if value is not None: 89 | yield (attr, value) 90 | 91 | def to_json(self) -> dict: 92 | """:class:`dict`: Returns a JSON-compatible representation of the author.""" 93 | return self._payload -------------------------------------------------------------------------------- /steamgrid/enums.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | from enum import Enum 22 | 23 | 24 | __all__ = [ 25 | 'PlatformType', 26 | 'StyleType', 27 | 'MimeType', 28 | 'ImageType', 29 | 'StylesIcon' 30 | ] 31 | 32 | class PlatformType(Enum): 33 | Steam = 'steam' 34 | Origin = 'origin' 35 | Egs = 'egs' 36 | Bnet = 'bnet' 37 | Uplay = 'uplay' 38 | Flashpoint = 'flashpoint' 39 | Eshop = 'eshop' 40 | 41 | def __str__(self) -> str: 42 | return self.name 43 | 44 | class StyleType(Enum): 45 | Alternate = 'alternate' 46 | Blurred = 'blurred' 47 | White_logo = 'white_logo' 48 | Material = 'material' 49 | No_logo = 'no_logo' 50 | 51 | def __str__(self) -> str: 52 | return self.name 53 | 54 | class MimeType(Enum): 55 | PNG = 'image/png' 56 | JPEG = 'image/jpeg' 57 | WEBP = 'image/webp' 58 | 59 | def __str__(self) -> str: 60 | return self.name 61 | 62 | class ImageType(Enum): 63 | Static = 'static ' 64 | Animated = 'animated' 65 | 66 | def __str__(self) -> str: 67 | return self.name 68 | 69 | class AssetType(Enum): 70 | Grid = 'grids' 71 | Hero = 'heroes' 72 | Logo = 'logoes' 73 | Icon = 'icons' 74 | 75 | def __str__(self) -> str: 76 | return self.name 77 | 78 | class StylesIcon(Enum): 79 | Official = 'official' 80 | Custom = 'custom' 81 | 82 | def __str__(self) -> str: 83 | return self.name -------------------------------------------------------------------------------- /steamgrid/game.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | from datetime import datetime 22 | from typing import Iterator, Tuple, Any 23 | 24 | __all__ = ( 25 | 'Game', 26 | ) 27 | 28 | class Game: 29 | """Represents a custom game. 30 | 31 | Depending on the way this object was created, some of the attributes can 32 | have a value of ``None``. 33 | 34 | .. container:: operations 35 | .. describe:: x == y 36 | Checks if two game are the same. 37 | .. describe:: x != y 38 | Checks if two game are not the same. 39 | .. describe:: iter(x) 40 | Returns an iterator of ``(field, value)`` pairs. This allows this class 41 | to be used as an iterable in list/dict/etc constructions. 42 | .. describe:: str(x) 43 | Returns a string representation of the game. 44 | 45 | 46 | Attributes 47 | ----------- 48 | name: :class:`str` 49 | The name of the game. 50 | id: :class:`int` 51 | The game's ID. 52 | types: List[:class:`str`] 53 | List of game types. 54 | verified: :class:`bool` 55 | Whether an game is verified or not. 56 | release_date: Optional[:class:`datetime`] 57 | The release date of the game. 58 | """ 59 | 60 | __slots__ = ( 61 | '_payload', 62 | 'id', 63 | 'name', 64 | 'types', 65 | 'verified', 66 | 'release_date', 67 | '_release_date' 68 | ) 69 | 70 | def __init__(self, payload: dict) -> None: 71 | self._payload = payload 72 | self._from_data(payload) 73 | 74 | def _from_data(self, game: dict): 75 | self.name = game.get('name') 76 | self.id = game.get('id') 77 | self.types = game.get('types') 78 | self.verified = game.get('verified') 79 | self._release_date = game.get('release_date', None) 80 | self.release_date = datetime.fromtimestamp(game['release_date']) if self._release_date else None 81 | 82 | def __str__(self) -> str: 83 | return self.name 84 | 85 | def __repr__(self) -> str: 86 | return f'' 87 | 88 | def __eq__(self, other) -> bool: 89 | return self.id == other.id 90 | 91 | def __ne__(self, other) -> bool: 92 | return self.id != other.id 93 | 94 | def __iter__(self) -> Iterator[Tuple[str, Any]]: 95 | for attr in self.__slots__: 96 | if attr[0] != '_': 97 | value = getattr(self, attr, None) 98 | if value is not None: 99 | yield (attr, value) 100 | 101 | def to_json(self) -> dict: 102 | """:class:`dict`: Returns a JSON-compatible representation of the author.""" 103 | return self._payload -------------------------------------------------------------------------------- /steamgrid/http.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | import requests 22 | from typing import List 23 | 24 | class HTTPException(Exception): 25 | """Exception raised when the HTTP request fails.""" 26 | pass 27 | 28 | class HTTPClient: 29 | 30 | BASE_URL = 'https://www.steamgriddb.com/api/v2' 31 | 32 | def __init__(self, auth_key: str): 33 | self.session = requests.Session() 34 | self.auth_key = auth_key 35 | self.session.headers.update({'Authorization': 'Bearer ' + self.auth_key}) 36 | 37 | def get(self, endpoint: str, queries: dict = None) -> dict: 38 | if queries: 39 | responce = self.session.get(endpoint, params=queries) 40 | else: 41 | responce = self.session.get(endpoint) 42 | 43 | try: 44 | payload = responce.json() 45 | except requests.exceptions.JSONDecodeError: 46 | raise Exception('Responce JSON Decode Error') 47 | 48 | if not payload['success']: 49 | error_context = payload['errors'][0] 50 | raise HTTPException(f'API Error: ({responce.status_code}) {error_context}') 51 | 52 | return payload['data'] if payload else None 53 | 54 | def post(self, endpoint: str, body: dict = None) -> dict: 55 | responce = self.session.post(endpoint, data=body) 56 | try: 57 | payload = responce.json() 58 | except requests.exceptions.JSONDecodeError: 59 | raise Exception('Responce JSON Decode Error') 60 | 61 | is_success = payload.get('success', None) 62 | if not is_success: 63 | error_context = payload['errors'][0] if payload else '' 64 | raise HTTPException(f'API Error: ({responce.status_code}) {error_context}') 65 | 66 | return payload['data'] if payload else None 67 | 68 | def delete(self, endpoint: str) -> dict: 69 | responce = self.session.delete(endpoint) 70 | try: 71 | payload = responce.json() 72 | except requests.exceptions.JSONDecodeError: 73 | raise Exception('Responce JSON Decode Error') 74 | 75 | if not payload['success']: 76 | error_context = payload['errors'][0] 77 | raise HTTPException(f'API Error: ({responce.status_code}) {error_context}') 78 | 79 | return payload['data'] if payload else None 80 | 81 | def get_game(self, game_id: int, request_type: str) -> dict: 82 | if request_type == 'steam': 83 | url = self.BASE_URL + '/games/steam/' + str(game_id) 84 | elif request_type == 'game': 85 | url = self.BASE_URL + '/games/id/' + str(game_id) 86 | 87 | return self.get(url) 88 | 89 | def get_grid( 90 | self, 91 | game_ids: List[int], 92 | request_type: str, 93 | platform: str = None, 94 | queries: dict = None 95 | ) -> List[dict]: 96 | if request_type == 'game': 97 | url = self.BASE_URL + '/grids/game/' + str(game_ids[0]) 98 | elif request_type == 'platform': 99 | url = self.BASE_URL + '/grids/' + platform + '/' + ','.join(str(i) for i in game_ids) 100 | 101 | return self.get(url, queries) 102 | 103 | def delete_grid(self, grid_ids: List[int]): 104 | url = self.BASE_URL + '/grids/' + ','.join(str(i) for i in grid_ids) 105 | self.delete(url) 106 | 107 | def get_hero( 108 | self, 109 | game_ids: List[int], 110 | request_type: str, 111 | platform: str = None, 112 | queries: dict = None 113 | ) -> List[dict]: 114 | if request_type == 'game': 115 | url = self.BASE_URL + '/heroes/game/' + str(game_ids[0]) 116 | elif request_type == 'platform': 117 | url = self.BASE_URL + '/heroes/' + platform + '/' + ','.join(str(i) for i in game_ids) 118 | 119 | return self.get(url, queries) 120 | 121 | def delete_hero(self, hero_ids: List[int]): 122 | url = self.BASE_URL + '/heroes/' + ','.join(str(i) for i in hero_ids) 123 | self.delete(url) 124 | 125 | def get_logo( 126 | self, 127 | game_ids: List[int], 128 | request_type: str, 129 | platform: str = None, 130 | queries: dict = None 131 | ) -> List[dict]: 132 | if request_type == 'game': 133 | url = self.BASE_URL + '/logos/game/' + str(game_ids[0]) 134 | elif request_type == 'platform': 135 | url = self.BASE_URL + '/logos/' + platform + '/' + ','.join(str(i) for i in game_ids) 136 | 137 | return self.get(url, queries) 138 | 139 | def delete_logo(self, logo_ids: List[int]): 140 | url = self.BASE_URL + '/logos/' + ','.join(str(i) for i in logo_ids) 141 | self.delete(url) 142 | 143 | def get_icon(self, game_ids: List[int], request_type: str, platform: str = None, queries: dict = None) -> List[dict]: 144 | if request_type == 'game': 145 | url = self.BASE_URL + '/icons/game/' + str(game_ids[0]) 146 | elif request_type == 'platform': 147 | url = self.BASE_URL + '/icons/' + platform + '/' + ','.join(str(i) for i in game_ids) 148 | 149 | return self.get(url, queries) 150 | 151 | def delete_icon(self, logo_ids: List[int]): 152 | url = self.BASE_URL + '/icons/' + ','.join(str(i) for i in logo_ids) 153 | self.delete(url) 154 | 155 | def search_games(self, term: str) -> List[dict]: 156 | url = self.BASE_URL + '/search/autocomplete/' + term 157 | 158 | return self.get(url) -------------------------------------------------------------------------------- /steamgrid/steamgrid.py: -------------------------------------------------------------------------------- 1 | """ 2 | The MIT License (MIT) 3 | Copyright (c) 2015-present Rapptz 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | DEALINGS IN THE SOFTWARE. 19 | """ 20 | 21 | from typing import List, Optional 22 | 23 | from .http import HTTPClient 24 | from .game import Game 25 | from .enums import ( 26 | StyleType, 27 | MimeType, 28 | ImageType, 29 | PlatformType, 30 | StylesIcon 31 | ) 32 | from .asset import * 33 | 34 | __all__ = ( 35 | 'SteamGridDB', 36 | ) 37 | 38 | class SteamGridDB: 39 | """Represents a custom author. 40 | 41 | Attributes 42 | ----------- 43 | auth_key: :class:`str` 44 | The auth key of the steamgriddb for authorization. 45 | 46 | """ 47 | 48 | __slots__ = ('_http') 49 | 50 | def __init__(self, auth_key: str) -> None: 51 | self._http = HTTPClient(auth_key) 52 | 53 | def auth_key(self) -> str: 54 | """:class:`str`: Returns the auth key of the steamgriddb. 55 | 56 | Returns 57 | -------- 58 | :class:`str` 59 | The auth key of the steamgriddb. 60 | """ 61 | return self._http.auth_key 62 | 63 | def get_game_by_gameid( 64 | self, 65 | game_id: int, 66 | ) -> Optional[Game]: 67 | """:class:`Game`: Returns a game by game id. 68 | 69 | Parameters 70 | ----------- 71 | game_id: :class:`int` 72 | The game id of the game. 73 | 74 | Raises 75 | -------- 76 | TypeError 77 | If the game_id is not an integer. 78 | HTTPException 79 | If the game_id is not found. 80 | 81 | Returns 82 | -------- 83 | :class:`Game` 84 | The game that was fetched. 85 | """ 86 | if not isinstance(game_id, int): 87 | raise TypeError('\'game_id\' must be an integer.') 88 | 89 | payload = self._http.get_game(game_id, 'game') 90 | return Game(payload) if payload != [] else None 91 | 92 | def get_game_by_steam_appid( 93 | self, 94 | app_id: int, 95 | ) -> Optional[Game]: 96 | """:class:`Game`: Returns a game by steam app id. 97 | 98 | Parameters 99 | ----------- 100 | app_id: :class:`int` 101 | The steam app id of the game. 102 | 103 | Raises 104 | -------- 105 | TypeError 106 | If the app_id is not an integer. 107 | HTTPException 108 | If the app_id is not found. 109 | 110 | Returns 111 | -------- 112 | :class:`Game` 113 | The game that was fetched. 114 | """ 115 | if not isinstance(app_id, int): 116 | raise TypeError('\'app_id\' must be an integer.') 117 | 118 | payload = self._http.get_game(app_id, 'steam') 119 | return Game(payload) if payload != [] else None 120 | 121 | def get_grids_by_gameid( 122 | self, 123 | game_ids: List[int], 124 | styles: List[StyleType] = [], 125 | mimes: List[MimeType] = [], 126 | types: List[ImageType] = [], 127 | is_nsfw: bool = False, 128 | is_humor: bool = False, 129 | ) -> Optional[List[Grid]]: 130 | """Optional[List[:class:`Grid`]] Returns a list of grids by game id. 131 | 132 | Parameters 133 | ----------- 134 | game_ids: List[:class:`int`] 135 | The game ids of the games. 136 | styles: List[:class:`StyleType`] 137 | The styles of the grids. Defaults to all styles. 138 | mimes: List[:class:`MimeType`] 139 | The mimes of the grids. Defaults to all mimes. 140 | types: List[:class:`ImageType`] 141 | The types of the grids. Defaults to all types. 142 | is_nsfw: :class:`bool` 143 | Whether or not the grids are NSFW. Defaults to False. 144 | is_humor: :class:`bool` 145 | Whether or not the grids are humor. Defaults to False. 146 | 147 | Raises 148 | -------- 149 | TypeError 150 | If one of the parameters is not of the correct type. 151 | HTTPException 152 | If the game_id is not found. 153 | 154 | Returns 155 | -------- 156 | Optional[List[:class:`Grid`]] 157 | The grids that were fetched. 158 | """ 159 | if not isinstance(game_ids, List): 160 | raise TypeError('\'game_ids\' must be a list of integers.') 161 | if not isinstance(styles, List): 162 | raise TypeError('\'styles\' must be a list of StyleType.') 163 | if not isinstance(mimes, List): 164 | raise TypeError('\'mimes\' must be a list of MimeType.') 165 | if not isinstance(types, List): 166 | raise TypeError('\'types\' must be a list of ImageType.') 167 | if not isinstance(is_nsfw, bool): 168 | raise TypeError('\'is_nsfw\' must be a boolean.') 169 | if not isinstance(is_humor, bool): 170 | raise TypeError('\'is_humor\' must be a boolean.') 171 | 172 | queries = { 173 | 'styles': ','.join(i.value for i in styles), 174 | 'mimes': ','.join(i.value for i in mimes), 175 | 'types': ','.join(i.value for i in types), 176 | 'nsfw': str(is_nsfw).lower(), 177 | 'humor': str(is_humor).lower(), 178 | } 179 | payloads = self._http.get_grid(game_ids, 'game', queries=queries) 180 | if payloads != []: 181 | return [Grid(payload, self._http) for payload in payloads] 182 | return None 183 | 184 | def get_grids_by_platform( 185 | self, 186 | game_ids: List[int], 187 | platform: PlatformType, 188 | styles: List[StyleType] = [], 189 | mimes: List[MimeType] = [], 190 | types: List[ImageType] = [], 191 | is_nsfw: bool = False, 192 | is_humor: bool = False, 193 | ) -> Optional[List[Grid]]: 194 | 195 | """Optional[List[:class:`Grid`]] Returns a list of grids by platform. 196 | 197 | Parameters 198 | ----------- 199 | game_ids: List[:class:`int`] 200 | The game ids of the games. 201 | platform: :class:`PlatformType` 202 | The platform type of the grids. 203 | styles: List[:class:`StyleType`] 204 | The styles of the grids. Defaults to all styles. 205 | mimes: List[:class:`MimeType`] 206 | The mimes of the grids. Defaults to all mimes. 207 | types: List[:class:`ImageType`] 208 | The types of the grids. Defaults to all types. 209 | is_nsfw: :class:`bool` 210 | Whether or not the grids are NSFW. Defaults to False. 211 | is_humor: :class:`bool` 212 | Whether or not the grids are humor. Defaults to False. 213 | 214 | Raises 215 | -------- 216 | TypeError 217 | If one of the parameters is not of the correct type. 218 | HTTPException 219 | If there is an error with the request. 220 | 221 | Returns 222 | -------- 223 | Optional[List[:class:`Grid`]] 224 | The grids that were fetched. 225 | """ 226 | if not isinstance(game_ids, List): 227 | raise TypeError('\'game_ids\' must be a list of integers.') 228 | if not isinstance(platform, PlatformType): 229 | raise TypeError('\'platform\' must be a PlatformType.') 230 | if not isinstance(styles, List): 231 | raise TypeError('\'styles\' must be a list of StyleType.') 232 | if not isinstance(mimes, List): 233 | raise TypeError('\'mimes\' must be a list of MimeType.') 234 | if not isinstance(types, List): 235 | raise TypeError('\'types\' must be a list of ImageType.') 236 | if not isinstance(is_nsfw, bool): 237 | raise TypeError('\'is_nsfw\' must be a boolean.') 238 | if not isinstance(is_humor, bool): 239 | raise TypeError('\'is_humor\' must be a boolean.') 240 | 241 | queries = { 242 | 'styles': ','.join(str(i) for i in styles), 243 | 'mimes': ','.join(str(i) for i in mimes), 244 | 'types': ','.join(str(i) for i in types), 245 | 'nsfw': str(is_nsfw).lower(), 246 | 'humor': str(is_humor).lower(), 247 | } 248 | 249 | payloads = self._http.get_grid( 250 | game_ids, 251 | 'platform', 252 | platform=platform.value, 253 | queries=queries 254 | ) 255 | if payloads != []: 256 | return [Grid(payload, self._http) for payload in payloads] 257 | return None 258 | 259 | def get_heroes_by_gameid( 260 | self, 261 | game_ids: List[int], 262 | styles: List[StyleType] = [], 263 | mimes: List[MimeType] = [], 264 | types: List[ImageType] = [], 265 | is_nsfw: bool = False, 266 | is_humor: bool = False, 267 | ) -> Optional[List[Hero]]: 268 | """Optional[List[:class:`Hero`]] Returns a list of heroes by game id. 269 | 270 | Parameters 271 | ----------- 272 | game_ids: List[:class:`int`] 273 | The game ids of the games. 274 | styles: List[:class:`StyleType`] 275 | The styles of the heroes. Defaults to all styles. 276 | mimes: List[:class:`MimeType`] 277 | The mimes of the heroes. Defaults to all mimes. 278 | types: List[:class:`ImageType`] 279 | The types of the heroes. Defaults to all types. 280 | is_nsfw: :class:`bool` 281 | Whether or not the heroes are NSFW. Defaults to False. 282 | is_humor: :class:`bool` 283 | Whether or not the heroes are humor. Defaults to False. 284 | 285 | Raises 286 | -------- 287 | TypeError 288 | If one of the parameters is not of the correct type. 289 | HTTPException 290 | If there is an error with the request. 291 | 292 | Returns 293 | -------- 294 | Optional[List[:class:`Hero`]] 295 | The heroes that were fetched. 296 | """ 297 | if not isinstance(game_ids, List): 298 | raise TypeError('\'game_ids\' must be a list of integers.') 299 | if not isinstance(styles, List): 300 | raise TypeError('\'styles\' must be a list of StyleType.') 301 | if not isinstance(mimes, List): 302 | raise TypeError('\'mimes\' must be a list of MimeType.') 303 | if not isinstance(types, List): 304 | raise TypeError('\'types\' must be a list of ImageType.') 305 | if not isinstance(is_nsfw, bool): 306 | raise TypeError('\'is_nsfw\' must be a boolean.') 307 | if not isinstance(is_humor, bool): 308 | raise TypeError('\'is_humor\' must be a boolean.') 309 | 310 | queries = { 311 | 'styles': ','.join(i.value for i in styles), 312 | 'mimes': ','.join(i.value for i in mimes), 313 | 'types': ','.join(i.value for i in types), 314 | 'nsfw': str(is_nsfw).lower(), 315 | 'humor': str(is_humor).lower(), 316 | } 317 | 318 | payloads = self._http.get_hero(game_ids, 'game', queries=queries) 319 | if payloads != []: 320 | return [Hero(payload, self._http) for payload in payloads] 321 | return None 322 | 323 | def get_heroes_by_platform( 324 | self, 325 | game_ids: List[int], 326 | platform: PlatformType, 327 | styles: List[StyleType] = [], 328 | mimes: List[MimeType] = [], 329 | types: List[ImageType] = [], 330 | is_nsfw: bool = False, 331 | is_humor: bool = False, 332 | ) -> Optional[List[Hero]]: 333 | """Optional[List[:class:`Hero`]] Returns a list of heroes by platform. 334 | 335 | Parameters 336 | ----------- 337 | game_ids: List[:class:`int`] 338 | The game ids of the games. 339 | platform: :class:`PlatformType` 340 | The platform type of the heroes. 341 | styles: List[:class:`StyleType`] 342 | The styles of the heroes. Defaults to all styles. 343 | mimes: List[:class:`MimeType`] 344 | The mimes of the heroes. Defaults to all mimes. 345 | types: List[:class:`ImageType`] 346 | The types of the heroes. Defaults to all types. 347 | is_nsfw: :class:`bool` 348 | Whether or not the heroes are NSFW. Defaults to False. 349 | is_humor: :class:`bool` 350 | Whether or not the heroes are humor. Defaults to False. 351 | 352 | Raises 353 | -------- 354 | TypeError 355 | If one of the parameters is not of the correct type. 356 | HTTPException 357 | If there is an error with the request. 358 | 359 | Returns 360 | -------- 361 | Optional[List[:class:`Hero`]] 362 | The heroes that were fetched. 363 | """ 364 | if not isinstance(game_ids, List): 365 | raise TypeError('\'game_ids\' must be a list of integers.') 366 | if not isinstance(platform, PlatformType): 367 | raise TypeError('\'platform\' must be a PlatformType.') 368 | if not isinstance(styles, List): 369 | raise TypeError('\'styles\' must be a list of StyleType.') 370 | if not isinstance(mimes, List): 371 | raise TypeError('\'mimes\' must be a list of MimeType.') 372 | if not isinstance(types, List): 373 | raise TypeError('\'types\' must be a list of ImageType.') 374 | if not isinstance(is_nsfw, bool): 375 | raise TypeError('\'is_nsfw\' must be a boolean.') 376 | if not isinstance(is_humor, bool): 377 | raise TypeError('\'is_humor\' must be a boolean.') 378 | 379 | queries = { 380 | 'styles': ','.join(str(i) for i in styles), 381 | 'mimes': ','.join(str(i) for i in mimes), 382 | 'types': ','.join(str(i) for i in types), 383 | 'nsfw': str(is_nsfw).lower(), 384 | 'humor': str(is_humor).lower(), 385 | } 386 | 387 | payloads = self._http.get_hero( 388 | game_ids, 389 | 'platform', 390 | platform=platform.value, 391 | queries=queries 392 | ) 393 | if payloads != []: 394 | return [Grid(payload, self._http) for payload in payloads] 395 | return None 396 | 397 | def get_logos_by_gameid( 398 | self, 399 | game_ids: List[int], 400 | styles: List[StyleType] = [], 401 | mimes: List[MimeType] = [], 402 | types: List[ImageType] = [], 403 | is_nsfw: bool = False, 404 | is_humor: bool = False, 405 | ) -> Optional[List[Logo]]: 406 | """Optional[List[:class:`Logo`]] Returns a list of logos by game id. 407 | 408 | Parameters 409 | ----------- 410 | game_ids: List[:class:`int`] 411 | The game ids of the games. 412 | styles: List[:class:`StyleType`] 413 | The styles of the logos. Defaults to all styles. 414 | mimes: List[:class:`MimeType`] 415 | The mimes of the logos. Defaults to all mimes. 416 | types: List[:class:`ImageType`] 417 | The types of the logos. Defaults to all types. 418 | is_nsfw: :class:`bool` 419 | Whether or not the logos are NSFW. Defaults to False. 420 | is_humor: :class:`bool` 421 | Whether or not the logos are humor. Defaults to False. 422 | 423 | Raises 424 | -------- 425 | TypeError 426 | If one of the parameters is not of the correct type. 427 | HTTPException 428 | If there is an error with the request. 429 | 430 | Returns 431 | -------- 432 | Optional[List[:class:`Logo`]] 433 | The logos that were fetched. 434 | """ 435 | if not isinstance(game_ids, List): 436 | raise TypeError('\'game_ids\' must be a list of integers.') 437 | if not isinstance(styles, List): 438 | raise TypeError('\'styles\' must be a list of StyleType.') 439 | if not isinstance(mimes, List): 440 | raise TypeError('\'mimes\' must be a list of MimeType.') 441 | if not isinstance(types, List): 442 | raise TypeError('\'types\' must be a list of ImageType.') 443 | if not isinstance(is_nsfw, bool): 444 | raise TypeError('\'is_nsfw\' must be a boolean.') 445 | if not isinstance(is_humor, bool): 446 | raise TypeError('\'is_humor\' must be a boolean.') 447 | 448 | queries = { 449 | 'styles': ','.join(i.value for i in styles), 450 | 'mimes': ','.join(i.value for i in mimes), 451 | 'types': ','.join(i.value for i in types), 452 | 'nsfw': str(is_nsfw).lower(), 453 | 'humor': str(is_humor).lower(), 454 | } 455 | 456 | payloads = self._http.get_logo(game_ids, 'game', queries=queries) 457 | if payloads != []: 458 | return [Logo(payload, self._http) for payload in payloads] 459 | return None 460 | 461 | def get_logos_by_platform( 462 | self, 463 | game_ids: List[int], 464 | platform: PlatformType, 465 | styles: List[StyleType] = [], 466 | mimes: List[MimeType] = [], 467 | types: List[ImageType] = [], 468 | is_nsfw: bool = False, 469 | is_humor: bool = False, 470 | ) -> Optional[List[Logo]]: 471 | """Optional[List[:class:`Logo`]] Returns a list of logos by platform. 472 | 473 | Parameters 474 | ----------- 475 | game_ids: List[:class:`int`] 476 | The game ids of the games. 477 | platform: :class:`PlatformType` 478 | The platform type of the logos. 479 | styles: List[:class:`StyleType`] 480 | The styles of the logos. Defaults to all styles. 481 | mimes: List[:class:`MimeType`] 482 | The mimes of the logos. Defaults to all mimes. 483 | types: List[:class:`ImageType`] 484 | The types of the logos. Defaults to all types. 485 | """ 486 | if not isinstance(game_ids, List): 487 | raise TypeError('\'game_ids\' must be a list of integers.') 488 | if not isinstance(platform, PlatformType): 489 | raise TypeError('\'platform\' must be a PlatformType.') 490 | if not isinstance(styles, List): 491 | raise TypeError('\'styles\' must be a list of StyleType.') 492 | if not isinstance(mimes, List): 493 | raise TypeError('\'mimes\' must be a list of MimeType.') 494 | if not isinstance(types, List): 495 | raise TypeError('\'types\' must be a list of ImageType.') 496 | if not isinstance(is_nsfw, bool): 497 | raise TypeError('\'is_nsfw\' must be a boolean.') 498 | if not isinstance(is_humor, bool): 499 | raise TypeError('\'is_humor\' must be a boolean.') 500 | 501 | queries = { 502 | 'styles': ','.join(str(i) for i in styles), 503 | 'mimes': ','.join(str(i) for i in mimes), 504 | 'types': ','.join(str(i) for i in types), 505 | 'nsfw': str(is_nsfw).lower(), 506 | 'humor': str(is_humor).lower(), 507 | } 508 | 509 | payloads = self._http.get_logo( 510 | game_ids, 511 | 'platform', 512 | platform=platform.value, 513 | queries=queries 514 | ) 515 | if payloads != []: 516 | return [Logo(payload, self._http) for payload in payloads] 517 | return None 518 | 519 | def get_icons_by_gameid( 520 | self, 521 | game_ids: List[int], 522 | styles: List[StylesIcon] = [], 523 | mimes: List[MimeType] = [], 524 | types: List[ImageType] = [], 525 | is_nsfw: bool = False, 526 | is_humor: bool = False, 527 | ) -> Optional[List[Icon]]: 528 | """Optional[List[:class:`Icon`]] Returns a list of icons by game id. 529 | 530 | Parameters 531 | ----------- 532 | game_ids: List[:class:`int`] 533 | The game ids of the games. 534 | styles: List[:class:`StyleType`] 535 | The styles of the icons. Defaults to all styles. 536 | mimes: List[:class:`MimeType`] 537 | The mimes of the icons. Defaults to all mimes. 538 | types: List[:class:`ImageType`] 539 | The types of the icons. Defaults to all types. 540 | is_nsfw: :class:`bool` 541 | Whether or not the icons are NSFW. Defaults to False. 542 | is_humor: :class:`bool` 543 | Whether or not the icons are humor. Defaults to False. 544 | 545 | Raises 546 | -------- 547 | TypeError 548 | If one of the parameters is not of the correct type. 549 | HTTPException 550 | If there is an error with the request. 551 | 552 | Returns 553 | -------- 554 | Optional[List[:class:`Icon`]] 555 | The icons that were fetched. 556 | """ 557 | if not isinstance(game_ids, List): 558 | raise TypeError('\'game_ids\' must be a list of integers.') 559 | if not isinstance(styles, List): 560 | raise TypeError('\'styles\' must be a list of StylesIcon.') 561 | if not isinstance(mimes, List): 562 | raise TypeError('\'mimes\' must be a list of MimeType.') 563 | if not isinstance(types, List): 564 | raise TypeError('\'types\' must be a list of ImageType.') 565 | if not isinstance(is_nsfw, bool): 566 | raise TypeError('\'is_nsfw\' must be a boolean.') 567 | if not isinstance(is_humor, bool): 568 | raise TypeError('\'is_humor\' must be a boolean.') 569 | 570 | queries = { 571 | 'styles': ','.join(i.value for i in styles), 572 | 'mimes': ','.join(i.value for i in mimes), 573 | 'types': ','.join(i.value for i in types), 574 | 'nsfw': str(is_nsfw).lower(), 575 | 'humor': str(is_humor).lower(), 576 | } 577 | 578 | payloads = self._http.get_icon(game_ids, 'game', queries=queries) 579 | if payloads != []: 580 | return [Icon(payload, self._http) for payload in payloads] 581 | return None 582 | 583 | def get_icons_by_platform( 584 | self, 585 | game_ids: List[int], 586 | platform: PlatformType, 587 | styles: List[StylesIcon] = [], 588 | mimes: List[MimeType] = [], 589 | types: List[ImageType] = [], 590 | is_nsfw: bool = False, 591 | is_humor: bool = False, 592 | ) -> Optional[List[Icon]]: 593 | """Optional[List[:class:`Icon`]] Returns a list of icons by platform. 594 | 595 | Parameters 596 | ----------- 597 | game_ids: List[:class:`int`] 598 | The game ids of the games. 599 | platform: :class:`PlatformType` 600 | The platform type of the icons. 601 | styles: List[:class:`StylesIcon`] 602 | The styles of the icons. Defaults to all styles. 603 | mimes: List[:class:`MimeType`] 604 | The mimes of the icons. Defaults to all mimes. 605 | types: List[:class:`ImageType`] 606 | The types of the icons. Defaults to all types. 607 | is_nsfw: :class:`bool` 608 | Whether or not the icons are NSFW. Defaults to False. 609 | is_humor: :class:`bool` 610 | Whether or not the icons are humor. Defaults to False. 611 | 612 | Raises 613 | -------- 614 | TypeError 615 | If one of the parameters is not of the correct type. 616 | HTTPException 617 | If there is an error with the request. 618 | 619 | Returns 620 | -------- 621 | Optional[List[:class:`Icon`]] 622 | The icons that were fetched. 623 | """ 624 | if not isinstance(game_ids, List): 625 | raise TypeError('\'game_ids\' must be a list of integers.') 626 | if not isinstance(platform, PlatformType): 627 | raise TypeError('\'platform\' must be a PlatformType.') 628 | if not isinstance(styles, List): 629 | raise TypeError('\'styles\' must be a list of StylesIcon.') 630 | if not isinstance(mimes, List): 631 | raise TypeError('\'mimes\' must be a list of MimeType.') 632 | if not isinstance(types, List): 633 | raise TypeError('\'types\' must be a list of ImageType.') 634 | if not isinstance(is_nsfw, bool): 635 | raise TypeError('\'is_nsfw\' must be a boolean.') 636 | if not isinstance(is_humor, bool): 637 | raise TypeError('\'is_humor\' must be a boolean.') 638 | 639 | queries = { 640 | 'styles': ','.join(str(i) for i in styles), 641 | 'mimes': ','.join(str(i) for i in mimes), 642 | 'types': ','.join(str(i) for i in types), 643 | 'nsfw': str(is_nsfw).lower(), 644 | 'humor': str(is_humor).lower(), 645 | } 646 | 647 | payloads = self._http.get_icon( 648 | game_ids, 649 | 'platform', 650 | platform=platform.value, 651 | queries=queries 652 | ) 653 | if payloads != []: 654 | return [Icon(payload, self._http) for payload in payloads] 655 | return None 656 | 657 | def delete_grid( 658 | self, 659 | grid_ids: List[int], 660 | ) -> None: 661 | """Deletes list of grid images from the website. 662 | 663 | Parameters 664 | ----------- 665 | grid_ids: List[:class:`int`] 666 | The grid ids to delete. 667 | 668 | Raises 669 | -------- 670 | TypeError 671 | If one of the parameters is not of the correct type. 672 | HTTPException 673 | If there is an error with the request. 674 | """ 675 | if not isinstance(grid_ids, List): 676 | raise TypeError('\'grid_ids\' must be a list of integers.') 677 | 678 | self._http.delete_grid(grid_ids) 679 | 680 | def delete_hero( 681 | self, 682 | hero_ids: List[int], 683 | ) -> None: 684 | """Deletes list of hero images from the website. 685 | 686 | Parameters 687 | ----------- 688 | hero_ids: List[:class:`int`] 689 | The hero ids to delete. 690 | 691 | Raises 692 | -------- 693 | TypeError 694 | If one of the parameters is not of the correct type. 695 | HTTPException 696 | If there is an error with the request. 697 | """ 698 | if not isinstance(hero_ids, List): 699 | raise TypeError('\'hero_ids\' must be a list of integers.') 700 | 701 | self._http.delete_hero(hero_ids) 702 | 703 | def delete_logo( 704 | self, 705 | logo_ids: List[int], 706 | ) -> None: 707 | """Deletes list of logo images from the website. 708 | 709 | Parameters 710 | ----------- 711 | logo_ids: List[:class:`int`] 712 | The logo ids to delete. 713 | 714 | Raises 715 | -------- 716 | TypeError 717 | If one of the parameters is not of the correct type. 718 | HTTPException 719 | If there is an error with the request. 720 | """ 721 | if not isinstance(logo_ids, List): 722 | raise TypeError('\'logo_ids\' must be a list of integers.') 723 | 724 | self._http.delete_logo(logo_ids) 725 | 726 | def delete_icon( 727 | self, 728 | icon_ids: List[int], 729 | ) -> None: 730 | """Deletes list of icon images from the website. 731 | 732 | Parameters 733 | ----------- 734 | icon_ids: List[:class:`int`] 735 | The icon ids to delete. 736 | 737 | Raises 738 | -------- 739 | TypeError 740 | If one of the parameters is not of the correct type. 741 | HTTPException 742 | If there is an error with the request. 743 | """ 744 | if not isinstance(icon_ids, List): 745 | raise TypeError('\'icon_ids\' must be a list of integers.') 746 | 747 | self._http.delete_icon(icon_ids) 748 | 749 | def search_game( 750 | self, 751 | term: str 752 | ) -> Optional[List[Game]]: 753 | """Searches for games on the website. 754 | 755 | Parameters 756 | ----------- 757 | term: :class:`str` 758 | The term to search for. 759 | 760 | Raises 761 | -------- 762 | TypeError 763 | If one of the parameters is not of the correct type. 764 | HTTPException 765 | If there is an error with the request. 766 | 767 | Returns 768 | -------- 769 | Optional[List[:class:`Game`]] 770 | The list of games that match the search term. 771 | """ 772 | if not isinstance(term, str): 773 | raise TypeError('\'term\' must be a string.') 774 | 775 | payloads = self._http.search_games(term) 776 | return [Game(payload) for payload in payloads] 777 | 778 | def set_auth_key( 779 | self, 780 | auth_key: str 781 | ) -> None: 782 | """Sets the new auth key for the API. 783 | 784 | Parameters 785 | ----------- 786 | auth_key: :class:`str` 787 | The new auth key to set. 788 | 789 | Raises 790 | -------- 791 | TypeError 792 | If one of the parameters is not of the correct type. 793 | HTTPException 794 | If there is an error with the request. 795 | ValueError 796 | If the auth key is not valid format. 797 | """ 798 | if not isinstance(auth_key, str): 799 | raise TypeError('\'auth_key\' must be a string.') 800 | if len(auth_key) != 32: 801 | raise ValueError('\'auth_key\' must be a 32-character string.') 802 | 803 | self._http.session.headers['Authorization'] = f'Bearer {auth_key}' --------------------------------------------------------------------------------