Skip to content

Commit 88863bc

Browse files
authored
[nfoSceneParser] new config options (#586)
1 parent 2f06948 commit 88863bc

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

plugins/nfoSceneParser/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
# ! Not yet implemented. Currently, only "with files" is supported
1111
nfo_location = "with files"
1212

13+
# By default the plugin will look for an nfo based on file name:
14+
# "Movie Title (2023).nfo"
15+
# If you want to use a custom file name eg. "movie.nfo", set it here.
16+
custom_nfo_name = ""
17+
1318
# If True, will never update already "organized" scenes.
1419
skip_organized = True
1520

@@ -41,6 +46,15 @@
4146
create_missing_tags = True
4247
create_missing_movies = True
4348

49+
# Choose which field should be parsed into user rating
50+
# and if it should be multiplied by a factor.
51+
user_rating_field = "userrating"
52+
user_rating_multiplier = 1
53+
54+
# Let you decide from where genres should be loaded from.
55+
# Possible values: "tags", "genres", "both"
56+
load_tags_from = "both"
57+
4458
###############################################################################
4559
# Do not change config below unless you are absolutely sure of what you do...
4660
###############################################################################

plugins/nfoSceneParser/nfoParser.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ def __init__(self, scene_path, defaults=None, folder_mode=False):
1616
self._defaults = defaults
1717
# Finds nfo file
1818
self._nfo_file = None
19+
dir_path = os.path.dirname(scene_path)
1920
if config.nfo_location.lower() == "with files":
2021
if folder_mode:
2122
# look in current dir & parents for a folder.nfo file...
22-
dir_path = os.path.dirname(scene_path)
2323
self._nfo_file = self._find_in_parents(dir_path, "folder.nfo")
2424
else:
25-
self._nfo_file = os.path.splitext(scene_path)[0] + ".nfo"
25+
if len(getattr(config, "custom_nfo_name", "")) > 0:
26+
self._nfo_file = os.path.join(dir_path, config.custom_nfo_name)
27+
else:
28+
self._nfo_file = os.path.splitext(scene_path)[0] + ".nfo"
2629
# else:
2730
# TODO: support dedicated dir instead of "with files" (compatibility with nfo exporters)
2831
self._nfo_root = None
@@ -56,7 +59,7 @@ def __read_cover_image_file(self):
5659
# Not found? Look tor folder image...
5760
path_dir = os.path.dirname(self._nfo_file)
5861
folder_files = sorted(glob.glob(f"{glob.escape(path_dir)}{os.path.sep}*.*"))
59-
folder_pattern = re.compile("^.*(landscape\\d{0,2}|thumb\\d{0,2}|poster\\d{0,2}|cover\\d{0,2})\\.(jpe?g|png|webp)$", re.I)
62+
folder_pattern = re.compile("^.*(landscape\\d{0,2}|thumb\\d{0,2}|poster\\d{0,2}|folder\\d{0,2}|cover\\d{0,2})\\.(jpe?g|png|webp)$", re.I)
6063
result = self.__match_image_files(folder_files, folder_pattern)
6164
return result
6265

@@ -103,7 +106,8 @@ def __extract_cover_images_b64(self):
103106
return file_images
104107

105108
def __extract_nfo_rating(self):
106-
user_rating = round(float(self._nfo_root.findtext("userrating") or 0))
109+
multiplier = getattr(config, "user_rating_multiplier", 1)
110+
user_rating = round(float(self._nfo_root.findtext(getattr(config, "user_rating_field", "userrating")) or 0) * multiplier)
107111
if user_rating > 0:
108112
return user_rating
109113
# <rating> is converted to a scale of 5 if needed
@@ -124,17 +128,20 @@ def __extract_nfo_date(self):
124128
return self._nfo_root.findtext("premiered") or year
125129

126130
def __extract_nfo_tags(self):
131+
source = getattr(config, "load_tags_from", "both").lower()
127132
file_tags = []
128-
# from nfo <tag>
129-
tags = self._nfo_root.findall("tag")
130-
for tag in tags:
131-
if tag.text:
132-
file_tags.append(tag.text)
133-
# from nfo <genre>
134-
genres = self._nfo_root.findall("genre")
135-
for genre in genres:
136-
if genre.text:
137-
file_tags.append(genre.text)
133+
if source in ["tags", "both"]:
134+
# from nfo <tag>
135+
tags = self._nfo_root.findall("tag")
136+
for tag in tags:
137+
if tag.text:
138+
file_tags.append(tag.text)
139+
if source in ["genres", "both"]:
140+
# from nfo <genre>
141+
genres = self._nfo_root.findall("genre")
142+
for genre in genres:
143+
if genre.text:
144+
file_tags.append(genre.text)
138145
return list(set(file_tags))
139146

140147
def __extract_nfo_actors(self):
@@ -147,6 +154,8 @@ def __extract_nfo_actors(self):
147154

148155
def parse(self):
149156
if not self._nfo_file or not os.path.exists(self._nfo_file):
157+
if self._nfo_file:
158+
log.LogDebug(f"The NFO file \"{os.path.split(self._nfo_file)[1]}\" was not found")
150159
return {}
151160
log.LogDebug("Parsing '{}'".format(self._nfo_file))
152161
# Parse NFO xml content

plugins/nfoSceneParser/nfoSceneParser.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: nfoSceneParser
22
description: Fills scene data from NFO or filename pattern
33
url: https://github.com/stashapp/CommunityScripts/tree/main/plugins/nfoSceneParser
4-
version: 1.3.1
4+
version: 1.4.0
55
exec:
66
- python
77
- "{pluginDir}/nfoSceneParser.py"
@@ -16,4 +16,4 @@ tasks:
1616
description: Reload all scenes that have specific "marker" tag (see plugin's config.py)
1717
defaultArgs:
1818
mode: reload
19-
# Last Updated January 3, 2024
19+
# Last Updated June 24, 2025

plugins/nfoSceneParser/stashInterface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def gql_updateScene(self, scene_id, scene_data):
149149
"date": scene_data["date"],
150150
"rating100": scene_data["rating"],
151151
"urls": scene_data["urls"],
152+
"studio_id": scene_data["studio_id"],
152153
"code": scene_data["code"],
153154
"performer_ids": scene_data["performer_ids"],
154155
"tag_ids": scene_data["tag_ids"],

0 commit comments

Comments
 (0)