Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions plugins/DateParser/date_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,21 @@ def parse_date_candidate(string):
return result


GALLERY_FRAGMENT = """
id
title
date
files {
path
}
folder {
path
}
"""

def find_date_for_galleries(settings):

galleries = stash.find_galleries(f={"is_missing": "date"})
galleries = stash.find_galleries(f={"is_missing": "date"}, fragment=GALLERY_FRAGMENT)

total = len(galleries)

Expand All @@ -58,13 +70,19 @@ def find_date_for_galleries(settings):
acceptableDate = None

for file in gallery.get("files", []):
if candidate := parse_date_candidate(file["path"]):
acceptableDate = candidate
file_path = file.get("path", "")
if file_path:
log.debug(f"Checking file path: {file_path}")
if candidate := parse_date_candidate(file_path):
acceptableDate = candidate

if "folder" in gallery and gallery["folder"]:
if "path" in gallery["folder"] and gallery["folder"]["path"]:
if candidate := parse_date_candidate(gallery["folder"]["path"]):
folder_path = gallery["folder"].get("path") or ""
if folder_path:
if candidate := parse_date_candidate(folder_path):
acceptableDate = candidate
else:
log.debug(f"Gallery ID {gallery.get('id')} has a folder entry but no path")

if acceptableDate:
log.info(
Expand All @@ -77,6 +95,8 @@ def find_date_for_galleries(settings):
if settings['setTitle'] and not gallery.get("title") and acceptableDate[1]:
updateObject["title"] = acceptableDate[1]
stash.update_gallery(updateObject)
else:
log.debug(f"Gallery ID ({gallery.get('id')}) - no date found in paths")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion plugins/DateParser/date_parser.yml
Original file line number Diff line number Diff line change
@@ -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.1.0
version: 1.2.0
url: https://discourse.stashapp.cc/t/gallery-date-parser/1330
exec:
- python
Expand Down
Loading