mirror of
https://github.com/stashapp/CommunityScripts.git
synced 2026-04-19 22:44:11 -05:00
[Gallery Date Parser] Fixed issue with trailing dates + added optional title set (#588)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import os
|
||||
import sys, json
|
||||
from PythonDepManager import ensure_import
|
||||
ensure_import("dateparser>=1.2.1")
|
||||
ensure_import("stashapi:stashapp-tools>=0.2.58")
|
||||
ensure_import("stashapi:stashapp-tools")
|
||||
import stashapi.log as log
|
||||
from stashapi.stashapp import StashInterface
|
||||
import re
|
||||
@@ -13,30 +14,38 @@ def main():
|
||||
global pattern
|
||||
|
||||
pattern = re.compile(
|
||||
r"\D(\d{4}|\d{1,2})[\._\- /\\](\d{1,2}|[a-zA-Z]{3,}\.*)[\._\- /\\](\d{4}|\d{1,2})\D"
|
||||
r"\D((\d{4}|\d{1,2})[\._\- /\\](\d{1,2}|[a-zA-Z]{3,}\.*)[\._\- /\\](\d{4}|\d{1,2}))\D*"
|
||||
)
|
||||
json_input = json.loads(sys.stdin.read())
|
||||
mode_arg = json_input["args"]["mode"]
|
||||
|
||||
stash = StashInterface(json_input["server_connection"])
|
||||
|
||||
config = stash.get_configuration()["plugins"]
|
||||
settings = {"setTitle": False}
|
||||
if "date_parser" in config:
|
||||
settings.update(config["date_parser"])
|
||||
if mode_arg == "gallery":
|
||||
find_date_for_galleries()
|
||||
find_date_for_galleries(settings)
|
||||
|
||||
|
||||
def parse_date_candidate(string):
|
||||
result = None
|
||||
for match in pattern.finditer(string):
|
||||
g1 = match.group(1)
|
||||
g2 = match.group(2)
|
||||
g3 = match.group(3)
|
||||
g0 = match.group(1)
|
||||
g1 = match.group(2)
|
||||
g2 = match.group(3)
|
||||
g3 = match.group(4)
|
||||
temp = parse(g1 + " " + g2 + " " + g3)
|
||||
if temp:
|
||||
result = temp.strftime("%Y-%m-%d")
|
||||
potential_title = None
|
||||
_,ext = os.path.splitext(string)
|
||||
if not ext and g0 in os.path.basename(string):
|
||||
potential_title = os.path.basename(string).replace(g0, "").strip()
|
||||
result = [temp.strftime("%Y-%m-%d"), potential_title]
|
||||
return result
|
||||
|
||||
|
||||
def find_date_for_galleries():
|
||||
def find_date_for_galleries(settings):
|
||||
|
||||
galleries = stash.find_galleries(f={"is_missing": "date"})
|
||||
|
||||
@@ -62,9 +71,11 @@ def find_date_for_galleries():
|
||||
"Gallery ID ("
|
||||
+ gallery.get("id")
|
||||
+ ") has matched the date : "
|
||||
+ acceptableDate
|
||||
+ acceptableDate[0]
|
||||
)
|
||||
updateObject = {"id": gallery.get("id"), "date": acceptableDate}
|
||||
updateObject = {"id": gallery.get("id"), "date": acceptableDate[0]}
|
||||
if settings['setTitle'] and not gallery.get("title") and acceptableDate[1]:
|
||||
updateObject["title"] = acceptableDate[1]
|
||||
stash.update_gallery(updateObject)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: Gallery Date Parser
|
||||
# requires: PythonDepManager
|
||||
description: Find date in path or filename and add it to the gallery
|
||||
version: 1.0.0
|
||||
version: 1.1.0
|
||||
exec:
|
||||
- python
|
||||
- "{pluginDir}/date_parser.py"
|
||||
@@ -11,3 +11,8 @@ tasks:
|
||||
description: Add the date on galleries based on their path
|
||||
defaultArgs:
|
||||
mode: gallery
|
||||
settings:
|
||||
setTitle:
|
||||
displayName: Set title ?
|
||||
description: Set title from folder name minus the found date ? Only applies on galleries without titles
|
||||
type: BOOLEAN
|
||||
|
||||
Reference in New Issue
Block a user