Skip to content

Commit

Permalink
add code to find library_id
Browse files Browse the repository at this point in the history
  • Loading branch information
yajrendrag committed Oct 26, 2024
1 parent 10d5188 commit 59c8659
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions source/notify_plex_partial/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

**<span style="color:#56adda">0.0.2</span>**
- add code to find library_id

**<span style="color:#56adda">0.0.1</span>**
- Initial version
- based on v0.0.5 of notify_plex
5 changes: 3 additions & 2 deletions source/notify_plex_partial/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ These two approaches will likely yield different tokens, but both should work.

- Enter the url for your Plex Server using your local IP address (ie, not the plex.tv cloud address)
- Enter the Plex token you found as per above
- Enter as a single string, the Library Mapping that you entered in your docker compose or on the docker run line for the library in which this plugin is installed,
e.g., /media/TVShows:/library
- Enter as a single string, the a mapping that shows your host media path relative to your unmanic library media path. The mapping should only go include where the paths are
different, e.g., /media:/library. This means that Plex sees your media at the path /media and unmanic sees it at /library. Below these paths the paths should be identical.
You should have a unique mapping for each library in which this plugin is deployed, e.g., TVShows, Movies, etc.
- enter True or False for whether this plugin should run an update if the task for the file failed.

:::note
Expand Down
2 changes: 1 addition & 1 deletion source/notify_plex_partial/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"on_postprocessor_task_results": 0
},
"tags": "post-processor",
"version": "0.0.5"
"version": "0.0.2"
}
21 changes: 18 additions & 3 deletions source/notify_plex_partial/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ class Settings(PluginSettings):
'Notify on Task Failure?': False,
}

def get_section(media_dir, plex_url, plex_token):
libs_url = plex_url + '/library/sections/?X-Plex-Token=' + plex_token
sections = requests.get(libs_url)
if sections:
section_parse = re.findall(r'Location id=\"(.*)\" path=\"(.*)\" ', sections.text)
if len(section_parse):
for s in section_parse:
if s[1] in media_dir:
return s[0]
else:
logger.error("Library section not found - '{}' - aborting".format(media_dir))
return ""

def update_plex(plex_url, plex_token, media_dir):
def update_plex(plex_url, plex_token, media_dir, section_id):
# Call to Plex to trigger an update
plex_url = plex_url + '/library/sections/all/refresh/?path=' + urllib.parse.quote(media_dir, safe='') + '&X-Plex-Token=' + plex_token
plex_url = plex_url + '/library/sections/' + str(section_id) + '/refresh/?path=' + urllib.parse.quote(media_dir, safe='') + '&X-Plex-Token=' + plex_token
response = requests.get(plex_url)
if response.status_code == 200:
logger.info("Notifying Plex ({}) to update its library.".format(plex_url))
Expand Down Expand Up @@ -91,6 +103,9 @@ def on_postprocessor_task_results(data):
except:
logger.error("cannot form host media directory path - unmanic_dir: '{}', host_dir: '{}', media_dir: '{}'".format(unmanic_dir, host_dir, media_dir))
return data
update_plex(plex_url, plex_token, media_dir)
section_id = get_section(media_dir, plex_url, plex_token)
if not section_id:
return data
update_plex(plex_url, plex_token, media_dir, section_id)

return data

0 comments on commit 59c8659

Please sign in to comment.