Skip to content

Commit

Permalink
update client's downloader settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Jun 4, 2023
1 parent c642e36 commit 4fd1be7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions spotdl/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def connect(self):
await self.websocket.accept()

# Add the connection to the list of connections
app_state.clients.append(self)
app_state.clients[self.client_id] = self
app_state.logger.info("Client %s connected", self.client_id)

async def send_update(self, update: Dict[str, Any]):
Expand Down Expand Up @@ -183,9 +183,9 @@ def get_instance(cls, client_id: str) -> Optional["Client"]:
- returns the WebSocket instance.
"""

for instance in app_state.clients:
if instance.client_id == client_id:
return instance
instance = app_state.clients.get(client_id)
if instance:
return instance

app_state.logger.error("Client %s not found", client_id)

Expand All @@ -202,7 +202,7 @@ class ApplicationState:
loop: asyncio.AbstractEventLoop
web_settings: WebOptions
downloader_settings: DownloaderOptions
clients: List[Client] = []
clients: Dict[str, Client] = {}
logger: logging.Logger


Expand Down Expand Up @@ -257,9 +257,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: str):
while True:
await websocket.receive_json()
except WebSocketDisconnect:
instance = Client.get_instance(client_id)
if instance:
app_state.clients.remove(instance)
app_state.clients.pop(client_id, None)

if (
len(app_state.clients) == 0
Expand Down Expand Up @@ -460,6 +458,7 @@ def update_settings(
new_settings = DownloaderOptions(**settings_cpy) # type: ignore

# Re-initialize downloader
client.downloader_settings = new_settings
client.downloader = Downloader(
new_settings,
loop=state.loop,
Expand Down

0 comments on commit 4fd1be7

Please sign in to comment.