print("Uploader:") print("\tCode:", user.code) print("\tName:", user.name) print("\tCountry:", user.country) print("\tLast active:", user.last_active) # Download thumbnails def download_thumbnail(info, filename): response = store.get_req_get_info_headers_info(info.data_type) headers = {h.key: h.value for h in response.headers} data = requests.get(info.url, headers=headers).content with open(filename, "wb") as f: f.write(data) download_thumbnail(course.one_screen_thumbnail, "thumbnail_onescreen.jpg") download_thumbnail(course.entire_thumbnail, "thumbnail_entire.jpg") # Download level file param = datastore.DataStorePrepareGetParam() param.data_id = course.data_id req_info = store.prepare_get_object(param) data = requests.get(req_info.url).content with open("level.bin", "wb") as f: f.write(data) # Disconnect from game server backend.close()
async def main(): keys = KeySet.load(PATH_KEYS) info = ProdInfo(keys, PATH_PRODINFO) with open(PATH_TICKET, "rb") as f: ticket = f.read() cert = info.get_tls_cert() pkey = info.get_tls_key() dauth = DAuthClient(keys) dauth.set_certificate(cert, pkey) dauth.set_system_version(SYSTEM_VERSION) response = await dauth.device_token(dauth.BAAS) device_token = response["device_auth_token"] aauth = AAuthClient() aauth.set_system_version(SYSTEM_VERSION) response = await aauth.auth_digital(SMM2.TITLE_ID, SMM2.LATEST_VERSION, device_token, ticket) app_token = response["application_auth_token"] baas = BAASClient() baas.set_system_version(SYSTEM_VERSION) response = await baas.authenticate(device_token) access_token = response["accessToken"] response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token, app_token) user_id = int(response["user"]["id"], 16) id_token = response["idToken"] auth_info = authentication.AuthenticationInfo() auth_info.token = id_token auth_info.ngs_version = 4 #Switch auth_info.token_type = 2 s = settings.load("switch") s.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION) async with backend.connect(s, HOST, PORT) as be: async with be.login(str(user_id), auth_info=auth_info) as client: store = datastore.DataStoreClientSMM2(client) param = datastore.GetUserOrCourseParam() param.code = COURSE_ID param.course_option = datastore.CourseOption.ALL response = await store.get_user_or_course(param) course = response.course # Print information about the course print("Level info:") print("\tName:", course.name) print("\tDescription:", course.description) print("\tUploaded at:", course.upload_time) print("\tGame:", GameStyles[course.game_style]) print("\tTheme:", CourseThemes[course.course_theme]) print("\tDifficulty:", Difficulties[course.difficulty]) print("\tFirst tag:", TagNames[course.tag1]) print("\tSecond tag:", TagNames[course.tag2]) print("\tWorld record:", format_time(course.time_stats.world_record)) print("\tNumber of comments:", course.comment_stats[0]) # Request information about its uploader param = datastore.GetUsersParam() param.pids = [course.owner_id] response = await store.get_users(param) user = response.users[0] print("Uploader:") print("\tCode:", user.code) print("\tName:", user.name) print("\tCountry:", user.country) print("\tLast active:", user.last_active) # Download thumbnails await download_thumbnail(store, course.one_screen_thumbnail, "thumbnail_onescreen.jpg") await download_thumbnail(store, course.entire_thumbnail, "thumbnail_entire.jpg") # Download level file param = datastore.DataStorePrepareGetParam() param.data_id = course.data_id req_info = await store.prepare_get_object(param) response = await http.get(req_info.url) response.raise_if_error() with open("level.bin", "wb") as f: f.write(response.body)