Skip to content

Commit

Permalink
[Feat] Replace dependency on Apple with returned version from f-api (#…
Browse files Browse the repository at this point in the history
…154)

* [feat] Replace dependency on Apple with returned version from f-api

* [Fix] Fix User-Agent version for imink
  • Loading branch information
HotaruBlaze committed Jun 2, 2024
1 parent 149d240 commit 9a9a1c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 72 deletions.
77 changes: 32 additions & 45 deletions client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,39 @@
import re
import pickle

fTokenAPIURL = "https://api.imink.app"
fTokenVersion = None

def getVersionRegex(html: str):
try:
# Attempt to determine the appropriate regex pattern with prefix
version_with_prefix = re.compile(r'Version\s*\s*(\d+\.\d+\.\d+)').search(html)
if version_with_prefix:
return version_with_prefix
except Exception as e:
print(f"Failed to determine regex pattern with prefix: {e}")

try:
# Attempt to determine an alternative regex pattern with prefix
version_without_space = re.compile(r'Version\s*(\d+\.\d+\.\d+)').search(html)
if version_without_space:
return version_without_space
except Exception as e:
print(f"Failed to determine alternative regex pattern with prefix: {e}")
def getIminkNSOVersion():
global fTokenVersion
if fTokenVersion == None:
route = '/config'
response = requests.get(fTokenAPIURL + route)
fTokenVersion = json.loads(response.text)['nso_version']
return fTokenVersion
return fTokenVersion


def getPath(path):
try:
# Attempt to determine an alternative regex pattern without prefix
version_no_prefix = re.compile(r'(\d+\.\d+\.\d+)').search(html)
if version_no_prefix:
return version_no_prefix
except Exception as e:
print(f"Failed to determine regex pattern without prefix: {e}")
return None
root = sys._MEIPASS
except Exception:
root = os.path.abspath('.')

return os.path.join(root, path)


# Get Version Info
try:
with open(getPath('version.txt'), 'r') as file:
versionTag = file.read().rstrip()
try:
versionTag = versionTag.split('-', 1)
except ValueError:
versionTag = [versionTag, '']
except:
versionTag = ['', '']


def getAppPath():
Expand Down Expand Up @@ -87,23 +94,6 @@ def log(info, time = time.time()):
return info


def getVersion():
for i in range(5):
try:
r = requests.get('https://apps.apple.com/us/app/nintendo-switch-online/id1234806557', timeout = 10)
break
except requests.RequestException as e:
log(f'Failed to get Apple\'s store page. Retrying... Error: {str(e)}')
else:
log('Failed to get Apple\'s store page after multiple retries.')
if r:
version = getVersionRegex(r.text)
if version:
app_version = version.group(1)
return app_version
return ''


client_id = '71b963c1b7b6d119'
version = 0.3
nsoAppVersion = None
Expand All @@ -124,11 +114,8 @@ def getVersion():

class API():
def __init__(self, session_token, user_lang, targetID, version):
version_match = getVersionRegex(version)
if not version_match:
raise Exception('missing app version')
global nsoAppVersion
nsoAppVersion = version_match.group(1)
nsoAppVersion = getIminkNSOVersion()
self.headers = {
'X-ProductVersion': nsoAppVersion,
'X-Platform': 'iOS',
Expand Down Expand Up @@ -267,7 +254,7 @@ def get(self):
class imink():
def __init__(self, na_id, id_token, timestamp, guid, iteration):
self.headers = {
'User-Agent': 'NSO-RPC/%s' % version,
'User-Agent': 'NSO-RPC/%s' % "-".join(versionTag),
'Content-Type': 'application/json; charset=utf-8',
}
self.body = {
Expand All @@ -276,7 +263,7 @@ def __init__(self, na_id, id_token, timestamp, guid, iteration):
'na_id': na_id,
}

self.url = 'https://api.imink.app'
self.url = fTokenAPIURL

def get(self):
log('Login from imink')
Expand Down
28 changes: 1 addition & 27 deletions client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@

# NSO Variables
session_token, user_lang, targetID = getToken(False)
version = getVersion()
while not version:
version, ok = QInputDialog.getText(MainWindow, 'Version Number', 'What is the current version of the Nintendo Switch Online Mobile app?\nThe App Store says it is %s (Please enter like X.X.X)\nEnter nothing and press Okay to be sent to the app store\'s website.' % version)
if not ok:
quit()
if ok and not version:
webbrowser.open('https://apps.apple.com/us/app/nintendo-switch-online/id1234806557')
version = getIminkNSOVersion()
try:
client = Discord(session_token, user_lang, False, targetID, version)
except Exception as e:
Expand Down Expand Up @@ -109,15 +103,6 @@
# self.mode = 2 is for full


def getPath(path):
try:
root = sys._MEIPASS
except Exception:
root = os.path.abspath('.')

return os.path.join(root, path)


def loadPix(url):
_pixmap = QPixmap()
_pixmap.loadFromData(requests.get(url).content)
Expand Down Expand Up @@ -165,17 +150,6 @@ def timeSince(epoch: int):
}
userSelected = ''

# Get Version Info
try:
with open(getPath('version.txt'), 'r') as file:
versionTag = file.read().rstrip()
try:
versionTag = versionTag.split('-', 1)
except ValueError:
versionTag = [versionTag, '']
except:
versionTag = ['', '']


def writeSettings():
try:
Expand Down

0 comments on commit 9a9a1c5

Please sign in to comment.