diff --git a/source/notify_plex_partial/changelog.md b/source/notify_plex_partial/changelog.md
index ba6749e79..0ef472ffb 100644
--- a/source/notify_plex_partial/changelog.md
+++ b/source/notify_plex_partial/changelog.md
@@ -1,4 +1,7 @@
+**0.0.4**
+- add option to analyze media file
+
**0.0.3**
- add test to see if destination file exists - otherwise plex can't be notified by destination path
diff --git a/source/notify_plex_partial/description.md b/source/notify_plex_partial/description.md
index 67be22882..549ef5a57 100644
--- a/source/notify_plex_partial/description.md
+++ b/source/notify_plex_partial/description.md
@@ -10,10 +10,10 @@ 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 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.
+- Enter as a single string, the mapping that shows your host media path relative to your unmanic library media path. The mapping should only include the unique component of the paths, 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.
+- Enter True or False for whether this plugin should run an update if the task for the file failed.
+- Enter True or False for whether this plugin should run an analyze on the media file
:::note
If you are not running Unmanic in docker, then for the above library mapping, just enter the mapping to be identical on both sides of the colon, e.g., /media/TVShows:/media/TVShows
diff --git a/source/notify_plex_partial/info.json b/source/notify_plex_partial/info.json
index 832386595..cfd942b30 100644
--- a/source/notify_plex_partial/info.json
+++ b/source/notify_plex_partial/info.json
@@ -15,5 +15,5 @@
"on_postprocessor_task_results": 0
},
"tags": "post-processor",
- "version": "0.0.3"
+ "version": "0.0.4"
}
diff --git a/source/notify_plex_partial/plugin.py b/source/notify_plex_partial/plugin.py
index 4fb9a42bc..57dfcf03f 100644
--- a/source/notify_plex_partial/plugin.py
+++ b/source/notify_plex_partial/plugin.py
@@ -24,6 +24,9 @@
import requests
import re
import urllib.parse
+from plexapi.server import PlexServer
+import os
+import PTN
# Configure plugin logger
logger = logging.getLogger("Unmanic.Plugin.notify_plex_partial")
@@ -35,6 +38,7 @@ class Settings(PluginSettings):
'Plex Token': '',
'Unmanic Library Mapping': '',
'Notify on Task Failure?': False,
+ 'Analyze Video': False,
}
def get_section(media_dir, plex_url, plex_token):
@@ -59,6 +63,37 @@ def update_plex(plex_url, plex_token, media_dir, section_id):
else:
logger.error("Error requesting Plex to update: '{}'".format(media_dir))
+def analyze_video(media_dir, plex_url, plex_token):
+ headers = {'Accept': 'application/json'}
+ plex = PlexServer(plex_url, plex_token)
+ basename = os.path.splitext(os.path.basename(media_dir))[0]
+ basename = re.sub(r' \(\d\d\d\d\)','', basename)
+ parsed_info = PTN.parse(basename, standardise = False)
+ try:
+ video = parsed_info['episodeName']
+ except KeyError:
+ video = parsed_info['title']
+ query_url = plex_url + '/search/?X-Plex-Token=' + plex_token + '&query=' + video
+ response = requests.get(query_url, headers=headers)
+ if response.status_code == 200:
+ videos = response.json()['MediaContainer']['Metadata']
+ for vid in range(len(videos)):
+ if basename in videos[vid]['Media'][0]['Part'][0]['file']:
+ if videos[vid]['type'] == 'movie':
+ lib = plex.library.section(videos[vid]['librarySectionTitle'])
+ movie=lib.get(video)
+ logger.debug(f"analyzing movie {basename} in library {videos[vid]['librarySectionTitle']}")
+ movie.analyze()
+ else:
+ show_title = parsed_info['title']
+ if videos[vid]['title'] == video:
+ lib = plex.library.section(videos[vid]['librarySectionTitle'])
+ episodes = lib.get(show_title).episodes()
+ for k in range(len(episodes)):
+ if episodes[k].title == video:
+ logger.debug(f"analyzing show {basename} in library {videos[vid]['librarySectionTitle']}")
+ episodes[k].analyze()
+
def on_postprocessor_task_results(data):
"""
Runner function - provides a means for additional postprocessor functions based on the task success.
@@ -88,6 +123,9 @@ def on_postprocessor_task_results(data):
logger.error("Non-existent destination file - plex cannot be notified.")
return data
+ analyze = settings.get_setting('Analyze Video')
+
+ # Get host mapping of library folder
lib_map = settings.get_setting('Unmanic Library Mapping')
unmanic_dir=re.search(r'.*:(.*$)', lib_map)
if unmanic_dir:
@@ -113,4 +151,8 @@ def on_postprocessor_task_results(data):
return data
update_plex(plex_url, plex_token, media_dir, section_id)
+ # Analyze Video
+ if analyze:
+ analyze_video(media_dir, plex_url, plex_token)
+
return data
diff --git a/source/notify_plex_partial/requirements.txt b/source/notify_plex_partial/requirements.txt
index 777628967..9c1d989f6 100644
--- a/source/notify_plex_partial/requirements.txt
+++ b/source/notify_plex_partial/requirements.txt
@@ -1 +1,2 @@
plexapi==4.15.16
+parse-torrent-title==2.8.1