Git Product home page Git Product logo

plex-auto-languages's People

Contributors

beisem avatar buthed010203 avatar onedr0p avatar overlord360 avatar remirigal avatar saltydk avatar stavros-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

plex-auto-languages's Issues

Initial scan taking a long time... can we have a cache file?

The newest version of Plex-Auto-Languages does an initial scan of all episodes when it launches. According to the log it should take "a few seconds." I have close to 400k episodes in my library, and this scan takes upwards of 10 minutes. Would it be possible to cache some of this information so that a full scan isn't required every time it launches?

Managed Accounts

Doesn't seem to work with managed accounts ie, Plex Home users.

Issue on Container Startup

I'm having an issue when starting the container even though I wasn't in the past. I've changed no configurations in PAL inbetween.

2022-12-01 03:10:15,855 [INFO] Parsing config file '/config/config.yaml'
2022-12-01 03:10:15,878 [INFO] The provided configuration has been successfully validated
2022-12-01 03:10:15,880 [INFO] Starting scheduler
2022-12-01 03:10:16,534 [INFO] Successfully connected as user 'CardcaptorRLH85' (id: 1)
Traceback (most recent call last):
  File "main.py", line 118, in <module>
    plex_auto_languages.start()
  File "main.py", line 68, in start
    self.init()
  File "main.py", line 45, in init
    self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"), self.notifier, self.config)
  File "/app/plex_auto_languages/plex_server.py", line 110, in __init__
    self.cache = PlexServerCache(self)
  File "/app/plex_auto_languages/plex_server_cache.py", line 41, in __init__
    if not self._load():
  File "/app/plex_auto_languages/plex_server_cache.py", line 114, in _load
    cache = json.load(stream)
  File "/usr/local/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Only change the subtitle if the Subtitle language exists

Example:
Season 1
Available Languages: English
Season 2
Available Languages: English, Japanese

If you go to season to and change the subtitle language to Japanese it makes it so that Season 1 gets no subtitle language. It makes things a pain when you have different releases for some shows with multiple seasons. Ideally you'd be able to change the entire show's subtitles (and when you make a change in the season that's different it wouldn't wipe the old settings due to the language not existing.)

'latin-1' codec can't encode characters in position 1-2

not functional since the last update.

2023-03-06T12:55:49.812296623Z File "/usr/local/lib/python3.8/http/client.py", line 1229, in putheader
2023-03-06T12:55:49.812336342Z values[i] = one_value.encode('latin-1')
2023-03-06T12:55:49.812367402Z UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-2: ordinal not in range(256)
2023-03-06T12:55:54.817718296Z 2023-03-06 20:55:54,817 [ERROR] Unexpected error during connection to Plex
2023-03-06T12:55:54.818340333Z 2023-03-06 20:55:54,817 [ERROR] 'latin-1' codec can't encode characters in position 1-2: ordinal not in range(256)

Latest update broke for me

I just updated to the latest build posted. Now when I try to run, it crashes immediately with the following output:

Traceback (most recent call last):
  File "main.py", line 297, in <module>
    plex_auto_languages = PlexAutoLanguages(args.config_file)
  File "main.py", line 25, in __init__
    self.healthcheck_server = HealthcheckServer("Plex-Auto-Languages", self.is_ready, self.is_healthy)
  File "/app/utils/healthcheck.py", line 20, in __init__
    self._server = make_server("0.0.0.0", 80, self._app)
  File "/usr/local/lib/python3.8/site-packages/werkzeug/serving.py", line 849, in make_server
    return BaseWSGIServer(
  File "/usr/local/lib/python3.8/site-packages/werkzeug/serving.py", line 693, in __init__
    self.server_bind()
  File "/usr/local/lib/python3.8/http/server.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/local/lib/python3.8/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address in use

Ignored type of subtitle chosen ( favoured forced ), possibly malformed subtitles

Hi, I notice an unexpected behaviour in this situation:
In a certain TV Series the first episode has those subtitles
Screenshot from 2022-10-01 17-13-05
If I select the Italian srt, when I go to the second episode the subtitles selected track is the Italian forced one.

Screenshot from 2022-10-01 17-26-56

But I notice that the subtitles are little different each other, in the second episode, it has the "SUB ITA" description, it should be the problem, because if I set the subtitles in the second episode it will go ok with the next episodes

Is this behaviour already known? Thanks

Plex Token as Docker secret

Usually the standard is to provide a direct environment variable for the secret

secrets:
  plex_token:
    file: <docker_dir>/secrets/plex_token

plex-auto-languages:
    image: remirigal/plex-auto-languages:latest
    container_name: pal
    secrets:
      - plex_token
    environment:
      TZ: $TZ
      PLEX_URL: <plex_url>
      PLEX_TOKEN_FILE: /run/secrets/plex_token

This is minor, in my opinion, but would be better than assuming the filename/location.

More importantly I'm getting an error when using the token as described:

2022-04-25 07:28:40,124 [INFO] Setting value of parameter PLEX_URL from environment variable
2022-04-25 07:28:40,124 [INFO] Getting PLEX_TOKEN from Docker secret
2022-04-25 07:28:40,125 [INFO] The provided configuration has been successfully validated
Traceback (most recent call last):
  File "main.py", line 174, in <module>
    plex_auto_languages = PlexAutoLanguages(args.config_file)
  File "main.py", line 20, in __init__
    self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"))
  File "/usr/local/lib/python3.8/site-packages/plexapi/server.py", line 117, in __init__
    data = self.query(self.key, timeout=self._timeout)
  File "/usr/local/lib/python3.8/site-packages/plexapi/server.py", line 672, in query
    response = method(url, headers=headers, timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1297, in _send_request
    self.putheader(hdr, value)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 224, in putheader
    _HTTPConnection.putheader(self, header, *values)
  File "/usr/local/lib/python3.8/http/client.py", line 1234, in putheader
    raise ValueError('Invalid header value %r' % (values[i],))
ValueError: Invalid header value b'<plex_token_value>\n'

It seems it's perhaps not being parsed correctly from the file?

[ERROR] Unable to process playing

Lately I've been seeing a lot of errors in the logs that look like this:

2022-06-13 18:15:00,278 [ERROR] Unable to process playing
Traceback (most recent call last):
  File "/app/plex_auto_languages/plex_alert_handler.py", line 43, in __call__
    alert.process(self._plex)
  File "/app/plex_auto_languages/alerts/playing.py", line 45, in process
    user_plex = plex.get_plex_instance_of_user(user_id)
  File "/app/plex_auto_languages/plex_server.py", line 168, in get_plex_instance_of_user
    matching_users = [u for u in self.get_instance_users() if str(u.id) == str(user_id)]
  File "/app/plex_auto_languages/plex_server.py", line 155, in get_instance_users
    for user in self._plex.myPlexAccount().users():
  File "/usr/local/lib/python3.8/site-packages/plexapi/myplex.py", line 505, in users
    elem = self.query(MyPlexUser.key)
  File "/usr/local/lib/python3.8/site-packages/plexapi/myplex.py", line 183, in query
    raise BadRequest(message)
plexapi.exceptions.BadRequest: (502) bad_gateway; https://plex.tv/api/users/ <!DOCTYPE html> <html> <head>   <title>We're sorry, but something went wrong (500)</title> <link href="/assets/errors.css" media="screen" rel="stylesheet" type="text/css" />   <script type="text/javascript">     var _gaq = _gaq || [];     _gaq.push(['_setAccount', 'UA-6111912-23']);     _gaq.push(['_setDomainName', 'plex.tv']);     _gaq.push(['_trackPageview', '/500?url=' + window.location.pathname]);     (function() {       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;       ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);     })();   </script> </head>  <body>   <div class="block">     <div class="dialog">            <h1>Oops; a 500 error...</h1>       <h2>That's "Internal Server Error" in geeky language.</h2>       <p>We've been notified about this issue and will take a look at it shortly.<br/>          <a href="/">Let us take you to the main page</a> and we can start all over again, shall we?       </p>       <p>You can always visit <a href="https://status.plex.tv/">status.plex.tv</a> for current information. Thank you for your patience.</p>     </div>   </div> </body> </html> 

Please let me know any other info you might need.

[Enhancement] Add processing thread

The websocket thread listening for events is currently blocked during the requests to the Plex server, which can lead to loss of messages when the number of events and/or users is large.

The solution to tackle this issue would be to improve the way messages are handled by creating a new thread dedicated to HTTP requests.

Add health checks + kubernetes liveness/readiness probes

It would be great to have at least one HTTP endpoint that we can use for a health check at deployment.

Could be as simple as:

@app.route('/healthz')
def live():
  return "Live!"

@app.route('/readyz')
def ready():
  return "Ready!"

after config is loaded. (example is using flask)

PAL dies without connection to Plex

I know this feature was supposed to add resiliency if Plex is down - #40

But it seems like either there is a code bug or it still dies after a certain number of attempts:

last Thursday at 12:30:08 PM 2022-09-01 12:30:08,774 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:13 PM 2022-09-01 12:30:13,785 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:18 PM 2022-09-01 12:30:18,792 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:23 PM 2022-09-01 12:30:23,805 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:28 PM 2022-09-01 12:30:28,814 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:33 PM 2022-09-01 12:30:33,868 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:38 PM 2022-09-01 12:30:38,908 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:43 PM 2022-09-01 12:30:43,912 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:48 PM 2022-09-01 12:30:48,918 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:53 PM 2022-09-01 12:30:53,921 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:30:58 PM 2022-09-01 12:30:58,929 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:31:03 PM 2022-09-01 12:31:03,931 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:31:08 PM 2022-09-01 12:31:08,940 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
last Thursday at 12:31:13 PM Traceback (most recent call last):
last Thursday at 12:31:13 PM   File "main.py", line 110, in <module>
last Thursday at 12:31:13 PM     plex_auto_languages.start()
last Thursday at 12:31:13 PM   File "main.py", line 68, in start
last Thursday at 12:31:13 PM     self.init()
last Thursday at 12:31:13 PM   File "main.py", line 45, in init
last Thursday at 12:31:13 PM     self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"), self.notifier, self.config)
last Thursday at 12:31:13 PM   File "/app/plex_auto_languages/plex_server.py", line 98, in __init__
last Thursday at 12:31:13 PM     super().__init__(url, token)
last Thursday at 12:31:13 PM   File "/app/plex_auto_languages/plex_server.py", line 30, in __init__
last Thursday at 12:31:13 PM     self._plex = self._get_server(url, token)
last Thursday at 12:31:13 PM   File "/app/plex_auto_languages/plex_server.py", line 126, in _get_server
last Thursday at 12:31:13 PM     return BasePlexServer(url, token)
last Thursday at 12:31:13 PM   File "/usr/local/lib/python3.8/site-packages/plexapi/server.py", line 117, in __init__
last Thursday at 12:31:13 PM     data = self.query(self.key, timeout=self._timeout)
last Thursday at 12:31:13 PM   File "/usr/local/lib/python3.8/site-packages/plexapi/server.py", line 682, in query
last Thursday at 12:31:13 PM     raise BadRequest(message)
last Thursday at 12:31:13 PM plexapi.exceptions.BadRequest: (503) service_unavailable; http://plex:32400/ <?xml version="1.0" encoding="utf-8"?><Response code="503" title="Maintenance" status="PMS is currently running startup maintenance tasks."/>
yesterday at 4:30:03 AM Exception in thread Thread-2:
yesterday at 4:30:03 AM Traceback (most recent call last):
yesterday at 4:30:03 AM   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
yesterday at 4:30:03 AM     self.run()
yesterday at 4:30:03 AM   File "/app/plex_auto_languages/utils/scheduler.py", line 22, in run
yesterday at 4:30:03 AM     schedule.run_pending()
yesterday at 4:30:03 AM   File "/usr/local/lib/python3.8/site-packages/schedule/__init__.py", line 780, in run_pending
yesterday at 4:30:03 AM     default_scheduler.run_pending()
yesterday at 4:30:03 AM   File "/usr/local/lib/python3.8/site-packages/schedule/__init__.py", line 100, in run_pending
yesterday at 4:30:03 AM     self._run_job(job)
yesterday at 4:30:03 AM   File "/usr/local/lib/python3.8/site-packages/schedule/__init__.py", line 172, in _run_job
yesterday at 4:30:03 AM     ret = job.run()
yesterday at 4:30:03 AM   File "/usr/local/lib/python3.8/site-packages/schedule/__init__.py", line 661, in run
yesterday at 4:30:03 AM     ret = self.job_func()
yesterday at 4:30:03 AM   File "main.py", line 96, in scheduler_callback
yesterday at 4:30:03 AM     if self.plex or not self.plex.is_alive:
yesterday at 4:30:03 AM AttributeError: 'NoneType' object has no attribute 'is_alive'

Docker Unexpected connection lost to Plex

Hello,

I installed the docker yesterday but it seems that it's losing connection to the Plex server regularly.
Here's a snippet of the logs:

2022-05-26 11:59:29,538 [DEBUG] [Cache] Loading server cache from file
2022-05-26 11:59:29,593 [INFO] Starting alert listener
2022-05-26 11:59:29,594 [DEBUG] [Cache] Saving server cache to file
2022-05-26 11:59:29,637 [INFO] Stopping scheduler
2022-05-26 11:59:55,257 [INFO] Parsing config file '/config/config.yaml'
2022-05-26 11:59:55,280 [INFO] The provided configuration has been successfully validated
2022-05-26 11:59:55,281 [INFO] Starting scheduler
2022-05-26 12:00:25,288 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
2022-05-26 12:00:30,801 [INFO] Successfully connected as user '*****' (id: 1)
2022-05-26 12:00:30,803 [INFO] Scanning all episodes from the Plex library, this action should only take a few seconds but can take several minutes for larger libraries
2022-05-26 12:01:21,581 [INFO] Scanned 28933 episodes from the library
2022-05-26 12:01:21,581 [INFO] Starting alert listener
2022-05-26 12:02:51,674 [WARNING] Lost connection to the Plex server
2022-05-26 12:02:51,708 [INFO] Trying to restore the connection to the Plex server...
2022-05-26 12:03:21,743 [WARNING] ConnectionError: Unable to connect to Plex server, retrying...
2022-05-26 12:03:33,208 [WARNING] Alert listener had an unexpected error

It will only briefly have connection to the Plex server before having a Connection Error.
I'm not sure what I might have done wrong, I setup he docker image on windows 10 with the following command:
docker run -v "C:\docker config\autolangaugesplex":/config --name PlexAutoLanguages -e TZ=America/Toronto remirigal/plex-auto-languages:latest

And finally here are my config.yaml settings for the Plex URL:

  # Plex configuration
  plex:
    # A valid Plex URL (required)
    url: "http://192.168.2.39:32400/"
    # A valid Plex Token (required)
    token: "gWjbP3a4GeJVNFxq9-aY"

Logs.txt

Let me know if more details are required. Thanks!

Only works on web-based clients

I tried four clients so far and only the web-based ones work:

Web App: works
Windows App: works
iOS: doesn't work
Roku: doesn't work

Thanks!

Plex added something like this

Just wanted to say that plex just added something like this but I personally will continue to use plex auto languages as this is a more streamlined approach imo. Thank you for making this tool!

"All / Next" setting doesn't work

The setting doesn't work for me. It always changes all the episodes in the entire season/show even if I put "next" in the config file.

ModuleNotFoundError: No module named 'apprise'

I've tried running this in a venv, but it doesn't find apprise, even though all requirements are installed in the venv.
Also, does this have to run as sudo?

Any help much appreciated :)

(pal-venv) user@domain:~/Plex-Auto-Languages$ sudo python3 main.py ./default.config                                                              
Traceback (most recent call last): File "/home/user/Plex-Auto-Languages/main.py", line 6, in <module>
    from apprise import Apprise
ModuleNotFoundError: No module named 'apprise'

[Enhancement] Improve notification system

The current notification system can result in a lot of notifications for people having a lot of users on their servers.

Possible improvements:

  • As suggested in #26, notifications for newly added episodes should not be sent per-user.
  • Improve the configuration and add Apprise configs for specific users, something like this:
notifications:
  enable: true
  apprise_configs:
    - "spush://apikey"
    - urls:
        - "discord://webhook_id/webhook_token"
        - "pover://user@token"
      users:
        - "MyUsername"
        - "MyUser1"
    - urls:
        - "gotify://hostname/token"
      users:
        - "MyUser2"

I'm open to feedback and suggestions !

Don't log plex token

Upon launch, the app spits out the plex token in plain text. It would be great if it didn't do that, for obvious security reasons.

[INFO] Setting value of parameter PLEX_TOKEN to 'xxxxxxxxxxx' from environment variable

Error whenever I change subtitles on an episode

I'm trying to get Plex-Auto-Languages to work with my setup. I installed via Docker. Every time I turn on subtitles on an episode, the Docker logs show a crash/traceback. Here is the traceback:

2022-04-22 19:08:23,227 [ERROR] Unable to process play session
Traceback (most recent call last):
  File "main.py", line 57, in process_playing_message
    self.process_play_session(play_session)
  File "main.py", line 93, in process_play_session
    self.change_default_tracks_if_needed(item)
  File "main.py", line 145, in change_default_tracks_if_needed
    changes = PlexUtils.get_track_changes(episode, episodes)
  File "/app/utils/plex.py", line 107, in get_track_changes
    matching_audio_stream = PlexUtils.match_audio_stream(selected_audio_stream, part.audioStreams())
  File "/app/utils/plex.py", line 72, in match_audio_stream
    if reference.title <= stream.title:
TypeError: '<=' not supported between instances of 'NoneType' and 'str'

I should mention, although I installed via Docker, my Plex install is native. So in the config.yaml file, I used the reverse proxy URL for my Plex server. I'm not sure if this is a valid configuration.

[Feature Request] More flexibility for which notifications are sent

Right now, while you can choose which users to get notifications for, it will still send notifications in any event that PAL modifies languages/subs. This means that if it is watching for new episodes or file changes, any such event will trigger PAL which will then send a condensed notification that the episode was changed for all users. This isn't particularly useful and creates a lot of noise.

Ideally, there is a way to subscribe to only "active" triggers, e.g. plays or I guess any activity if so configured for the user. I would also want notifications for changes made during the scheduled run if enabled, but you could bifurcate those out if you want more flexibility as well. But from my usecase, the main goal is to suppress the new episode/file change notifications

Thanks!

Forced Subtitles being reset

I noticed that when I grabbed the Boys, with PAL set to work on new files and episodes, it seems to have reset the forced subtitles and turned them off. I believe Plex sets Forced Subs on by default, so this seems like it is happening due to PAL's behavior of setting default tracks for new items.

EDIT: I think this might be related to #17 ? If the first episode did not have a forced subtitle track, then does PAL set preferences to no subs for all subsequent episodes? If a future episode does have that track then, it will be deselected because the preferences were determined by the first episode's tracks?

Cannot run on FreeBSD

Currently this cannot be ran on FreeBSD as in get_data_directory() in the file plex_auto_languages/utils/configuration.py will return a None object as sys.platform will return freebsd13 which does not match any of the current checks

[ERROR] Unable to process status

image

Running within a docker container using the following config.yaml (pretty close to default -- no major changes). Anyone else come across the error noted in the screenshot?

plexautolanguages:
  # Update language for the entire show or only for the current season
  # Accepted values:
  #   - show (default)
  #   - season
  update_level: "show"

  # Update all episodes of the show/season or only the next ones
  # Accepted values:
  #   - all (default)
  #   - next
  update_strategy: "all"

  # Whether or not playing a file should trigger a language update, defaults to 'true'
  trigger_on_play: true

  # Whether or not scanning the library for new files should trigger a language update, defaults to 'true'
  # A newly added episode will be updated based on the most recently watched episode, or the first episode of the show if it has never been watched
  trigger_on_scan: true

  # Whether or not navigating the Plex library should trigger a language update, defaults to 'false'
  # Only the Plex web client and the Plex for Windows app support this feature
  # Set this to 'true' only if you want to perform changes whenever the default track of an episode is updated, even when the episode is not played.
  # Setting this parameter to 'true' can result in higher resource usage.
  trigger_on_activity: false

  # Whether or not to refresh the cached library whenever the Plex server scans its own library, defaults to 'true'
  # Disabling this parameter will prevent PlexAutoLanguages from detecting updated files for an already existing episode
  # It is recommended to disable this parameter if you have a large TV Show library (10k+ episodes)
  refresh_library_on_scan: true

  # Plex configuration
  plex:
    # A valid Plex URL (required)
    url: "local_plex_url_here"
    # A valid Plex Token (required)
    token: "token_here"

  scheduler:
    # Whether of not to enable the scheduler, defaults to 'true'
    # The scheduler will perform a deeper analysis of all recently played TV Shows
    enable: true
    # The time at which the scheduler start its task with the format 'HH:MM', defaults to '02:00'
    schedule_time: "01:00"

#  notifications:
#    # Whether or not to enable the notifications through Apprise, defaults to 'false'
#    # A notification is sent whenever a language change is performed
#    enable: true
#    # An array of Apprise configurations, see Apprise docs for more information: https://github.com/caronc/apprise
#    # The array 'users' can be specified in order to link notification URLs with specific users
#    #   Defaults to all users if not present
#    # The array 'events' can be specified in order to get notifications only for specific events
#    #   Valid event values: "play_or_activity" "new_episode" "updated_episode" "scheduler"
#    #   Defaults to all events if not present
#    apprise_configs:
#      # This URL will be notified of all changes during all events
#      - "discord://webhook_id/webhook_token"
#      # These URLs will only be notified of language change for users "MyUser1" and "MyUser2"
#      - urls:
#          - "gotify://hostname/token"
#          - "pover://user@token"
#        users:
#          - "MyUser1"
#          - "MyUser2"
#      # This URL will only be notified of language change for user "MyUser3" during play or activity events
#      - urls:
#          - "tgram://bottoken/ChatID"
#        users:
#          - "MyUser3"
#        events:
#          - "play_or_activity"
#      # This URL will be notified of language change during scheduler tasks only
#      - urls:
#          - "gotify://hostname/token"
#        events:
#          - "scheduler"
#      - "..."

  # Whether or not to enable the debug mode, defaults to 'false'
  # Enabling debug mode will significantly increase the number of output logs
  debug: false

Plex API: Missing argument title or season is required

Running as a python script with command in admin powershell on Windows 10 VM:
python3 main.py -c ./config.yaml

logs

  2022-10-28 11:18:33,523 [INFO] Parsing config file './config.yaml'
2022-10-28 11:18:33,528 [INFO] The provided configuration has been successfully validated
2022-10-28 11:18:33,535 [INFO] Starting scheduler
2022-10-28 11:18:34,690 [INFO] Successfully connected as user 'aadgh' (id: 1)
2022-10-28 11:18:34,696 [INFO] Scanning all episodes from the Plex library, this action should only take a few seconds but can take several minutes for larger libraries
Traceback (most recent call last):
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\main.py", line 118, in <module>
    plex_auto_languages.start()
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\main.py", line 68, in start
    self.init()
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\main.py", line 45, in init
    self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"), self.notifier, self.config)
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\plex_auto_languages\plex_server.py", line 110, in __init__
    self.cache = PlexServerCache(self)
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\plex_auto_languages\plex_server_cache.py", line 44, in __init__
    self.refresh_library_cache()
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\plex_auto_languages\plex_server_cache.py", line 68, in refresh_library_cache
    for episode in self._plex.episodes():
  File "C:\Users\Alex\Desktop\Plex-Auto-Languages\plex_auto_languages\plex_server.py", line 62, in episodes
    return self._plex.library.all(libtype="episode", container_size=1024)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\library.py", line 114, in all
    for item in section.all(**kwargs):
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\library.py", line 672, in all
    return self.search(libtype=libtype, **kwargs)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\library.py", line 1519, in search
    return self._search(key, maxresults, container_start, container_size, **kwargs)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\library.py", line 1531, in _search
    subresults = self.fetchItems(key, container_start=container_start,
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\library.py", line 451, in fetchItems
    items = self.findItems(data, cls, ekey, **kwargs)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\base.py", line 312, in findItems
    item = self._buildItemOrNone(elem, cls, initpath)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\base.py", line 101, in _buildItemOrNone
    return self._buildItem(elem, cls, initpath)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\base.py", line 93, in _buildItem
    return ecls(self._server, elem, initpath)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\base.py", line 56, in __init__
    self._loadData(data)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\video.py", line 854, in _loadData
    if self.skipParent and not self.parentRatingKey:
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\base.py", line 502, in __getattribute__
    self._reload(_overwriteNone=False)
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\base.py", line 378, in _reload
    self._loadData(data[0])
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\video.py", line 860, in _loadData
    self.parentRatingKey = self.show().season(season=self.parentIndex).ratingKey
  File "C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\plexapi\video.py", line 556, in season
    raise BadRequest('Missing argument: title or season is required')
plexapi.exceptions.BadRequest: Missing argument: title or season is required

I installed the dependencies from the requirements.txt.

config.yaml

plexautolanguages:
  # Update language for the entire show or only for the current season
  # Accepted values:
  #   - show (default)
  #   - season
  update_level: "show"

  # Update all episodes of the show/season or only the next ones
  # Accepted values:
  #   - all (default)
  #   - next
  update_strategy: "all"

  # Whether or not playing a file should trigger a language update, defaults to 'true'
  trigger_on_play: true

  # Whether or not scanning the library for new files should trigger a language update, defaults to 'true'
  # A newly added episode will be updated based on the most recently watched episode, or the first episode of the show if it has never been watched
  trigger_on_scan: true

  # Whether or not navigating the Plex library should trigger a language update, defaults to 'false'
  # Only the Plex web client and the Plex for Windows app support this feature
  # Set this to 'true' only if you want to perform changes whenever the default track of an episode is updated, even when the episode is not played.
  # Setting this parameter to 'true' can result in higher resource usage.
  trigger_on_activity: false

  # Whether or not to refresh the cached library whenever the Plex server scans its own library, defaults to 'true'
  # Disabling this parameter will prevent PlexAutoLanguages from detecting updated files for an already existing episode
  # It is recommended to disable this parameter if you have a large TV Show library (10k+ episodes)
  refresh_library_on_scan: true

  # Plex configuration
  plex:
    # A valid Plex URL (required)
    url: "http://127.0.0.1:32400"
    # A valid Plex Token (required)
    token: "********"

  scheduler:
    # Whether of not to enable the scheduler, defaults to 'true'
    # The scheduler will perform a deeper analysis of all recently played TV Shows
    enable: true
    # The time at which the scheduler start its task with the format 'HH:MM', defaults to '02:00'
    schedule_time: "04:30"

  notifications:
    # Whether or not to enable the notifications through Apprise, defaults to 'false'
    # A notification is sent whenever a language change is performed
    enable: true
    # An array of Apprise configurations, see Apprise docs for more information: https://github.com/caronc/apprise
    # The array 'users' can be specified in order to link notification URLs with specific users
    #   Defaults to all users if not present
    # The array 'events' can be specified in order to get notifications only for specific events
    #   Valid event values: "play_or_activity" "new_episode" "updated_episode" "scheduler"
    #   Defaults to all events if not present
    apprise_configs:
      # This URL will be notified of all changes during all events
      - "discord://webhook_id/webhook_token"
      # These URLs will only be notified of language change for users "MyUser1" and "MyUser2"
      - urls:
          - "gotify://hostname/token"
          - "pover://user@token"
        users:
          - "MyUser1"
          - "MyUser2"
      # This URL will only be notified of language change for user "MyUser3" during play or activity events
      - urls:
          - "tgram://bottoken/ChatID"
        users:
          - "MyUser3"
        events:
          - "play_or_activity"
      # This URL will be notified of language change during scheduler tasks only
      - urls:
          - "gotify://hostname/token"
        events:
          - "scheduler"
      - "..."

  # Whether or not to enable the debug mode, defaults to 'false'
  # Enabling debug mode will significantly increase the number of output logs
  debug: false

I haven't edited the config past adding my plex config. I have tried to use http://192.168.1.114:32400 for my URL as well and that didn't help.

Thanks for any help :)

PermissionError: [Errno 13] Permission denied: '/config'

I am using the python version of the program, and for some reason I can load the config-file I've created, under the config-folder, but I get an error running the program.

Full stack-trace:

[USER]@[MACHINE]:~/.apps/Plex-Auto-Languages$ python3 main.py -c ./config/config.yaml
2023-06-05 10:35:35,437 [INFO] Parsing config file './config/config.yaml'
2023-06-05 10:35:35,439 [INFO] The provided configuration has been successfully validated
Traceback (most recent call last):
  File "/home/user/.apps/Plex-Auto-Languages/main.py", line 117, in <module>
    plex_auto_languages = PlexAutoLanguages(args.config_file)
  File "/home/user/.apps/Plex-Auto-Languages/main.py", line 27, in __init__
    self.config = Configuration(user_config_path)
  File "/home/user/.apps/Plex-Auto-Languages/plex_auto_languages/utils/configuration.py", line 74, in __init__
    self._add_system_config()
  File "/home/user/.apps/Plex-Auto-Languages/plex_auto_languages/utils/configuration.py", line 128, in _add_system_config
    os.makedirs(self._config["data_dir"])
  File "/usr/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/config'

I've tried changing the owner to myself, with chown, and I've tried to give all files permission 777 with chmod.

Official list of supported devices

The feedback from Plex is not consistent between devices. This purpose of this thread is to have an updated list of supported devices based on your feedbacks, I will try to update this list regularly so do not hesitate to share your experience.

Client Trigger on Play Trigger on Activity
Web App Yes Yes
Plex for Windows Yes Yes
Android Phone App Yes No
Android TV App Yes No
Kodi Addon for Android TV Yes ?
Amazon Firestick 4K Yes No
Apple TV App Yes ?
Infuse App on Apple TV Yes No
Infuse App on macOS Yes No
iOS App No Inconsistent
Plex for Samsung Yes Inconsistent

To check if a device supports Trigger on Play or Trigger on Activity, follow this procedure:

  • Enable debug mode by adding debug: true to the configuration file
  • Enable the trigger you wish to test by setting trigger_on_xxxx to true
  • Start PlexAutoLanguages
  • For Trigger on Play, start watching an episode on the client you wish to test
    If you see a log similar to this, Trigger on Play is supported:
    [DEBUG] [Play Session] Session: 4 | State: 'playing' | User id: 1 | Episode: <Episode:23268:The-Crown-s04e09>
  • For Trigger on Activity, browse episodes of the Plex library on the client you wish to test
    If you see a log similar to this, Trigger on Activity is supported:
    [DEBUG] [Activity] User: xxx | Episode: <Episode:23268:The-Crown-s04e09>

Episodes will randomly change language when paused, and crash stream

I've had this happen to me a few times, but basically what goes on is when I pause an episode or even minimize it to look at the episode details it'll change to another language.

I.E. Having an anime set to be Japanese with subtitles, and then it turns the audio to English and removes subs and crashes the stream when I attempt to change it back.

Not sure what exactly is causing this but it's pretty annoying.

High CPU usage when Plex is detecting intros

For some reason I'm getting very high CPU usage when Plex is doing a large scan and detecting intros on newly added media. Running the command docker stats -a was showing 60% under CPU % for plex-auto-languages alone. Stopping and restarting the container reset things and CPU usage when down to less than 1%. Anyone else seen this? Configuration file options were left at defaults. This is running in docker on win10.

Cannot connect to plex server

Hi,
I've been trying out this via docker (Synology Nas) and managed to install it, but looking at the logs it just says ConnectionError: unable to connect to plex server, retrying

The only thing I added in the config is PLEX_URL and PLEX_TOKEN

Let me know if you need any other info

Unable to find elem: cls=Season

My PAL docker seems to be stuck during caching:

[INFO]` Scanning all episodes from the Plex library, this action should only take a few seconds but can take several minutes for larger libraries
[DEBUG] [Cache] Refreshing library cache
Traceback (most recent call last):
File "main.py", line 118, in
plex_auto_languages.start()
File "main.py", line 68, in start
self.init()
File "main.py", line 45, in init
self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"), self.notifier, self.config)
File "/app/plex_auto_languages/plex_server.py", line 110, in init
self.cache = PlexServerCache(self)
File "/app/plex_auto_languages/plex_server_cache.py", line 44, in init
self.refresh_library_cache()
File "/app/plex_auto_languages/plex_server_cache.py", line 68, in refresh_library_cache
for episode in self._plex.episodes():
File "/app/plex_auto_languages/plex_server.py", line 62, in episodes
return self._plex.library.all(libtype="episode", container_size=1024)
File "/usr/local/lib/python3.8/site-packages/plexapi/library.py", line 114, in all
for item in section.all(**kwargs):
File "/usr/local/lib/python3.8/site-packages/plexapi/library.py", line 672, in all
return self.search(libtype=libtype, **kwargs)
File "/usr/local/lib/python3.8/site-packages/plexapi/library.py", line 1519, in search
return self._search(key, maxresults, container_start, container_size, **kwargs)
File "/usr/local/lib/python3.8/site-packages/plexapi/library.py", line 1531, in _search
subresults = self.fetchItems(key, container_start=container_start,
File "/usr/local/lib/python3.8/site-packages/plexapi/library.py", line 451, in fetchItems
items = self.findItems(data, cls, ekey, **kwargs)
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 312, in findItems
item = self._buildItemOrNone(elem, cls, initpath)
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 101, in _buildItemOrNone
return self._buildItem(elem, cls, initpath)
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 93, in _buildItem
return ecls(self._server, elem, initpath)
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 56, in init
self._loadData(data)
File "/usr/local/lib/python3.8/site-packages/plexapi/video.py", line 854, in _loadData
if self.skipParent and not self.parentRatingKey:
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 502, in getattribute
self._reload(_overwriteNone=False)
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 378, in _reload
self._loadData(data[0])
File "/usr/local/lib/python3.8/site-packages/plexapi/video.py", line 860, in _loadData
self.parentRatingKey = self.show().season(season=self.parentIndex).ratingKey
File "/usr/local/lib/python3.8/site-packages/plexapi/video.py", line 555, in season
return self.fetchItem(key, Season, index=index)
File "/usr/local/lib/python3.8/site-packages/plexapi/base.py", line 182, in fetchItem
raise NotFound(f'Unable to find elem: cls={clsname}, attrs={kwargs}')
plexapi.exceptions.NotFound: Unable to find elem: cls=Season, attrs={'index': 38}

Server access is removed when running PAL docker

When running PAL docker I lose the ability to "see" my Plex server via app.plex.tv and local connection. Stopping the container allows access to the server. Config.yaml (redacted token info) and docker-compose config are below.

plexautolanguages:
  # Update language for the entire show or only for the current season
  # Accepted values:
  #   - show (default)
  #   - season
  update_level: "show"

  # Update all episodes of the show/season or only the next ones
  # Accepted values:
  #   - all (default)
  #   - next
  update_strategy: "all"

  # Whether or not playing a file should trigger a language update, defaults to 'true'
  trigger_on_play: true

  # Whether or not navigating the Plex library should trigger a language update, defaults to 'false'
  # Set this to 'true' only if you want to perform changes whenever the default track of an episode is updated, even when the episode is not played.
  # Setting this parameter to 'true' can result in higher resource usage.
  trigger_on_activity: false

  # Plex configuration
  plex:
    # A valid Plex URL (required)
    url: "http://plex:32400"
    # A valid Plex Token (required)
    token: "XXXXXXX"

  scheduler:
    # Whether of not to enable the scheduler, defaults to 'true'
    # The scheduler will perform a deeper analysis of all recently played TV Shows
    enable: false
    # The time at which the scheduler start its task with the format 'HH:MM', defaults to '02:00'
    schedule_time: "07:00"

   notifications:
    # Whether of not to enable the notifications through Apprise, defaults to 'false'
    # A notification is sent whenever a language change is performed
    enable: false
    # An array of Apprise configurations, see Apprise docs for more information: https://github.com/caronc/apprise
    apprise_configs:
      - "XXXXXX"

Compose config

### PAL###
  PAL:
    image: remirigal/plex-auto-languages:latest
    container_name: PAL
    environment:
      - TZ=${TZ}
    volumes:
      - ${APPDATA_ROOT}/PAL/config.yaml:/config/config.yaml
    restart: unless-stopped

Issue at Startup

When I initially set this program up, it was working perfectly but now, it's giving me an error. Here's the debug log.

debug log
2022-05-15 12:34:18,172 [INFO] Trying to restore the connection to the Plex server...
2022-05-15 12:34:18,681 [INFO] Successfully connected as user 'CardcaptorRLH85' (id: 1)
2022-05-15 12:34:18,682 [DEBUG] [Cache] Loading server cache from file
2022-05-15 12:34:18,687 [INFO] Starting alert listener
2022-05-15 12:34:18,717 [WARNING] Alert listener had an unexpected error
2022-05-15 12:34:19,689 [DEBUG] [Cache] Saving server cache to file
2022-05-15 12:34:19,698 [INFO] Trying to restore the connection to the Plex server...
2022-05-15 12:34:20,275 [INFO] Successfully connected as user 'CardcaptorRLH85' (id: 1)
2022-05-15 12:34:20,276 [DEBUG] [Cache] Loading server cache from file
2022-05-15 12:34:20,284 [INFO] Starting alert listener
2022-05-15 12:34:20,335 [WARNING] Alert listener had an unexpected error
2022-05-15 12:34:21,285 [DEBUG] [Cache] Saving server cache to file
2022-05-15 12:34:21,295 [INFO] Trying to restore the connection to the Plex server...
This continues for hundreds of lines.

Here's my docker-compose for this container.

docker-compose
...
  plexautolanguages:
    image: remirigal/plex-auto-languages:latest
    container_name: Plex-Auto-Languages
    environment:
      - TZ=America/Detroit
    volumes:
      - /volume1/docker/Plex-Auto-Languages:/config
    depends_on:
      - plex
    restart: unless-stopped
...

Finally, here's a redacted version of my config.yaml.

config.yaml
plexautolanguages:
  # Update language for the entire show or only for the current season
  # Accepted values:
  #   - show (default)
  #   - season
  update_level: "show"

  # Update all episodes of the show/season or only the next ones
  # Accepted values:
  #   - all (default)
  #   - next
  update_strategy: "all"

  # Whether or not playing a file should trigger a language update, defaults to 'true'
  trigger_on_play: true

  # Whether or not navigating the Plex library should trigger a language update, defaults to 'false'
  # Set this to 'true' only if you want to perform changes whenever the default track of an episode is updated, even when the episode is not played.
  # Setting this parameter to 'true' can result in higher resource usage.
  trigger_on_activity: false

  # Plex configuration
  plex:
    # A valid Plex URL (required)
    url: "<plex.example.com>"
    # A valid Plex Token (required)
    token: "<REDACTED>"

  scheduler:
    # Whether of not to enable the scheduler, defaults to 'true'
    # The scheduler will perform a deeper analysis of all recently played TV Shows
    enable: true
    # The time at which the scheduler start its task with the format 'HH:MM', defaults to '02:00'
    schedule_time: "04:30"

  notifications:
    # Whether of not to enable the notifications through Apprise, defaults to 'false'
    # A notification is sent whenever a language change is performed
    enable: false
    # An array of Apprise configurations, see Apprise docs for more information: https://github.com/caronc/apprise
    apprise_configs: []

  # Whether or not to enable the debug mode, defaults to 'false'
  # Enabling debug mode will significantly increase the number of output logs
  debug: true

I have a registered domain name that I host all of my local services on in the form <service.domain.tld>. Since the logs show PAL connecting to my Plex server as me, I don't think this is the problem. Also, I specifically turned debug on for diagnosing this issue but it doesn't seem to have added any detail about what the unexpected error was.

Notifications Showing `None` for User

I have notifications set up and they seem to be working correctly. Except, whenever one of my home users (not managed) starts watching a show the notification looks as follows:

PlexAutoLanguages - Futurama
Show: Futurama
User: None
Audio: English (EAC3 Stereo)
Subtitles: English (SRT)
Updated episodes: 1/124 (S01E01 - S07E26)

Initial scan not completing

Upon starting the PAL container I see the following in the logs repeated without ever seeing scan activity in Plex or the creation of a cache file.

2022-06-17 13:35:56,278 [INFO] Scanning all episodes from the Plex library, this action should only take a few seconds but can take several minutes for larger libraries
2022-06-17 13:35:56,278 [DEBUG] [Cache] Refreshing library cache
2022-06-17 13:37:51,628 [INFO] Received SIGINT or SIGTERM, stopping gracefully

[Feature Request] Update new files as they are added

I am not sure if this increases the scope or complexity of the app, but I noticed PlexAutoLanguages works super well when I have a full season/show available on Plex. However, for currently airing items, it doesn't track new files as they are added to Plex. There are two scenarios

  1. A completely new episode is added
  2. An existing episode file is upgraded. Let's take a scenario where I am watching an anime. I have subbed releases, but they are being replaced by dual audio files as those are released, which usually lag behind by a few weeks. If I play the first dual audio release using the dub tracks, it won't find those dubbed tracks for the rest of the season, but as a new dual audio file is added, those tracks could now theoretically be selected.

I realize this may not be easy to do. Currently, it seems you are just updating the languages given a trigger, so you don't need to keep track of the sub/language selection beyond the update. But in this scenario, if a new file is added, you would need to A) know the file is added which includes both as new episodes as well as replacements of existing files and B) know which tracks to select

However, I figured I would create a GHI to at least initiate the discussion

json.decoder.JSONDecodeError: Extra data: line 1 column 1744933 (char 1744932)

File "C:\Users\Media\Documents\Plex-Auto-Languages\main.py", line 118, in
plex_auto_languages.start()
File "C:\Users\Media\Documents\Plex-Auto-Languages\main.py", line 68, in start
self.init()
File "C:\Users\Media\Documents\Plex-Auto-Languages\main.py", line 45, in init
self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"), self.notifier, self.config)
File "C:\Users\Media\Documents\Plex-Auto-Languages\plex_auto_languages\plex_server.py", line 110, in init
self.cache = PlexServerCache(self)
File "C:\Users\Media\Documents\Plex-Auto-Languages\plex_auto_languages\plex_server_cache.py", line 41, in init
if not self.load():
File "C:\Users\Media\Documents\Plex-Auto-Languages\plex_auto_languages\plex_server_cache.py", line 114, in load
cache = json.load(stream)
File "C:\Users\Media\AppData\Local\Programs\Python\Python310\lib\json_init
.py", line 293, in load
return loads(fp.read(),
File "C:\Users\Media\AppData\Local\Programs\Python\Python310\lib\json_init
.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Media\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 1744933 (char 1744932)

Notification Details

Can we update the notification to provide details of language/subtitle changes.
Language: English -> Korean
Subtitle: None -> English

self.notify(f"Updated default language of {len(unique_parts)} file(s) for TV Show '{episode.show().title}'")

[ERROR] Connection to the Plex server failed for user

For some reason there are regular connection errors for the shared users in my plex home in the logs.
Although this is not always the case, as it shows that there have been language changes for some.

I set up the Docker container on the same windows machine my plex server runs on. I used the Docker compose minimal configuration.
I have attached some log files, maybe you understand where these errors are coming from. Also attached the yaml file (as a .txt file as github doesnt let you upload yaml files).

I was able to trigger language changes remotely with the android app on my phone over the mobile network.
Most other users access the server remotely.

Best Regards.

Logs Plex Auto Languages.txt
Logs Plex Auto Languages1.txt
docker-compose.yaml.txt

EDIT: Okay, seems i only get errors now altthough as you can see in the attached picture there is one time when the app changed the language settings for one user
image

[ERROR] cannot decode

Seeing this error with notifications enabled

2022-06-17 22:57:11,305 [ERROR] cannot decode: b'{"NotificationContainer":{"type":"progress","size":1,"ProgressNotification":
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/websocket/_app.py", line 383, in run_forever
    dispatcher.read(self.sock.sock, read, check)
  File "/usr/local/lib/python3.8/site-packages/websocket/_app.py", line 48, in read
    if not read_callback():
  File "/usr/local/lib/python3.8/site-packages/websocket/_app.py", line 349, in read
    op_code, frame = self.sock.recv_data_frame(True)
  File "/usr/local/lib/python3.8/site-packages/websocket/_core.py", line 415, in recv_data_frame
    return self.cont_frame.extract(frame)
  File "/usr/local/lib/python3.8/site-packages/websocket/_abnf.py", line 421, in extract
    raise WebSocketPayloadException(
websocket._exceptions.WebSocketPayloadException: cannot decode: b'{"NotificationContainer":{"type":"progress","size":1,"ProgressNotification":

Running master

Runnning when plex restarts/updates

right now it just closes the cmd window without much luck. I've tried making a task in task scheduler windows still sees it at running despite not running.

[Enhancement] Retrieve updated episodes the same way as added episodes.

Rebuilding the entire library cache every time an episode is updated is slow, I looked into it and it appears that updated episodes can be fetched the same way as added episodes by changing the addedAt to updatedAt here:

recent = section.searchEpisodes(sort="addedAt:desc", filters={"addedAt>>": f"{minutes}m"})

Not sure if you knew this was possible, it seems to work fine but I haven't done any real testing.

Not sure what else the cache is actually used for but it seems that it is pretty much useless now? Would be worth removing to save some small amount of memory.

The newly_added and newly_updated lists could also be made irrelevant by caching the time of the latest added/updated item and only processing items added/updated after then.

Docker image compatible with Rasperry Pi (arm) 32bits and 64bits

All is in the title. I'm running docker on a rpi with raspianOS 64bits version. I've seen on the DockerHub there is only amd64 images. Is-it difficult to provide such an image (I'm a noob on docker so I don't how much work it represents) ?

Thank you for your time and your work.

Ignore series?

There's a few series that I have that aren't super consistent with their subtitle naming or have different named japanese/english tracks (even though there's just 1) confuses the hell out of the program.

Silently Crashes During Scanning

I just discovered this! I set it up to run in my k8s cluster, but it seems to be silently crashing. I have enabled debug mode, below is the log.

[#0099ff-::]2022-07-17 06:38:55,349 [INFO] Parsing config file '/config/config.yaml'
[#0099ff-::]2022-07-17 06:38:55,354 [INFO] Setting value of parameter PLEX_URL from environment variable
[#0099ff-::]2022-07-17 06:38:55,354 [INFO] Setting value of parameter PLEX_TOKEN from environment variable
[#0099ff-::]2022-07-17 06:38:55,354 [INFO] The provided configuration has been successfully validated
2022-07-17 06:38:55,354 [DEBUG] Debug mode enabled
[#0099ff-::]2022-07-17 06:38:55,355 [INFO] Starting scheduler
[#0099ff-::]2022-07-17 06:38:55,934 [INFO] Successfully connected as user 'PLEX_USERNAME' (id: 1)
[#0099ff-::]2022-07-17 06:38:55,934 [INFO] Scanning all episodes from the Plex library, this action should only take a few seconds but can take several minutes for larger libraries 
2022-07-17 06:38:55,934 [DEBUG] [Cache] Refreshing library cache 
Stream closed EOF for media/plex-auto-languages-7b9f58948d-hqjpl (plex-auto-languages)  

Im not even sure where to start debugging. I was hoping enabling debug mode would give me a lot more info, but it does not.
I am running version 1.1.3 container image

Any suggestions?

Multiple Plex Servers?

Does this application support multiple Plex servers in a single container? Whether it be by the following options or some other way.

  1. Entering multiple Plex Tokens & URL’s to the config file.

  2. Mounting multiple volumes for each individual config file each with its own Plex Token & URL.

  3. Adding multiple Plex Tokens & URL's as environment variables.

If not, then I’d like to suggest it be possible to do. (Enhancement)

[ERROR] Unable to process timeline

2022-06-23 06:54:03,988 [ERROR] Unable to process timeline Traceback (most recent call last): File "/app/plex_auto_languages/plex_alert_handler.py", line 43, in __call__ alert.process(self._plex) File "/app/plex_auto_languages/alerts/timeline.py", line 65, in process logger.info(f"[Timeline] Processing newly added episode {plex.get_episode_short_name(item)}") File "/app/plex_auto_languages/plex_server.py", line 91, in get_episode_short_name return f"'{episode.show().title}' (S{episode.seasonNumber:02}E{episode.episodeNumber:02})" TypeError: unsupported format string passed to NoneType.__format__

Running in docker - image tag master

JSONDecodeError when launching the container

Hello, I'm getting a JSONDecodeError that seems to have something to do with grabbing either the plex.url, plex.token, or notifier. My config.yaml was working fine awhile back, not sure what changed. I have tried checking that my token is correct, and tried multiple plex urls. Nothing has fixed the issue. Any help would be much appreciated, I've found this tool invaluable for watching shows with poorly labelled subtitles.

My container version tag is latest, my plex version is 1.31.3.6868.

Here's the log containing the error.

2023-04-01 13:26:15,147 [INFO] Parsing config file '/config/config.yaml'
2023-04-01 13:26:15,155 [INFO] The provided configuration has been successfully validated
2023-04-01 13:26:15,155 [INFO] Starting scheduler
2023-04-01 13:26:16,441 [INFO] Successfully connected as user '<censored>' (id: 1)
Traceback (most recent call last):
  File "main.py", line 118, in <module>
    plex_auto_languages.start()
  File "main.py", line 68, in start
    self.init()
  File "main.py", line 45, in init
    self.plex = PlexServer(self.config.get("plex.url"), self.config.get("plex.token"), self.notifier, self.config)
  File "/app/plex_auto_languages/plex_server.py", line 110, in __init__
    self.cache = PlexServerCache(self)
  File "/app/plex_auto_languages/plex_server_cache.py", line 41, in __init__
    if not self._load():
  File "/app/plex_auto_languages/plex_server_cache.py", line 114, in _load
    cache = json.load(stream)
  File "/usr/local/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here's my config.yaml file

plexautolanguages:
  # Update language for the entire show or only for the current season
  # Accepted values:
  #   - show (default)
  #   - season
  update_level: "show"

  # Update all episodes of the show/season or only the next ones
  # Accepted values:
  #   - all (default)
  #   - next
  update_strategy: "all"

  # Whether or not playing a file should trigger a language update, defaults to 'true'
  trigger_on_play: true

  # Whether or not scanning the library for new files should trigger a language update, defaults to 'true'
  # A newly added episode will be updated based on the most recently watched episode, or the first episode of the show if it has never been watched
  trigger_on_scan: true

  # Whether or not navigating the Plex library should trigger a language update, defaults to 'false'
  # Only the Plex web client and the Plex for Windows app support this feature
  # Set this to 'true' only if you want to perform changes whenever the default track of an episode is updated, even when the episode is not played.
  # Setting this parameter to 'true' can result in higher resource usage.
  trigger_on_activity: false

  # Whether or not to refresh the cached library whenever the Plex server scans its own library, defaults to 'true'
  # Disabling this parameter will prevent PlexAutoLanguages from detecting updated files for an already existing episode
  # It is recommended to disable this parameter if you have a large TV Show library (10k+ episodes)
  refresh_library_on_scan: false

  # Plex configuration
  plex:
    # A valid Plex URL (required)
    url: "https://plex.<censored>.ca"
    # A valid Plex Token (required)
    token: "<censored>"

  scheduler:
    # Whether of not to enable the scheduler, defaults to 'true'
    # The scheduler will perform a deeper analysis of all recently played TV Shows
    enable: true
    # The time at which the scheduler start its task with the format 'HH:MM', defaults to '02:00'
    schedule_time: "04:30"

  notifications:
    # Whether or not to enable the notifications through Apprise, defaults to 'false'
    # A notification is sent whenever a language change is performed
    enable: false
    # An array of Apprise configurations, see Apprise docs for more information: https://github.com/caronc/apprise
    # The array 'users' can be specified in order to link notification URLs with specific users
    #   Defaults to all users if not present
    # The array 'events' can be specified in order to get notifications only for specific events
    #   Valid event values: "play_or_activity" "new_episode" "updated_episode" "scheduler"
    #   Defaults to all events if not present
    apprise_configs:
      # This URL will be notified of all changes during all events
      - "discord://webhook_id/webhook_token"
      # These URLs will only be notified of language change for users "MyUser1" and "MyUser2"
      - urls:
          - "gotify://hostname/token"
          - "pover://user@token"
        users:
          - "MyUser1"
          - "MyUser2"
      # This URL will only be notified of language change for user "MyUser3" during play or activity events
      - urls:
          - "tgram://bottoken/ChatID"
        users:
          - "MyUser3"
        events:
          - "play_or_activity"
      # This URL will be notified of language change during scheduler tasks only
      - urls:
          - "gotify://hostname/token"
        events:
          - "scheduler"
      - "..."

  # Whether or not to enable the debug mode, defaults to 'false'
  # Enabling debug mode will significantly increase the number of output logs
  debug: false

Read timeout error

Is this project being developed any more? It's fantastic when it works, but I'm finding that I am getting fairly regular read timeouts where it seems like pal loses its connection with Plex.

requests.exceptions.ReadTimeout: HTTPConnectionPool(host='127.0.0.1', port=32400): Read timed out. (read timeout=30)

It would be great if pal could somehow survive these timeouts, because when it happens, I end up having to restart the service. If it could just pick up again once the connection is resumed, that would be great.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.