Skip to main content
 首页 » 编程设计

python之如何从 python 中的 steamID 获取 steamid 64

2025年04月02日13mayingbao

我有一个如下所示的 Steam IDS 列表:

STEAM_1:0:61759597 
STEAM_1:1:20263946 
STEAM_1:0:105065707 

对于你需要给它一个 steamID64 的所有对 steam API 的调用,它们看起来像这样:

76561198083784922 
76561198000793621 
76561198170397142 

Steam 页面显示了如何将 SteamID 转换为 SteamID64 的示例 https://developer.valvesoftware.com/wiki/SteamID

As a 64-bit integer 
Given the components of a Steam ID, a Steam ID can be converted to it's 64-bit integer form as follows:  
((Universe << 56) | (Account Type << 52) | (Instance << 32) | Account ID) 
Worked Example: 
Universe: Public (1) 
Account Type: Clan (7) 
Instance: 0 
Account ID: 4 
64-bit integer value: 103582791429521412 

我的问题是如何在 python 中实现它。我不明白这里发生了什么。

为了让我的问题更清楚,我想从 STEAM_1:0:61759597 开始解析 SteamID64,即 76561198083784922

我知道这是可能的,因为有很多网站都这样做: https://steamid.io/ , http://steamidfinder.com/ , https://steamid.co/

这么多问题是:这个算法是做什么的,我如何在 python 中实现它?

更新

这是我现在的代码,没有按预期工作:

steamID = "STEAM_1:0:61759597" 
X = int(steamID[6:7]) 
Y = int(steamID[8:9]) 
Z = int(steamID[10:]) 
 
#x is 1 
#y is 0 
#z is 61759597 
 
print(X,Y,Z) 
 
print((X << 56) | (Y << 52) | (Z << 32) | 4) 
#current output: 265255449329139716 
#desired output: 76561198083784922 

请您参考如下方法:

steam forum post 中有解释如何转换,我们只关心最后两个数字:

ID3 因此是 ID64 基数 (76561197960265728) 的偏移量,并且是帐号。 有史以来第一个帐户:(其 76561197960265728 + 1、76561197960265728 不存在)

    ID64 = 76561197960265728 + (B * 2) + A 
    ID3 = (B * 2) + A 
    ID32 = STEAM_0:A:B 

所以你只需要:

def to_steam64(s): 
    return ((b * 2) + a) + 76561197960265728 

要走相反的路线,从 steam64:

def from_steam64(sid): 
    y = int(sid) - 76561197960265728 
    x = y % 2  
    return "STEAM_0:{}:{}".format(x, (y - x) // 2) 

这是一个转换表here