-
-
Notifications
You must be signed in to change notification settings - Fork 941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global function to hash string values #3679
Comments
This is also useful for detecting edits to text content on DeviantArt (e.g. journals and status updates). In this case it's not even necessary to use a postprocessor. |
I added |
"postprocessors": [{
"filter": "subcategory in ('artworks', 'work')",
"name": "metadata",
"mode": "custom",
"event": "post",
"archive": "~/gallery-dl/gallery-dl-pixiv-postprocessor.sqlite",
"archive-prefix": "\fF {category}",
"archive-format": "{id}_{hash_sha1(caption)[:10]}",
"directory": "metadata",
"filename": "\fF [{category}] {user['id']}—{id}—{user['name']}—{date.strftime('%Y.%m.%d')}—{title}—{hash_sha1(caption)[:10]}.html",
"content-format": "\fT ~/gallery-dl/templates/pixiv.html",
"mtime": true
}] pixiv.html: <div id="{id}">
<h4>
<a href="https://www.pixiv.net/artworks/{id}">{title}</a> by <a href="https://www.pixiv.net/users/{user[id]}">{user[name]}</a>
</h4>
<div class="content">{caption}</div>
<hr>
<div>{user[id]}—{id}—{date:%Y.%m.%d %H:%M:%S}{frames[0][delay]:?<br>Ugoira delay: / ms/}</div>
<hr>
<div class="tags">{tags:?["/"]/J", "}</div>
<hr>
</div>
The related note: Use Edit: here is the fixed line: "filename": "\fF [{category}] {user['id']}—{id}—{user['name']}—{date.strftime('%Y.%m.%d')}—{title}—{hash_sha1(caption)[:10]}.html", |
|
Found the problem.
On a side note: Archives now support setting PRAGMAs like |
It would be useful to have a global function to hash string values in order to use it in f-string templates.
This function should return a hex-string hash (md5, sha1 are more than enough).
Something like
string_hash(content)
->"a1b234ff..."
(string -> utf8 string bytes -> hash bytes -> hex string).It can be used in a meta download archive when there is no information what a post was edited.
In this case you can create a postprocessor that will fire the first time and only when the post was edited (when
content
/description
/caption
/... property was changed.)A postprocessor could look something like this:
Note:
\fF
— to use f-string formatting (for using a regular Python code inside{}
).[:10]
just to limit the hash string length, since 10 character is pretty enough.This approach will work fine with Kemono, Pixiv, for example. (They have not information about text content editing. Mastodon have it, in comparison.)
The text was updated successfully, but these errors were encountered: