Skip to content

Commit 49e4156

Browse files
Parse All Galleries for date (#507)
* Parse All Galleries for date - Break out the date parsing to a separate function. - Expand gallery search to more than single file zip galleries. - Also scan the gallery's folder path if available. The final valid parsed date of the files, then the gallery folder will be taken as the gallery's date. This will preserve the previous behavior of single file zip galleries, as there will be only one path to ever consider. * Revert to previous logic Previous logic returned the last possible valid date string in the path string, which is the more correct approach when a parent directory might also have a date string. * formatting * bump version * Cleanup lingering prototype line
1 parent c414e47 commit 49e4156

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

plugins/DateParser/date_parser.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ def main():
2222
find_date_for_galleries()
2323

2424

25+
def parse_date_candidate(string):
26+
result = None
27+
for match in pattern.finditer(string):
28+
g1 = match.group(1)
29+
g2 = match.group(2)
30+
g3 = match.group(3)
31+
temp = parse(g1 + " " + g2 + " " + g3)
32+
if temp:
33+
result = temp.strftime("%Y-%m-%d")
34+
return result
35+
36+
2537
def find_date_for_galleries():
2638

27-
galleries = stash.find_galleries(
28-
f={
29-
"is_missing": "date",
30-
"path": {"modifier": "MATCHES_REGEX", "value": ".zip$"},
31-
"file_count": {"modifier": "EQUALS", "value": 1},
32-
}
33-
)
39+
galleries = stash.find_galleries(f={"is_missing": "date"})
3440

3541
total = len(galleries)
3642

@@ -39,14 +45,16 @@ def find_date_for_galleries():
3945
for i, gallery in enumerate(galleries):
4046
log.progress(i / total)
4147
acceptableDate = None
48+
4249
for file in gallery.get("files", []):
43-
for match in pattern.finditer(file["path"]):
44-
g1 = match.group(1)
45-
g2 = match.group(2)
46-
g3 = match.group(3)
47-
temp = parse(g1 + " " + g2 + " " + g3)
48-
if temp:
49-
acceptableDate = temp.strftime("%Y-%m-%d")
50+
if candidate := parse_date_candidate(file["path"]):
51+
acceptableDate = candidate
52+
53+
if "folder" in gallery and gallery["folder"]:
54+
if "path" in gallery["folder"] and gallery["folder"]["path"]:
55+
if candidate := parse_date_candidate(gallery["folder"]["path"]):
56+
acceptableDate = candidate
57+
5058
if acceptableDate:
5159
log.info(
5260
"Gallery ID ("

plugins/DateParser/date_parser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Gallery Date Parser
22
description: Find date in path or filename and add it to the gallery
3-
version: 0.2.1
3+
version: 0.3.0
44
exec:
55
- python
66
- "{pluginDir}/date_parser.py"

0 commit comments

Comments
 (0)