Skip to content

Commit

Permalink
Add the ability to specify a custom API server
Browse files Browse the repository at this point in the history
Fixes #193

Add the ability to specify a custom SponsorBlock API server. (draft implementation by copilot-workspace)

* Add a new configuration option `api_server` in `config.json.template` to specify the custom API server URL.
* Remove the hardcoded `SponsorBlock_api` URL from `src/iSponsorBlockTV/constants.py`.
* Update the `ApiHelper` class in `src/iSponsorBlockTV/api_helpers.py` to use the `api_server` configuration option for API calls.
* Add an option to input a custom API server URL in the CLI setup in `src/iSponsorBlockTV/config_setup.py`.
* Add an option to input a custom API server URL in the graphical setup wizard in `src/iSponsorBlockTV/setup_wizard.py`.
* Set the default `api_server` to "https://sponsor.ajay.app" in `src/iSponsorBlockTV/helpers.py`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/dmunozv04/iSponsorBlockTV/issues/193?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
dmunozv04 committed Oct 16, 2024
1 parent d9ab2cd commit 1567a33
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 200 deletions.
3 changes: 2 additions & 1 deletion config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
{"id": "",
"name": ""
}
]
],
"api_server": "https://sponsor.ajay.app"
}
5 changes: 3 additions & 2 deletions src/iSponsorBlockTV/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, config, web_session: ClientSession) -> None:
self.skip_count_tracking = config.skip_count_tracking
self.web_session = web_session
self.num_devices = len(config.devices)
self.api_server = config.api_server

# Not used anymore, maybe it can stay here a little longer
@AsyncLRU(maxsize=10)
Expand Down Expand Up @@ -130,7 +131,7 @@ async def get_segments(self, vid_id):
"service": constants.SponsorBlock_service,
}
headers = {"Accept": "application/json"}
url = constants.SponsorBlock_api + "skipSegments/" + vid_id_hashed
url = self.api_server + "/api/skipSegments/" + vid_id_hashed
async with self.web_session.get(
url, headers=headers, params=params
) as response:
Expand Down Expand Up @@ -201,7 +202,7 @@ async def mark_viewed_segments(self, uuids):
Lets the contributor know that someone skipped the segment (thanks)"""
if self.skip_count_tracking:
for i in uuids:
url = constants.SponsorBlock_api + "viewedVideoSponsorTime/"
url = self.api_server + "/api/viewedVideoSponsorTime/"
params = {"UUID": i}
await self.web_session.post(url, params=params)

Expand Down
Loading

0 comments on commit 1567a33

Please sign in to comment.