GOG Galaxy 集成 Python API 使用教程

GOG Galaxy 集成 Python API 使用教程

galaxy-integrations-python-apiNOTE: Please report here only issues related to the python API. Issues and general feedback regarding the Galaxy Client 2.0 shall be sent via Galaxy Client menu项目地址:https://gitcode.com/gh_mirrors/ga/galaxy-integrations-python-api

1. 项目的目录结构及介绍

目录结构

galaxy-integrations-python-api/
├── galaxy/
│   └── api/
│       ├── __init__.py
│       ├── plugin.py
│       └── ...
├── examples/
│   └── my_integration/
│       ├── galaxy/
│       │   └── api/
│       │       └── plugin.py
│       ├── plugin.py
│       └── manifest.json
├── tests/
│   └── ...
├── .gitignore
├── LICENSE
├── README.md
└── setup.py

目录介绍

  • galaxy/: 包含核心API接口和插件类的实现。
  • examples/: 包含示例插件的实现,展示了如何使用API。
  • tests/: 包含测试文件,用于测试API和插件的功能。
  • .gitignore: Git忽略文件配置。
  • LICENSE: 项目许可证文件。
  • README.md: 项目说明文档。
  • setup.py: 项目安装脚本。

2. 项目的启动文件介绍

启动文件

在示例插件目录 examples/my_integration/ 中,启动文件是 plugin.py

启动文件内容

import sys
from galaxy.api.plugin import Plugin
from galaxy.api.consts import Platform
from galaxy.api.types import Authentication, Game, LicenseInfo, LicenseType

class PluginExample(Plugin):
    def __init__(self, reader, writer, token):
        super().__init__(Platform.Example, token)
        # 初始化插件

    def authenticate(self, stored_credentials=None):
        # 认证逻辑
        return Authentication("user_id", "username")

    def get_owned_games(self):
        # 获取拥有的游戏
        games = [
            Game("game_id", "Game Name", [], LicenseInfo(LicenseType.SinglePurchase))
        ]
        return games

def main():
    create_and_run_plugin(PluginExample, sys.argv)

if __name__ == "__main__":
    main()

启动文件介绍

  • PluginExample类: 继承自 galaxy.api.plugin.Plugin,实现了插件的主要逻辑。
  • authenticate方法: 实现用户认证逻辑。
  • get_owned_games方法: 获取用户拥有的游戏列表。
  • main函数: 创建并运行插件实例。

3. 项目的配置文件介绍

配置文件

在示例插件目录 examples/my_integration/ 中,配置文件是 manifest.json

配置文件内容

{
    "name": "My Integration",
    "author": "Author Name",
    "version": "1.0",
    "description": "A sample integration for GOG Galaxy 2.0",
    "platform": "example",
    "script": "plugin.py"
}

配置文件介绍

  • name: 插件名称。
  • author: 插件作者。
  • version: 插件版本。
  • description: 插件描述。
  • platform: 插件支持的平台。
  • script: 插件的入口脚本文件。

以上是基于开源项目 galaxy-integrations-python-api 的教程,包含了项目的目录结构、启动文件和配置文件的介绍。希望对你有所帮助。

galaxy-integrations-python-apiNOTE: Please report here only issues related to the python API. Issues and general feedback regarding the Galaxy Client 2.0 shall be sent via Galaxy Client menu项目地址:https://gitcode.com/gh_mirrors/ga/galaxy-integrations-python-api

  • 25
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

单迅秋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值