Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Aug 9, 2024
2 parents 1f3162a + c4e6d52 commit 05a8d53
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ WORKDIR /usr/src/app

RUN apk add --no-cache git gcc g++ musl-dev libffi-dev openssl-dev file make

RUN git clone --depth 1 https://github.com/oldnapalm/zwift-offline
RUN mkdir -p ./zwift-offline
COPY ./ ./zwift-offline

COPY requirements.txt requirements.txt
RUN pip install --user --requirement requirements.txt
RUN pip install --user --requirement ./zwift-offline/requirements.txt
RUN pip install --user garth

FROM python:3.12-alpine
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ To obtain your current profile:
* Ensure zoffline is disabled.
* Run ``scripts/get_profile.py -u <your_zwift_username>``
* Or, if using the Windows zoffline.exe version without Python installed you can run ``get_profile.exe`` obtained from https://github.com/zoffline/zwift-offline/releases/tag/zoffline_helper in place of ``scripts/get_profile.py``
* Move the resulting ``profile.bin`` and ``achievements.bin`` (saved in whatever directory you ran get_profile.py in) into the ``storage/1`` directory.
* Move the resulting ``profile.bin``, ``achievements.bin`` and ``economy_config.txt`` (saved in whatever directory you ran get_profile.py in) into the ``storage/1`` directory.
* If using zoffline.exe on Windows, create a ``storage/1`` directory within the same folder as zoffline.exe if it does not already exist.
* If using Docker, the directory ``1`` should be in the path you passed to ``-v``

Expand Down
22 changes: 22 additions & 0 deletions online_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ def query(session, access_token, route):
print('HTTP Request failed: %s' % e)


def api_login(session, access_token, login_request):
try:
response = session.post(
url="https://us-or-rly101.zwift.com/api/users/login",
headers={
"Content-Type": "application/x-protobuf-lite",
"Accept": "application/x-protobuf-lite",
"Connection": "keep-alive",
"Host": "us-or-rly101.zwift.com",
"User-Agent": "Zwift/115 CFNetwork/758.0.2 Darwin/15.0.0",
"Authorization": "Bearer %s" % access_token,
"Accept-Language": "en-us",
},
data=login_request.SerializeToString(),
)

return response.content

except requests.exceptions.RequestException as e:
print('HTTP Request failed: %s' % e)


def logout(session, refresh_token):
# Logout
# POST https://secure.zwift.com/auth/realms/zwift/tokens/logout
Expand Down
2 changes: 1 addition & 1 deletion protobuf/login.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ message LoginResponse {
}

message LoginRequest {
required AnalyticsEventProperties properties = 1;
optional AnalyticsEventProperties properties = 1;
required bytes key = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion protobuf/login_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions scripts/get_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import os
import requests
import sys
sys.path.insert(0, '../protobuf')
import login_pb2
from google.protobuf.json_format import MessageToDict
from random import randbytes


if getattr(sys, 'frozen', False):
Expand Down Expand Up @@ -118,6 +122,33 @@ def query(session, access_token, route):
print('HTTP Request failed: %s' % e)


def api_login(session, access_token, login_request):
try:
response = session.post(
url="https://us-or-rly101.zwift.com/api/users/login",
headers={
"Content-Type": "application/x-protobuf-lite",
"Accept": "application/x-protobuf-lite",
"Connection": "keep-alive",
"Host": "us-or-rly101.zwift.com",
"User-Agent": "Zwift/115 CFNetwork/758.0.2 Darwin/15.0.0",
"Authorization": "Bearer %s" % access_token,
"Accept-Language": "en-us",
},
data=login_request.SerializeToString(),
verify=args.verifyCert,
)

if args.verbose:
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))

return response.content

except requests.exceptions.RequestException as e:
print('HTTP Request failed: %s' % e)


def logout(session, refresh_token):
# Logout
# POST https://secure.zwift.com/auth/realms/zwift/tokens/logout
Expand Down Expand Up @@ -203,6 +234,14 @@ def main(argv):
achievements = query(session, access_token, "achievement/loadPlayerAchievements")
with open('%s/achievements.bin' % SCRIPT_DIR, 'wb') as f:
f.write(achievements)
login_request = login_pb2.LoginRequest()
login_request.key = randbytes(16)
login_response = login_pb2.LoginResponse()
login_response.ParseFromString(api_login(session, access_token, login_request))
login_response_dict = MessageToDict(login_response, preserving_proto_field_name=True)
if 'economy_config' in login_response_dict:
with open('%s/economy_config.txt' % SCRIPT_DIR, 'w') as f:
json.dump(login_response_dict['economy_config'], f, indent=2)

logout(session, refresh_token)

Expand Down
2 changes: 1 addition & 1 deletion scripts/get_profile.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import sys
sys.modules['FixTk'] = None

a = Analysis(['get_profile.py'],
pathex=[],
pathex=['../protobuf'],
binaries=[],
datas=[],
hiddenimports=[],
Expand Down
10 changes: 10 additions & 0 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,16 @@ def profile(username):
backup_file(profile_file)
with open(profile_file, 'wb') as f:
f.write(profile)
login_request = login_pb2.LoginRequest()
login_request.key = random.randbytes(16)
login_response = login_pb2.LoginResponse()
login_response.ParseFromString(online_sync.api_login(session, access_token, login_request))
login_response_dict = MessageToDict(login_response, preserving_proto_field_name=True)
if 'economy_config' in login_response_dict:
economy_config_file = '%s/economy_config.txt' % profile_dir
backup_file(economy_config_file)
with open(economy_config_file, 'w') as f:
json.dump(login_response_dict['economy_config'], f, indent=2)
if request.form.get("achievements"):
achievements = online_sync.query(session, access_token, "achievement/loadPlayerAchievements")
achievements_file = '%s/achievements.bin' % profile_dir
Expand Down

0 comments on commit 05a8d53

Please sign in to comment.