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
36 changes: 22 additions & 14 deletions plugins/DateParser/date_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ def main():
find_date_for_galleries()


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)
temp = parse(g1 + " " + g2 + " " + g3)
if temp:
result = temp.strftime("%Y-%m-%d")
return result


def find_date_for_galleries():

galleries = stash.find_galleries(
f={
"is_missing": "date",
"path": {"modifier": "MATCHES_REGEX", "value": ".zip$"},
"file_count": {"modifier": "EQUALS", "value": 1},
}
)
galleries = stash.find_galleries(f={"is_missing": "date"})

total = len(galleries)

Expand All @@ -39,14 +45,16 @@ def find_date_for_galleries():
for i, gallery in enumerate(galleries):
log.progress(i / total)
acceptableDate = None

for file in gallery.get("files", []):
for match in pattern.finditer(file["path"]):
g1 = match.group(1)
g2 = match.group(2)
g3 = match.group(3)
temp = parse(g1 + " " + g2 + " " + g3)
if temp:
acceptableDate = temp.strftime("%Y-%m-%d")
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"]):
acceptableDate = candidate

if acceptableDate:
log.info(
"Gallery ID ("
Expand Down
2 changes: 1 addition & 1 deletion plugins/DateParser/date_parser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Gallery Date Parser
description: Find date in path or filename and add it to the gallery
version: 0.2.1
version: 0.3.0
exec:
- python
- "{pluginDir}/date_parser.py"
Expand Down