Skip to content

Commit 9a9a1c5

Browse files
authored
[Feat] Replace dependency on Apple with returned version from f-api (#154)
* [feat] Replace dependency on Apple with returned version from f-api * [Fix] Fix User-Agent version for imink
1 parent 149d240 commit 9a9a1c5

2 files changed

Lines changed: 33 additions & 72 deletions

File tree

client/api/__init__.py

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,39 @@
1313
import re
1414
import pickle
1515

16+
fTokenAPIURL = "https://api.imink.app"
17+
fTokenVersion = None
1618

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

26-
try:
27-
# Attempt to determine an alternative regex pattern with prefix
28-
version_without_space = re.compile(r'Version\s*(\d+\.\d+\.\d+)').search(html)
29-
if version_without_space:
30-
return version_without_space
31-
except Exception as e:
32-
print(f"Failed to determine alternative regex pattern with prefix: {e}")
20+
def getIminkNSOVersion():
21+
global fTokenVersion
22+
if fTokenVersion == None:
23+
route = '/config'
24+
response = requests.get(fTokenAPIURL + route)
25+
fTokenVersion = json.loads(response.text)['nso_version']
26+
return fTokenVersion
27+
return fTokenVersion
28+
3329

30+
def getPath(path):
3431
try:
35-
# Attempt to determine an alternative regex pattern without prefix
36-
version_no_prefix = re.compile(r'(\d+\.\d+\.\d+)').search(html)
37-
if version_no_prefix:
38-
return version_no_prefix
39-
except Exception as e:
40-
print(f"Failed to determine regex pattern without prefix: {e}")
41-
return None
32+
root = sys._MEIPASS
33+
except Exception:
34+
root = os.path.abspath('.')
35+
36+
return os.path.join(root, path)
37+
38+
39+
# Get Version Info
40+
try:
41+
with open(getPath('version.txt'), 'r') as file:
42+
versionTag = file.read().rstrip()
43+
try:
44+
versionTag = versionTag.split('-', 1)
45+
except ValueError:
46+
versionTag = [versionTag, '']
47+
except:
48+
versionTag = ['', '']
4249

4350

4451
def getAppPath():
@@ -87,23 +94,6 @@ def log(info, time = time.time()):
8794
return info
8895

8996

90-
def getVersion():
91-
for i in range(5):
92-
try:
93-
r = requests.get('https://apps.apple.com/us/app/nintendo-switch-online/id1234806557', timeout = 10)
94-
break
95-
except requests.RequestException as e:
96-
log(f'Failed to get Apple\'s store page. Retrying... Error: {str(e)}')
97-
else:
98-
log('Failed to get Apple\'s store page after multiple retries.')
99-
if r:
100-
version = getVersionRegex(r.text)
101-
if version:
102-
app_version = version.group(1)
103-
return app_version
104-
return ''
105-
106-
10797
client_id = '71b963c1b7b6d119'
10898
version = 0.3
10999
nsoAppVersion = None
@@ -124,11 +114,8 @@ def getVersion():
124114

125115
class API():
126116
def __init__(self, session_token, user_lang, targetID, version):
127-
version_match = getVersionRegex(version)
128-
if not version_match:
129-
raise Exception('missing app version')
130117
global nsoAppVersion
131-
nsoAppVersion = version_match.group(1)
118+
nsoAppVersion = getIminkNSOVersion()
132119
self.headers = {
133120
'X-ProductVersion': nsoAppVersion,
134121
'X-Platform': 'iOS',
@@ -267,7 +254,7 @@ def get(self):
267254
class imink():
268255
def __init__(self, na_id, id_token, timestamp, guid, iteration):
269256
self.headers = {
270-
'User-Agent': 'NSO-RPC/%s' % version,
257+
'User-Agent': 'NSO-RPC/%s' % "-".join(versionTag),
271258
'Content-Type': 'application/json; charset=utf-8',
272259
}
273260
self.body = {
@@ -276,7 +263,7 @@ def __init__(self, na_id, id_token, timestamp, guid, iteration):
276263
'na_id': na_id,
277264
}
278265

279-
self.url = 'https://api.imink.app'
266+
self.url = fTokenAPIURL
280267

281268
def get(self):
282269
log('Login from imink')

client/app.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020

2121
# NSO Variables
2222
session_token, user_lang, targetID = getToken(False)
23-
version = getVersion()
24-
while not version:
25-
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)
26-
if not ok:
27-
quit()
28-
if ok and not version:
29-
webbrowser.open('https://apps.apple.com/us/app/nintendo-switch-online/id1234806557')
23+
version = getIminkNSOVersion()
3024
try:
3125
client = Discord(session_token, user_lang, False, targetID, version)
3226
except Exception as e:
@@ -109,15 +103,6 @@
109103
# self.mode = 2 is for full
110104

111105

112-
def getPath(path):
113-
try:
114-
root = sys._MEIPASS
115-
except Exception:
116-
root = os.path.abspath('.')
117-
118-
return os.path.join(root, path)
119-
120-
121106
def loadPix(url):
122107
_pixmap = QPixmap()
123108
_pixmap.loadFromData(requests.get(url).content)
@@ -165,17 +150,6 @@ def timeSince(epoch: int):
165150
}
166151
userSelected = ''
167152

168-
# Get Version Info
169-
try:
170-
with open(getPath('version.txt'), 'r') as file:
171-
versionTag = file.read().rstrip()
172-
try:
173-
versionTag = versionTag.split('-', 1)
174-
except ValueError:
175-
versionTag = [versionTag, '']
176-
except:
177-
versionTag = ['', '']
178-
179153

180154
def writeSettings():
181155
try:

0 commit comments

Comments
 (0)