Created
September 28, 2022 13:08
-
-
Save nekochanfood/ce9fa9bfa057db42822fd2c5f541a29c to your computer and use it in GitHub Desktop.
VRChatAPI to add worlds as favorites without a client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asyncio.windows_events import NULL | |
from http import cookies | |
from tkinter import TRUE | |
import requests | |
import pickle | |
import argparse | |
import os | |
import json | |
import sys | |
from requests.auth import HTTPBasicAuth | |
from getpass import getpass | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0'} | |
apiKey = "JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26" | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-type",default=NULL) | |
parser.add_argument("-id",default=NULL) | |
parser.add_argument("-tag",default=NULL) | |
parser.add_argument("--setup",action='store_true') | |
parser.add_argument("--reset",action='store_true') | |
args = parser.parse_args() | |
def main(): | |
# print(os.path.exists('cookies/auth_cookie.dump')) | |
# print(os.path.exists('cookies/totp_cookie.dump')) | |
if args.reset: | |
reset() | |
return | |
elif args.setup: | |
setup() | |
return | |
else: | |
IsValid = checkDump() | |
if IsValid == False: | |
doSetup = input("It looks like the setup has not been done yet. Would you like to do the setup? (Y/n): ") | |
if doSetup == "Y" and "y": | |
setup() | |
return | |
else: | |
variable_completion(args.type,args.id,args.tag) | |
return | |
def reset(): | |
doReset = input("Reset will require you to run the setup again. Do you still want to reset? (Y/n): ") | |
if doReset == "Y" and "y": | |
if os.path.exists('cookies/totp_cookie.dump') == True: | |
os.remove("cookies/totp_cookie.dump") | |
if os.path.exists('cookies/auth_cookie.dump') == True: | |
os.remove("cookies/auth_cookie.dump") | |
def checkDump(): | |
if os.path.exists('cookies/auth_cookie.dump') == False: | |
return False | |
if os.path.exists('cookies/totp_cookie.dump') == False: | |
return False | |
def setup(): | |
username = input("Username: ") | |
passwd = getpass("Password: ") | |
if os.path.exists('cookies') == False: | |
os.mkdir("cookies") | |
response = requests.get( | |
"https://api.vrchat.cloud/api/1/auth/user",headers=headers,auth=HTTPBasicAuth(username, passwd) | |
) | |
if response.status_code != 200: | |
print("There is a communication problem. Please try again." + " ("+ str(response.status_code) +")") | |
return | |
open('cookies/auth_cookie.dump', 'w') | |
with open('cookies/auth_cookie.dump', 'wb') as f: | |
pickle.dump(response.cookies, f) | |
print("\nAuth: " + str(response.status_code)) | |
auth_cookie = response.cookies | |
code = input("\n2FA Code: ") | |
response = requests.post( | |
"https://api.vrchat.cloud/api/1/auth/twofactorauth/totp/verify",headers=headers,cookies=auth_cookie,data={'code':code} | |
) | |
if response.status_code == 429: | |
print("Too many requests. Please give it some time to try." + " ("+ str(response.status_code) +")") | |
return | |
elif response.status_code != 200: | |
print("There is a communication problem. Please try again." + " ("+ str(response.status_code) +")") | |
return | |
open('cookies/totp_cookie.dump', 'w') | |
with open('cookies/totp_cookie.dump', 'wb') as f: | |
pickle.dump(response.cookies, f) | |
print("\n2FA: " + str(response.status_code)) | |
print("Setup has been completed.") | |
def variable_completion(type,id,tag): | |
if type == NULL: | |
type = "world" | |
if id == NULL: | |
while(True): | |
id = input("Please enter ID. (e.g. wrld_xxxxxxxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxxxxxxxx)\n> ") | |
if id != NULL: | |
break | |
if tag == NULL: | |
while(True): | |
int_tag = int(input("Please choose the Tag.\n\n1. worlds1\n2. worlds2\n3. worlds3\n4. worlds4\n\n> ")) | |
if int_tag == 1: | |
tag = "worlds1" | |
break | |
elif int_tag == 2: | |
tag = "worlds2" | |
break | |
elif int_tag == 3: | |
tag = "worlds3" | |
break | |
elif int_tag == 4: | |
tag = "worlds4" | |
break | |
else: | |
continue | |
Addfav(type,id,tag) | |
def Addfav(type,id,tag): | |
with open('cookies/auth_cookie.dump', 'rb') as f: | |
auth_cookie = pickle.load(f) | |
s = requests.session() | |
s.cookies.update(auth_cookie) | |
with open('cookies/totp_cookie.dump', 'rb') as f: | |
totp_cookie = pickle.load(f) | |
s = requests.session() | |
s.cookies.update(totp_cookie) | |
response = requests.post( | |
"https://api.vrchat.cloud/api/1/favorites",params={'apiKey':apiKey,'authToken':totp_cookie['twoFactorAuth']},headers=headers,cookies=auth_cookie,data={ | |
'type':type, | |
'favoriteId':id, | |
'tags':[ | |
tag | |
] | |
} | |
) | |
if response.status_code == 200: | |
print("successfully add \"" + id + "\" to " + str(tag) + "." + " ("+ str(response.status_code) +")") | |
elif response.status_code == 400: | |
print("The \"" + id + "\" is already add to " + str(tag) + " or something connection error." + " ("+ str(response.status_code) +")") | |
elif response.status_code == 403: | |
print("you trying adding favorite someone whom you are not friends with." + " ("+ str(response.status_code) +")") | |
main() | |
os.system('PAUSE') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
注意: main.pyと同じディレクトリでセットアップを行ってください