osu-api
osu-api copied to clipboard
Replay encoding.
As far as I get, I get the base64 string, I can decode it using a buffer.
now I need to save it, but I have to know the encoding for it to be saved correctly. think of; utf-8, ascii, or w/e
I tried utf-8 and Osu tells me it can't open the file.
My code (nodejs):
var tempFile = new Buffer(data.content);
var file_name = './temp/' + user_id + '_' + beatmap_id + '.osr';
return fs.writeFile(file_name, tempFile, 'utf-8', function(err){});
URL used:
https://osu.ppy.sh/api/get_replay?k=*key*&u=7159229&m=0&b=731428
Data received:
{"content":"XQAAIAB9JQAAAAAAAAAYHwJDUQO0AFVX2FOrBI1oDI0X\/6U2J65xw9mVdDG+I\/WKt2nCrOA19XkXfHctW4ofndJbiqbWd+sA7IPsYoA1IGN2c2098LzNRxw1Lm3b4b42NRGFVtVU2br0eOLlqM3y7SU1SorJiNeuDn\/MLBjxVkYhhptXqYi1Za8fgPt+PhGtmvhwvw9CmPrFvHq5UJX\/OK5B0lGdogfwts2UoVKOv0tVD4ErnQV9K1wxSNeheIxVazc6JJuOyFtSEQ2ev\/l5v5FzCwW9RSwUZCByOl8qHOjP9uhMhwdNoOKH2IKoZ63Frst3CCFgKbD0H8yG7BpacFogDhc3cN3APZNJolYv9+AXjk5NjvsvYCdTrWFOClua0hlt+riXNUSpMbRIm+7Nt3KPwO4u2CZWO7JvFb31goD5k7KaojckgEz3atguNztDLpMD8hqf6\/VQ9op2Asu4103Z\/lUt1ViBHR3xpk6LpEZDoHnHBRncGfFAIBdllwkFG0cDI\/lLd06dWajRaiF8\/FPrU7rSS+U8CqsecMALGc4qZoVij6N0c7L3Jes0j6ki3RrP9w\/+xBa+eEAvy1fEGBZ9gqKeNupkSJJzqWikkpVHJiie1J+FadAyzT0WnXRymp30jmjoWmmTpnq8ty5SPgylLKSlhBN1f6o8O9OmzC5cq6umH3iLTWJvZuM\/sjvnEU10h7lmd6lTJYkY47qRVhHv4XNgX91p2tekWwFZxPuVt25hqZ05foRzTVAB9en+Et3hkV314+VCp6mxvTod2BArvpleha5q5nysVFp5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OJ+H5RiRliAHwsJ0l+dCri8E6OzEEPsXPCY68LnsbVh2pvjVgbJ8uVh7d7vGlofinl8NbFItNmtAraOb3lVdW1\/tj6B7IyhDhsUy1EYZ7+oZMCMYx5ntQ+s28Q+TILHTOkxHbWhF4n7K0mF8QWnRzms7hnar0bJV7DbBalfw1zW4MBYA0vXXdu0j4JcqAA==","encoding":"base64"}
PS: No error is thrown when you put in a wrong beatmap id
There is no character set. You get a string of bytes from the base64 encoded string, and that is exactly what you save. You don't interpret the bytes as characters first.
On Sat, Nov 14, 2015 at 6:06 AM, HazeDevelopment [email protected] wrote:
As far as I get, I get the base64 string, I can decode it using a buffer.
now I need to save it, but I have to know the encoding for it to be saved correctly. think of; utf-8, ascii, or w/e
I tried utf-8 and Osu tells me it can't open the file.
— Reply to this email directly or view it on GitHub https://github.com/ppy/osu-api/issues/114.
Then how come it's unreadable by osu?
According to fs documentation, if a buffer is passed, no encoding to save is used
I just downloaded the replay of cptn_xn's score on four dimensions. Turns out, the received data was only around 3KB, which is much to short to be an actual replay. So this is not an encoding issue - the data is simply wrong.
On Sat, Nov 14, 2015 at 6:32 PM, HazeDevelopment [email protected] wrote:
According to fs documentation, if a buffer is passed, no encoding to save is used
— Reply to this email directly or view it on GitHub https://github.com/ppy/osu-api/issues/114#issuecomment-156721992.
according to https://osu.ppy.sh/wiki/Osr_(file_format)
we are missing a lot of data.
- Version of osu used
- Life bar graph
- Timestamp
just zero those out for now.
I have done some experimenting before and as far as I remember, the data received from decoding the base64-thing is only the last part of the osr-file: the "Compressed replay data" part. and accoring to that wiki-page:
The remaining data contains information about mouse movement and key presses in an wikipedia:LZMA stream.
So we have to lzma decode it to get the actual w | x | y | z
.
What I did was the following:
curl "https://osu.ppy.sh/api/get_replay?k=*key*&u=7159229&m=0&b=731428" | jq -r '.content' | base64 -d > test.txt.lzma
unlzma test.txt.lzma
The first line is some fancy bash-stuff that does the http-request, gets the content-part of the json-string, base64-decodes it and saves it to file test.txt.lzma
, the next line lzma-decodes that file saves it to file test.txt
which left me with test.txt with the following content:
0|256|-500|0,-1|256|-500|0,-658|296.4525|198.1008|0,13|294.7365|198.1008|0,19|293.0205|197.2428|0,13|293.0205|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,19|292.1625|197.2428|0,12|292.1625|197.2428|0,21|292.1625|197.2428|0,14|292.1625|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,17|292.1625|197.2428|0,18|292.1625|197.2428|0,12|292.1625|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,18|292.1625|197.2428|0,13|292.1625|197.2428|0,22|292.1625|197.2428|0,15|292.1625|197.2428|0,14|292.1625|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,17|292.1625|197.2428|0,13|292.1625|197.2428|0,17|292.1625|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,18|292.1625|197.2428|0,17|292.1625|197.2428|0,13|292.1625|197.2428|0,17|292.1625|197.2428|0,16|292.1625|197.2428|0,19|292.1625|197.2428|0,17|292.1625|197.2428|0,18|292.1625|197.2428|0,14|292.1625|197.2428|0,13|297.3105|201.5328|0,0|300.7425|204.9648|0,10|307.6064|210.1127|0,13|311.8964|212.6867|0,19|317.0443|214.4027|0,15|320.4763|216.1187|0,19|323.0504|216.9767|0,14|324.7664|216.9767|0,17|327.3403|216.9767|0,19|327.3403|216.9767|0,17|327.3403|216.9767|0,14|327.3403|216.9767|0,15|327.3403|216.9767|0,18|327.3403|216.9767|0,17|327.3403|216.9767|0,17|327.3403|216.9767|0,17|327.3403|216.9767|0,18|327.3403|216.9767|0,13|327.3403|216.9767|0,20|327.3403|216.9767|0,15|327.3403|216.9767|0,21|327.3403|216.9767|0,15|327.3403|216.9767|0,14|327.3403|216.9767|0,17|327.3403|216.9767|0,18|327.3403|216.9767|0,17|327.3403|216.9767|0,17|327.3403|216.9767|0,12|327.3403|216.9767|0,20|327.3403|216.9767|0,13|327.3403|216.9767|0,21|328.1983|215.2607|0,15|329.9143|214.4027|0,16|329.9143|213.5447|0,18|330.7723|211.8287|0,17|330.7723|210.9707|0,18|330.7723|210.1127|0,17|330.7723|210.1127|0,13|330.7723|210.1127|0,17|330.7723|210.1127|0,17|330.7723|210.1127|0,17|330.7723|210.1127|0,16|330.7723|210.1127|0,17|330.7723|210.1127|0,17|330.7723|210.1127|0,15|330.7723|210.1127|0,18|330.7723|210.1127|0,19|330.7723|210.1127|0,13|330.7723|210.1127|0,21|330.7723|209.2547|0,13|330.7723|209.2547|0,16|330.7723|209.2547|0,21|329.9143|209.2547|0,13|329.9143|210.1127|0,21|329.0563|210.9707|0,12|328.1983|210.9707|0,19|327.3403|212.6867|0,60|322.1923|221.2667|0,50|307.6064|259.0186|1,50|262.1326|309.6404|1,50|111.9825|328.5163|1,51|-10.71157|217.8343|1,50|117.9884|28.2163|1,49|420.8625|-30.12771|1,51|443.1704|108.0103|1,50|308.4642|297.6283|1,50|99.97031|275.3203|1,50|9.02233|86.5603|1,50|221.8063|15.34629|1,51|418.2883|213.5443|1,50|311.0383|382.5703|1,50|111.1244|343.9603|1,50|105.1183|139.7563|1,50|364.2344|147.4783|1,50|441.4544|355.1143|1,50|199.4984|410.5301|1,50|26.18236|226.06|1,50|189.2023|106.7981|1,50|305.8903|251.8|1,50|152.3083|392.5121|1,49|-9.853675|256.9481|1,51|58.78632|60.46603|1,50|317.0443|198.604|1,50|303.3162|400.234|1,49|61.36029|323.8719|1,51|19.31831|111.088|1,50|302.4585|128.248|1,50|357.3704|343.606|1,50|102.5444|394.228|1,50|57.07041|203.752|1,50|291.3043|135.9701|1,50|329.0563|298.132|1,50|67.3663|364.1982|1,50|23.60829|196.0301|1,50|328.1983|93.92816|1,50|382.2522|250.9422|1,50|149.7343|337.6002|1,51|9.022257|178.0121|1,50|228.6703|82.77415|1,50|507.5203|246.6521|1,49|377.1043|359.0502|1,50|136.0063|250.9422|1,51|272.4282|95.64425|1,50|487.7863|194.3142|1,50|353.0803|360.7662|1,49|137.7223|303.2801|1,51|274.1442|139.402|1,49|443.17|169.432|1,50|329.9141|330.7361|1,50|126.568|332.4521|1,50|238.966|188.308|1,50|410.5661|158.278|1,51|418.2881|316.1501|1,50|215.8002|364.1981|1,49|158.3142|236.3559|1,50|282.7242|118.81|1,50|424.2942|187.4499|1,49|356.5121|322.156|1,51|235.534|297.274|1,51|258.7|151.4138|1,49|371.0982|84.48985|1,51|426.01|224.3438|1,49|255.2681|311.0018|1,50|73.37214|173.7217|1,50|166.8941|41.58969|1,50|389.9741|143.6917|1,50|373.6721|319.5818|1,50|192.6342|310.1437|1,50|108.5502|132.5377|1,50|320.4763|51.88572|1,50|451.7502|187.4497|1,50|301.6002|298.1317|1,50|97.39622|205.4676|1,50|177.1902|47.59561|1,50|432.8742|112.8036|1,50|407.1342|259.5217|1,50|188.3444|274.9657|1,50|144.5864|129.9636|1,50|295.5945|43.30563|1,51|395.1225|175.4376|1,49|296.4524|286.1196|1,50|202.9305|198.6037|1,50|207.2205|52.74364|1,50|368.5245|89.63763|1,50|434.5905|242.3616|1,50|294.7365|284.4036|1,50|155.7406|154.8456|1,50|309.3226|57.89163|1,50|474.9166|181.4436|1,50|378.8206|305.8537|1,50|176.3326|255.2317|1,50|202.9306|109.3717|1,50|411.4245|128.2476|1,50|405.4185|276.6817|1,51|191.7766|296.4157|1,50|162.6046|141.1176|1,49|320.4766|71.61967|1,50|477.4905|218.3377|1,50|346.2166|330.7357|1,50|142.0128|213.1897|1,50|159.1728|80.19968|1,50|376.2467|123.0997|1,50|426.8687|280.1137|1,50|197.7827|317.0078|1,50|147.1607|154.8457|1,49|345.3585|62.18173|1,51|456.8986|215.7637|1,50|302.4586|348.7537|1,50|154.8826|263.8116|1,50|234.6766|101.6496|1,50|329.9147|141.1176|1,50|298.1686|305.8537|1,50|151.4505|317.0077|1,49|59.64456|188.3076|1,51|168.6105|113.6616|1,50|398.5546|202.0356|1,50|347.0746|320.4397|1,50|199.4986|286.1198|1,50|237.2506|158.2778|1,49|329.9145|159.1358|1,51|316.1865|287.8358|1,50|123.1365|305.8539|1,50|76.80447|172.8637|1,51|226.9545|95.64374|1,49|309.3225|215.7637|1,50|168.6105|299.8477|1,50|81.95245|221.7698|1,50|233.8184|122.2419|1,51|336.7784|196.8878|1,49|223.5224|307.5698|1,50|79.37839|258.6638|1,50|207.2203|120.5259|1,50|343.6423|143.6919|1,50|256.1263|284.4039|1,50|115.4143|299.8479|1,49|110.2663|178.012|1,50|264.7063|94.786|1,51|362.5182|197.746|1,50|272.4282|310.144|1,50|123.1362|267.244|1,50|166.8942|133.396|1,49|371.9561|151.414|1,51|350.5061|290.41|1,50|148.8762|317.0081|1,50|71.65622|175.4379|1,50|224.3802|85.34793|1,50|386.5421|203.7519|1,50|288.7301|320.44|1,51|117.1301|261.2379|1,50|153.1661|124.816|1,49|304.1742|141.9759|1,50|292.1622|269.8179|1,50|114.5562|274.9658|1,50|72.5142|147.9819|1,50|200.3562|99.07588|1,50|317.0442|215.7638|1,50|238.9662|296.4158|1,50|105.1182|241.5039|1,49|119.7042|111.0879|1,51|311.8961|112.8039|1,49|359.9441|243.2199|1,51|145.4442|301.5639|1,50|66.50825|180.5859|1,50|159.1722|45.87992|1,50|323.0502|111.9459|1,50|281.0081|238.9298|1,50|114.5562|244.9358|1,51|140.2962|117.9519|1,49|254.4102|58.74994|1,50|298.1679|166.858|1,50|241.54|280.1139|1,50|125.7099|267.2439|1,49|58.78592|138.5439|1,51|169.4679|56.17596|1,50|330.7719|140.2599|1,50|316.1859|244.9358|1,50|188.3437|267.2437|1,50|68.22379|190.8818|1,50|117.9878|70.76185|1,50|260.4158|66.47186|1,49|359.9438|164.2838|1,50|364.2338|214.0478|1,51|359.0858|218.3377|1,50|353.9378|217.4797|1,50|350.5059|216.6217|1,49|350.5059|216.6217|1,51|350.5059|216.6217|1,50|350.5059|216.6217|1,50|350.5059|216.6217|1,50|345.3579|219.1957|1,25|345.3579|219.1957|0,25|336.7779|222.6277|0,49|325.624|228.6337|0,50|316.186|232.0657|0,51|298.1681|243.2196|0,7|295.5941|245.7936|0,6|292.1622|247.5096|0,5|290.4462|248.3676|0,4|288.7302|249.2256|0,6|287.0142|251.7996|0,3|286.1562|251.7996|0,3|284.4402|253.5155|0,4|282.7242|253.5155|0,5|280.1502|255.2316|0,4|279.2922|256.0895|0,4|278.4342|256.9475|0,4|277.5762|257.8055|0,13|275.0023|258.6635|0,15|269.8543|262.0955|0,17|264.7063|263.8115|0,17|260.4163|267.2435|0,15|255.2684|270.6755|0,17|249.2624|273.2495|0,17|244.1144|275.8235|0,16|239.8244|277.5394|0,17|238.1084|278.3974|0,17|235.5345|278.3974|0,16|234.6765|279.2554|0,18|234.6765|279.2554|0,17|234.6765|279.2554|0,15|234.6765|279.2554|0,16|234.6765|279.2554|0,18|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,15|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,18|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,18|234.6765|279.2554|0,16|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,18|234.6765|279.2554|0,17|234.6765|279.2554|0,15|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,18|234.6765|279.2554|0,16|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,17|234.6765|279.2554|0,15|234.6765|279.2554|0,17|234.6765|279.2554|0,19|234.6765|279.2554|0,16|234.6765|279.2554|0,15|234.6765|279.2554|0,18|234.6765|279.2554|0,17|234.6765|279.2554|0,16|234.6765|279.2554|0,16|234.6765|279.2554|0,18|234.6765|279.2554|0,15|234.6765|279.2554|0,18|234.6765|279.2554|0,17|237.2504|280.1134|0,16|238.9664|280.9714|0,17|239.8244|281.8294|0,17|241.5404|284.4034|0,16|243.2564|286.1194|0,17|244.9724|288.6934|0,17|246.6884|291.2674|0,16|248.4044|292.9834|0,17|249.2624|293.8413|0,17|250.9784|294.6993|0,16|251.8364|295.5573|0,18|253.5524|295.5573|0,17|255.2684|296.4153|0,16|258.7003|297.2733|0,17|262.1323|297.2733|0,17|264.7063|298.9893|0,16|268.1383|298.9893|0,16|272.4283|298.9893|0,17|276.7182|298.9893|0,16|280.1502|297.2733|0,16|281.8662|297.2733|0,18|285.2982|296.4153|0,16|287.0142|295.5573|0,18|288.7302|294.6993|0,17|289.5882|294.6993|0,15|289.5882|294.6993|0,18|289.5882|294.6993|0,17|289.5882|294.6993|0,15|289.5882|294.6993|0,17|289.5882|294.6993|0,17|289.5882|294.6993|0,16|289.5882|294.6993|0,17|289.5882|294.6993|0,-12345|0|0|417540,
So there are two things to note here:
- The base64 decoded thing is in fact binary data: a lzma-stream which you have to decode! I have no clue if nodejs has an appropriate package to do that, but I wouldn't be surprised if there is.
- It does not contain an osr-file! If you want to save an osr-file, you'll have to get the other data of that file from somewhere else (
get_scores
?) and build the file according to the specs (note that inside the file it is actually lzma-encoded, so if the only thing you want to do is create that file, you dont have to worry about encoding/decoding lzma streams!)