From 6efa62ced204cb70e092ad3187e0468b349e5cd1 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 17 Jan 2022 15:16:51 -0500 Subject: [PATCH] Ensure deviceId is unique and URL safe --- resources/lib/downloadutils.py | 8 ++++---- resources/lib/utils.py | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 833ae54..c1dfb7e 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -6,6 +6,7 @@ import xbmcaddon import requests import json +import hashlib from six.moves.urllib.parse import urlparse from base64 import b64encode from collections import defaultdict @@ -473,12 +474,11 @@ class DownloadUtils: log.debug("User NOT Authenticated") def get_auth_header(self, authenticate=True): - txt_mac = get_device_id() + device_id = get_device_id() version = get_version() client = 'Kodi JellyCon' settings = xbmcaddon.Addon() - username = settings.getSetting('username') device_name = settings.getSetting('deviceName') # remove none ascii chars device_name = py2_decode(device_name) @@ -492,12 +492,12 @@ class DownloadUtils: headers["Accept-Charset"] = "UTF-8,*" if authenticate is False: - auth_string = 'MediaBrowser Client="{}",Device="{}",DeviceId="{}{}",Version="{}'.format(client, device_name, txt_mac, username, version) + auth_string = 'MediaBrowser Client="{}",Device="{}",DeviceId="{}",Version="{}'.format(client, device_name, device_id, version) headers['X-Emby-Authorization'] = auth_string return headers else: userid = self.get_user_id() - auth_string = 'MediaBrowser UserId="{}",Client="{}",Device="{}",DeviceId="{}{}",Version="{}"'.format(userid, client, device_name, txt_mac, username, version) + auth_string = 'MediaBrowser UserId="{}",Client="{}",Device="{}",DeviceId="{}",Version="{}"'.format(userid, client, device_name, device_id, version) headers['X-Emby-Authorization'] = auth_string auth_token = self.authenticate() diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 904e774..b872ac4 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -13,6 +13,7 @@ import json import time import math import os +import hashlib from datetime import datetime import re from uuid import uuid4 @@ -113,10 +114,12 @@ def translate_string(string_id): def get_device_id(): window = HomeWindow() + username = window.get_property('username') client_id = window.get_property("client_id") + hashed_name = hashlib.md5(username.encode()).hexdigest() if client_id: - return client_id + return '{}-{}'.format(client_id, hashed_name) jellyfin_guid_path = py2_decode(xbmc.translatePath("special://temp/jellycon_guid")) log.debug("jellyfin_guid_path: {0}".format(jellyfin_guid_path)) @@ -135,7 +138,7 @@ def get_device_id(): log.debug("jellyfin_client_id: {0}".format(client_id)) window.set_property("client_id", client_id) - return client_id + return '{}-{}'.format(client_id, hashed_name) def get_version():