This commit is contained in:
+18
-1
@@ -107,9 +107,26 @@ async def sonarr_webhook(request: Request, background_tasks: BackgroundTasks, de
|
|||||||
|
|
||||||
if not episodes_data and webhook.episodeFile:
|
if not episodes_data and webhook.episodeFile:
|
||||||
episode_file = webhook.episodeFile
|
episode_file = webhook.episodeFile
|
||||||
# Extract season and episode from episodeFile if available
|
# Extract season and episode from episodeFile path/filename
|
||||||
season_num = episode_file.get("seasonNumber")
|
season_num = episode_file.get("seasonNumber")
|
||||||
episode_num = episode_file.get("episodeNumber")
|
episode_num = episode_file.get("episodeNumber")
|
||||||
|
|
||||||
|
# If not directly available, parse from relativePath or path
|
||||||
|
if not (season_num and episode_num):
|
||||||
|
from utils.nfo_patterns import extract_episode_info_from_filename
|
||||||
|
|
||||||
|
# Try relativePath first, then path
|
||||||
|
file_path = episode_file.get("relativePath") or episode_file.get("path", "")
|
||||||
|
print(f"DEBUG: Parsing episode info from path: {file_path}")
|
||||||
|
|
||||||
|
episode_info = extract_episode_info_from_filename(file_path)
|
||||||
|
if episode_info:
|
||||||
|
season_num = episode_info["season"]
|
||||||
|
episode_num = episode_info["episode"]
|
||||||
|
print(f"DEBUG: Extracted from filename - Season: {season_num}, Episode: {episode_num}")
|
||||||
|
else:
|
||||||
|
print(f"DEBUG: Could not extract season/episode from filename: {file_path}")
|
||||||
|
|
||||||
print(f"DEBUG: episodeFile seasonNumber: {season_num}, episodeNumber: {episode_num}")
|
print(f"DEBUG: episodeFile seasonNumber: {season_num}, episodeNumber: {episode_num}")
|
||||||
if season_num and episode_num:
|
if season_num and episode_num:
|
||||||
# Create episode data structure that matches what process_webhook_episodes expects
|
# Create episode data structure that matches what process_webhook_episodes expects
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ class EpisodeNFOManager:
|
|||||||
lockdata_elem = ET.SubElement(episode_elem, "lockdata")
|
lockdata_elem = ET.SubElement(episode_elem, "lockdata")
|
||||||
lockdata_elem.text = "true"
|
lockdata_elem.text = "true"
|
||||||
|
|
||||||
# Add comment with source
|
# Add comment with source at the bottom
|
||||||
comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ")
|
comment = ET.Comment(f" Created by {self.manager_brand} - Source: {source} ")
|
||||||
episode_elem.append(comment)
|
episode_elem.append(comment)
|
||||||
|
|
||||||
|
|||||||
+9
-17
@@ -342,10 +342,6 @@ class NFOManager:
|
|||||||
# This ensures they appear as a group at the bottom of the file
|
# This ensures they appear as a group at the bottom of the file
|
||||||
nfoguard_elements = []
|
nfoguard_elements = []
|
||||||
|
|
||||||
# Add NFOGuard comment marker as the first of our additions
|
|
||||||
nfoguard_comment = ET.Comment(f" NFOGuard - Source: {source} ")
|
|
||||||
nfoguard_elements.append(nfoguard_comment)
|
|
||||||
|
|
||||||
# Add IMDb uniqueid
|
# Add IMDb uniqueid
|
||||||
uniqueid = ET.Element("uniqueid", type="imdb", default="true")
|
uniqueid = ET.Element("uniqueid", type="imdb", default="true")
|
||||||
uniqueid.text = imdb_id
|
uniqueid.text = imdb_id
|
||||||
@@ -384,6 +380,10 @@ class NFOManager:
|
|||||||
lockdata.text = "true"
|
lockdata.text = "true"
|
||||||
nfoguard_elements.append(lockdata)
|
nfoguard_elements.append(lockdata)
|
||||||
|
|
||||||
|
# Add NFOGuard comment as the very last element (appears at bottom)
|
||||||
|
nfoguard_comment = ET.Comment(f" NFOGuard - Source: {source} ")
|
||||||
|
nfoguard_elements.append(nfoguard_comment)
|
||||||
|
|
||||||
# Now append all NFOGuard elements to the movie in one batch
|
# Now append all NFOGuard elements to the movie in one batch
|
||||||
# This ensures they appear as a contiguous block at the bottom
|
# This ensures they appear as a contiguous block at the bottom
|
||||||
for elem in nfoguard_elements:
|
for elem in nfoguard_elements:
|
||||||
@@ -395,7 +395,7 @@ class NFOManager:
|
|||||||
tree = ET.ElementTree(movie)
|
tree = ET.ElementTree(movie)
|
||||||
ET.indent(tree, space=" ", level=0)
|
ET.indent(tree, space=" ", level=0)
|
||||||
|
|
||||||
# Write directly to file (comment is already embedded in XML)
|
# Write directly to file (comment is already embedded in XML at bottom)
|
||||||
with open(nfo_path, 'w', encoding='utf-8') as f:
|
with open(nfo_path, 'w', encoding='utf-8') as f:
|
||||||
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||||
tree.write(f, encoding='unicode', xml_declaration=False)
|
tree.write(f, encoding='unicode', xml_declaration=False)
|
||||||
@@ -455,22 +455,14 @@ class NFOManager:
|
|||||||
lockdata = ET.SubElement(tvshow, "lockdata")
|
lockdata = ET.SubElement(tvshow, "lockdata")
|
||||||
lockdata.text = "true"
|
lockdata.text = "true"
|
||||||
|
|
||||||
# Add NFOGuard comment at the beginning
|
# Add NFOGuard comment at the bottom
|
||||||
comment_text = f" Created by {self.manager_brand} "
|
comment = ET.Comment(f" Created by {self.manager_brand} ")
|
||||||
|
tvshow.append(comment)
|
||||||
|
|
||||||
# Write file with proper formatting
|
# Write file with proper formatting
|
||||||
tree = ET.ElementTree(tvshow)
|
tree = ET.ElementTree(tvshow)
|
||||||
ET.indent(tree, space=" ", level=0)
|
ET.indent(tree, space=" ", level=0)
|
||||||
|
tree.write(nfo_path, encoding='utf-8', xml_declaration=True)
|
||||||
# Write to string first to add comment
|
|
||||||
xml_str = ET.tostring(tvshow, encoding='unicode')
|
|
||||||
|
|
||||||
# Add XML declaration and comment
|
|
||||||
full_xml = f'<?xml version="1.0" encoding="utf-8"?>\n<!--{comment_text}-->\n{xml_str}'
|
|
||||||
|
|
||||||
# Write to file
|
|
||||||
with open(nfo_path, 'w', encoding='utf-8') as f:
|
|
||||||
f.write(full_xml)
|
|
||||||
|
|
||||||
print(f"✅ Successfully created/updated TV show NFO: {nfo_path}")
|
print(f"✅ Successfully created/updated TV show NFO: {nfo_path}")
|
||||||
print(f" IMDb ID: {imdb_id}" + (f", TVDB ID: {tvdb_id}" if tvdb_id else ""))
|
print(f" IMDb ID: {imdb_id}" + (f", TVDB ID: {tvdb_id}" if tvdb_id else ""))
|
||||||
|
|||||||
Reference in New Issue
Block a user