diff --git a/README.md b/README.md index b6a9cf8f..bf9df4dd 100644 --- a/README.md +++ b/README.md @@ -381,11 +381,11 @@ If github is not your cup of tea; > > >
-> Plex lables: +> Plex labels: > -> - To add automatic version and user lables to your downloaded content, navigate to '/Settings/Library Service/Library update service/Edit/' +> - To add automatic version and user labels to your downloaded content, navigate to '/Settings/Library Service/Library update service/Edit/' > - This requires a Plex library refresh to be set up aswell (see above). -> - Lables that will be added are: "From: ..." for each user that watchlisted this item, "Version: ..." for each version that was downloaded. +> - Labels that will be added are: "From: ..." for each user that watchlisted this item, "Version: ..." for each version that was downloaded. > >
> diff --git a/content/classes.py b/content/classes.py index 3d1ba45c..2349d2b5 100644 --- a/content/classes.py +++ b/content/classes.py @@ -1078,7 +1078,7 @@ def available(self): def collect(self, refresh_=True): for refresh_service in refresh(): if refresh_service.__module__ == self.__module__ or (self.__module__ in ["content.services.trakt", "releases", "content.services.overseerr", "content.services.plex"] and refresh_service.__module__ in ["content.services.plex", "content.services.jellyfin"]): - if refresh_ or refresh_service.name == "Plex Lables": + if refresh_ or refresh_service.name == "Plex Labels": refresh_service(self) elif self.__module__ in ["content.services.plex", "content.services.overseerr"] and refresh_service.__module__ == "content.services.trakt": try: diff --git a/content/services/plex.py b/content/services/plex.py index 20a73c20..4d2cf35d 100644 --- a/content/services/plex.py +++ b/content/services/plex.py @@ -529,7 +529,7 @@ def __new__(cls, element): class lable(classes.refresh): - name = 'Plex Lables' + name = 'Plex Labels' def setup(cls, new=False): ui_cls("Options/Settings/Library Services/Library update services") @@ -586,7 +586,7 @@ def call(element): retries += 1 library_item = next((x for x in current_library if element == x), None) if library_item == None: - ui_print('[plex] error: couldnt add lables - item: "' + element.query() + '" could not be found on server.') + ui_print('[plex] error: couldnt add labels - item: "' + element.query() + '" could not be found on server.') return tags_string = "" for tag in tags: @@ -598,7 +598,7 @@ def call(element): response = get(url) library_item.__dict__.update(response.MediaContainer.Metadata[0].__dict__) except Exception as e: - ui_print("[plex] error: couldnt add lables! Turn on debug printing for more info.") + ui_print("[plex] error: couldnt add labels! Turn on debug printing for more info.") ui_print(str(e), debug=ui_settings.debug) def __new__(cls, element): @@ -632,12 +632,12 @@ def __new__(cls, element): if len(tags) == 0: return element.post_tags = tags - ui_print('[plex] adding lables: "' + '","'.join(tags) + '" to item: "' + element.query() + '"') + ui_print('[plex] adding labels: "' + '","'.join(tags) + '" to item: "' + element.query() + '"') results = [None] t = Thread(target=multi_init, args=(library.lable.call, element, results, 0)) t.start() except Exception as e: - ui_print("[plex] error: couldnt add lables! Turn on debug printing for more info.") + ui_print("[plex] error: couldnt add labels! Turn on debug printing for more info.") ui_print(str(e), debug=ui_settings.debug) class ignore(classes.ignore): diff --git a/content/services/trakt.py b/content/services/trakt.py index 5af16aff..357d7804 100644 --- a/content/services/trakt.py +++ b/content/services/trakt.py @@ -4,9 +4,22 @@ from content import classes from ui.ui_print import * +from pydantic_settings import BaseSettings + +# Get Trakt oauth details from env +class Settings(BaseSettings): + client_id: str + client_secret: str + + class Config: + env_file = ".env" + env_file_encoding = "utf-8" + +trakt = Settings() + name = 'Trakt' -client_id = "0183a05ad97098d87287fe46da4ae286f434f32e8e951caad4cc147c947d79a3" -client_secret = "87109ed53fe1b4d6b0239e671f36cd2f17378384fa1ae09888a32643f83b7e6c" +client_id = trakt.client_id +client_secret = trakt.client_secret lists = [] users = [] current_user = ["", ""] @@ -169,9 +182,20 @@ def post(url, data): response = None return response +def post2(url, data): + try: + response = session.post(url, headers={ + 'Content-type': "application/json"}, data=data) + logerror(response) + response = json.loads(response.content, object_hook=lambda d: SimpleNamespace(**d)) + time.sleep(1.1) + except: + response = None + return response + def oauth(code=""): if code == "": - response = post('https://api.trakt.tv/oauth/device/code', json.dumps({'client_id': client_id})) + response = post2('https://api.trakt.tv/oauth/device/code', json.dumps({'client_id': client_id})) if not response == None: return response.device_code, response.user_code else: @@ -180,7 +204,7 @@ def oauth(code=""): else: response = None while response == None: - response = post('https://api.trakt.tv/oauth/device/token', json.dumps( + response = post2('https://api.trakt.tv/oauth/device/token', json.dumps( {'code': code, 'client_id': client_id, 'client_secret': client_secret})) time.sleep(1) return response.access_token diff --git a/requirements.txt b/requirements.txt index 8c94ee28..72b1d708 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ bs4==0.0.1 regex==2022.9.13 requests==2.28.1 six==1.16.0 +pydantic-settings \ No newline at end of file