How do i only sync watched status for my users? #2049
Replies: 3 comments 1 reply
-
I ended up doing the following.. Wrote a little script to get all your plex users and their token and output to config files for PlexTraktSync.. Copying here if anyone else wants it. import requests
import xml.etree.ElementTree as ET
import os
import yaml
PLEX_SERVER_URL = "http://x.x.x.x:32400"
PLEX_SERVER_ID = "xxxxxxx"
PLEX_SERVER_TOKEN = "xxxxx"
# Function to fetch and parse the XML
def fetch_xml(url):
response = requests.get(url)
if response.status_code == 200:
return ET.fromstring(response.content)
else:
raise Exception(f"Failed to fetch XML from {url}, status code: {response.status_code}")
# Function to create or update the server.yml file
def create_or_update_file(username, access_token):
base_dir = f"/config/traktsync/{username}"
if not os.path.exists(base_dir):
os.makedirs(base_dir)
file_path = os.path.join(base_dir, "server.yml")
# Load existing YAML content if file exists, otherwise use a template
if os.path.exists(file_path):
with open(file_path, 'r') as file:
config = yaml.safe_load(file)
else:
config = {"servers": {
"SFlix": {"token": "", "urls": [PLEX_SERVER_URL], "id": PLEX_SERVER_ID, "config": None}}}
# Update the access token in the config
config['servers']['SFlix']['token'] = access_token
# Write the YAML file back
with open(file_path, 'w') as file:
yaml.dump(config, file)
# Function to create or update the .env file
def create_or_update_env_file(username):
base_dir = f"/config/traktsync/{username}"
if not os.path.exists(base_dir):
os.makedirs(base_dir)
env_file_path = os.path.join(base_dir, ".env")
# Define the content of the .env file
env_content = f"""# This is .env file for PlexTraktSync
PLEX_USERNAME={username}
TRAKT_USERNAME=stevezau+{username}
PLEX_SERVER=SFlix
PLEX_OWNER_TOKEN=
PLEX_ACCOUNT_TOKEN=
"""
# Write or overwrite the .env file
with open(env_file_path, 'w') as file:
file.write(env_content)
def main():
url = f"https://plex.tv/api/servers/{PLEX_SERVER_ID}/shared_servers?X-Plex-Token={PLEX_SERVER_TOKEN}"
# Fetch and parse XML
xml_root = fetch_xml(url)
# Loop through each SharedServer element and process it
for server in xml_root.findall('SharedServer'):
username = server.attrib.get('username')
access_token = server.attrib.get('accessToken')
if username and access_token:
# Create or update the YAML configuration file
create_or_update_file(username, access_token)
# Create or update the .env file
create_or_update_env_file(username)
else:
print(f"Skipping invalid server entry with missing username or access token.")
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
-
Anyone able to help me here? I am trying to work out how to configure a docker container per user in my plex server.. but since i don't know the users plex credentials.. i cannot login with their plex user/pass.. I own the plex server thought so i should be able to access my users watch status.. Or, does this not support this use case? |
Beta Was this translation helpful? Give feedback.
-
PLEX_USERNAME is for informational purposes only. And plex-login uses to pre-fill you username when you log in again. |
Beta Was this translation helpful? Give feedback.
-
Hi, I am trying to setup a sync of watch status to trakt per each of my shared library users. I have setup a trakt account for each user.. now i am trying to setup PlexTraktSync container per user.
It is not clear in the documentation/readme on how i can do this. Well not to me anyway.
Am I correct that i'd need to login to each users plex account to generate a token, then because that token is associated to that user it will then only sync their watch status to their trakt ACC?
I don't know my users username/passwords, is there some other way to do this? I thought setting PLEX_USERNAME in .env would do it but it does not seem to work?
thanks for the help.
Beta Was this translation helpful? Give feedback.
All reactions