mirror of
https://github.com/stashapp/CommunityScripts.git
synced 2026-04-27 16:44:09 -05:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 ("
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user