From 6d32c020dc839b4d778f8bd8723d187a2a5183c0 Mon Sep 17 00:00:00 2001 From: Mike Hill <88695244+gamichaelh@users.noreply.github.com> Date: Thu, 26 Aug 2021 21:12:07 -0400 Subject: [PATCH 1/2] Modularizing client_id Making the client_id for the API call a variable pulled from the config file, to avoid needing to modify the connection string directly in the code. --- config_example.ini | 1 + lib/locast_service.py | 10 +++++++--- lib/user_config.py | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config_example.ini b/config_example.ini index 17fd50a..860f5ff 100644 --- a/config_example.ini +++ b/config_example.ini @@ -3,6 +3,7 @@ plex_accessible_ip = 0.0.0.0 locast_username=username@example.com locast_password=1234567 +locast_clientid=api_client_id_here #disable_ssdp = False #plex_accessible_port = 6077 diff --git a/lib/locast_service.py b/lib/locast_service.py index 9655749..27bdffa 100644 --- a/lib/locast_service.py +++ b/lib/locast_service.py @@ -33,7 +33,7 @@ def __init__(self, location): @handle_url_except - def login(self, username, password): + def login(self, username, password, clientid): # check environment vars if (username is None): @@ -44,7 +44,11 @@ def login(self, username, password): print("Password not specified in config.ini. Exiting...") return False - # login + if (clientid is None): + print("ClientID Token not specified in config.ini. Exiting...") + return False + + # login print("Logging into Locast using username " + username + "...") # https://api.locastnet.org/api/user/login @@ -52,7 +56,7 @@ def login(self, username, password): # {"username":"thomas_vg1@hotmail.com","password":"xxxxxxxx"} - loginReq = urllib.request.Request('https://api.locastnet.org/api/user/login?client_id=9qXBrVzpTjUZmVGsZRnnWQ-7GvGeJ48QWtV9v%2Bbsen4%3D', + loginReq = urllib.request.Request('https://api.locastnet.org/api/user/login?client_id=' + clientid, ('{"username":"' + username + '","password":"' + password + '"}').encode("utf-8"), {'Content-Type': 'application/json', 'User-agent': self.DEFAULT_USER_AGENT}) diff --git a/lib/user_config.py b/lib/user_config.py index 14f789a..d9f5aa8 100644 --- a/lib/user_config.py +++ b/lib/user_config.py @@ -26,6 +26,7 @@ class UserConfig(): "cache_dir": None, "locast_username": None, "locast_password": None, + "locast_clientid": None, 'disable_ssdp': False, 'epg_update_frequency': 43200, # 12 hours 'epg_update_days': 7, From 0156abbc5b1604afb77ea9b6311ba58ffac501ce Mon Sep 17 00:00:00 2001 From: Mike Hill <88695244+gamichaelh@users.noreply.github.com> Date: Sat, 28 Aug 2021 13:21:12 -0400 Subject: [PATCH 2/2] Fixed errant spacing for comment. Fixed errant spacing for comment. --- lib/locast_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locast_service.py b/lib/locast_service.py index 27bdffa..8263088 100644 --- a/lib/locast_service.py +++ b/lib/locast_service.py @@ -48,7 +48,7 @@ def login(self, username, password, clientid): print("ClientID Token not specified in config.ini. Exiting...") return False - # login + # login print("Logging into Locast using username " + username + "...") # https://api.locastnet.org/api/user/login