好的,所以我决定我想要一个程序来下载基于地图编号的osu地图(因为没有更好的术语)。在对链接做了一些测试以理解重定向之后,我得到了一个进入.../download
页面的程序-当我到达上述页面时,地图将被下载。然而,当试图通过请求下载它时,我得到了HTML。你知道吗
def grab(self, identifier=None):
if not identifier:
print("Missing Argument: 'identifier'")
return
mapLink = f"https://osu.ppy.sh/beatmaps/{identifier}"
dl = requests.get(mapLink, allow_redirects=True)
if not dl:
print("Error: map not found!")
return
mapLink2 = dl.url
mapLink2 = f"https://osu.ppy.sh/beatmapsets/{self.parseLink(mapLink2)}/download"
dl = requests.get(mapLink2)
with open(f"{identifier}.osz", "wb") as f:
f.write(dl.content)
如果有必要,这里是self.parseLink
:
def parseLink(self, mapLink=None):
if not mapLink:
return None
id = mapLink.replace("https://osu.ppy.sh/beatmapsets/","")
id = id.split("#")
return id[0]
理想情况下,当我在grab()
末尾打开文件时,它应该保存一个可用的.osz
文件—一个不是html的文件,可以拖到实际的游戏中使用。当然,这在我的测试中还处于非常早期的阶段,为了方便起见,我将想出一种方法使文件名成为歌曲名。你知道吗
编辑:一个identifier
的例子是:OsuMaps().grab("1385415")
,以防您想要测试
有一种非常快速的方法:
此解决方法以
https://bloodcat.com/osu/
的形式出现—要直接获得地图的下载链接,您只需:https://bloodcat.com/osu/s/<beatmap set number>
。你知道吗举个例子:
行
if len(dl.conetent) > 330
是我的解决方法,指向一个不起作用的链接。.osz
文件可以包含成千上万行未知字符,而站点的“未找到”页面只有不到330行-我们可以用它来检查文件是否太短而不是beatmap。你知道吗就这些!如果您愿意,可以随意使用代码。你知道吗
相关问题 更多 >
编程相关推荐