Skip to content

Commit

Permalink
try to pass oauth details to PD using env vars
Browse files Browse the repository at this point in the history
Signed-off-by: David Young <davidy@funkypenguin.co.nz>
  • Loading branch information
funkypenguin committed Jul 12, 2024
1 parent 3a3c858 commit c678fa1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ If github is not your cup of tea;
></details>
>
><details>
> <summary><b><u><img src="https://app.plex.tv/desktop/favicon.ico" height="16"> Plex lables:</u></b></summary>
> <summary><b><u><img src="https://app.plex.tv/desktop/favicon.ico" height="16"> Plex labels:</u></b></summary>
>
> - 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.
>
></details>
>
Expand Down
2 changes: 1 addition & 1 deletion content/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions content/services/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
32 changes: 28 additions & 4 deletions content/services/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["", ""]
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bs4==0.0.1
regex==2022.9.13
requests==2.28.1
six==1.16.0
pydantic-settings

0 comments on commit c678fa1

Please sign in to comment.