bearlikelion / popularplex

Generate dynamic collections of popular media for Plex using Tautulli
15 stars 2 forks source link

Locks collection field #2

Closed bigdork closed 4 years ago

bigdork commented 4 years ago

Script locks the collection field, causing error on re-run if the same series is still popular

bearlikelion commented 4 years ago

Can you provide the error or exception you are seeing when re-running the script? I frequently run it one after another during development, the clear_collections() function should empty out the configured Movie and TV collections before adding media back without locking the field.

bigdork commented 4 years ago

Actually, I don't think it's the lock that's causing it.

The script appears to be trigging a metadata refresh on the items post-add or remove. NBD for movies, the new agent is very quick, but large TV shows on the (ie: Supernatural, The Walking Dead, Spongebob) take time to complete with the slower agent.

Is the metadata refresh necessary?

meisnate12 commented 4 years ago

All this script does is call the plexapi method called removeCollection. It doesn't actually tell anything to refresh. So either the plexapi is refreshing on removal or plex itself refreshes on removal. I would wager it's the later, that plex itself is causing the refresh. If it is on plex there may be a plex setting that when changed may fix this issue.

bigdork commented 4 years ago

You may be right - I've disabled " Run a partial scan when changes are detected" but noticed there was an update. After update, the script won't run. Thoughts?

Output below, and a snippet from the [Plex] section of my config.

$ git pull https://github.com/bearlikelion/popularplex.git
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 5), reused 7 (delta 4), pack-reused 0
Unpacking objects: 100% (8/8), done.
From https://github.com/bearlikelion/popularplex
 * branch            HEAD       -> FETCH_HEAD
Updating a950604..654b893
Fast-forward
 README.md       | 8 ++++++++
 popular_plex.py | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)

$ python3 popular_plex.py
Traceback (most recent call last):
  File "popular_plex.py", line 76, in <module>
    if (config['Plex']['url'] != '' and config['Plex']['token'] != ''):
  File "/usr/lib/python3.6/configparser.py", line 959, in __getitem__
    raise KeyError(key)
KeyError: 'Plex'
$ cat config.ini
[Plex]
url = https://plex.domain.cc
token = _VxxxxxxxxxxxxM
username =
password =
server =
bigdork commented 4 years ago

To bypass the new crashing, I replaced line 69 config.read(os.path.dirname(__file__) + os.path.sep + 'config.ini') with the following from a prior version: config.read('config.ini') Script runs now.

I can confirm removing the "Run a partial scan when changes are detected" setting in Plex prevents the crashing due to metadata refresh!

(I'm not github-savvy, should I close this issue and open a new one for the config.read problem?)

bearlikelion commented 4 years ago

Yes, ideally we would close this issue and open a new one for the config.ini issue, but I'm curious what your output for:

os.path.dirname(__file__) + os.path.sep + 'config.ini'

This change was made so when the script runs outside from its directory it still uses the local config.ini file instead of looking for it in the current directory (like C:\Windows\System32)

You can reproduce by calling the python path from outside the git repo directory

bigdork commented 4 years ago

With line 69 as config.read(os.path.dirname(__file__) + os.path.sep + 'config.ini') the script runs if executed from outside the script directory, but not from within the script directory.

The reverse is true with line 69 as config.read('config.ini') where the script fails to execute from outside the script directory, but runs properly if executed from within the script directory.

Since I'm still just testing this out, I'd not yet moved it to my scripts path and have only been executing manually from my home directory. Now that I understand this behavior I can avoid the problem.

bearlikelion commented 4 years ago

The script has now been updated to look for a local config.ini, if not use the script_path to find one https://github.com/bearlikelion/popularplex/commit/9d5276f9aa3b2e4b8c167bfa00a5d066e7446948