mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.69k stars 954 forks source link

[DeviantArt] Filter by Image Ratio #4225

Closed BlueSpiders99 closed 1 year ago

BlueSpiders99 commented 1 year ago

I'm trying to create a filter that applies a post-processor if the image is of a certain ratio - greater or less than 2:1 height:width. However, nothing I try is working, including the ["width >= 1200", "width/height > 1.2"] example given on the documentation page. It simply doesn't recognize "width" as a valid argument, despite the fact that it shows up when I run with the -K flag (content['width'] 1500 ).

Failed attempts (attempting a width-under-2k filter for simplicity):

          "filter": "{content[width]} < 2000",
          "filter": "{width} < 2000",
          "filter": "width < 2000",
          "filter": "(width < 2000)",
          "filter": "'width' < 2000", (this one it's understandably unhappy because I'm comparing a string and an int)
          "filter": ["width < 2000"], (this one just isn't recognized as a filter at all, despite matching the docs page best.)

Here's the error I get, in all cases except those last two:

C:\Users\USERNAME\gallery-dl\deviantart\sandara\Windsurfing-sandara-931293806.jpg[deviantart][error] An unexpected error occurred: NameError - name 'width' is not defined. Please run gallery-dl again with the --verbose flag, copy its output and report this issue on https://github.com/mikf/gallery-dl/issues .

And here's the output with the --verbose flag:

[gallery-dl][debug] Version 1.25.6
[gallery-dl][debug] Python 3.10.11 - Windows-10-10.0.19045-SP0
[gallery-dl][debug] requests 2.31.0 - urllib3 2.0.3
[gallery-dl][debug] Configuration Files ['%USERPROFILE%\\gallery-dl\\config.json']
[gallery-dl][debug] Starting DownloadJob for 'https://www.deviantart.com/sandara/art/Windsurfing-931293806'
[deviantart][debug] Using DeviantartDeviationExtractor for 'https://www.deviantart.com/sandara/art/Windsurfing-931293806'
[deviantart][debug] Using custom API credentials (client-id CLIENTID)
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.deviantart.com:443
[urllib3.connectionpool][debug] https://www.deviantart.com:443 "GET /api/v1/oauth2/user/profile/sandara HTTP/1.1" 200 1474
[urllib3.connectionpool][debug] https://www.deviantart.com:443 "GET /sandara/art/931293806 HTTP/1.1" 200 None
[urllib3.connectionpool][debug] https://www.deviantart.com:443 "GET /api/v1/oauth2/deviation/6CCCCB2C-CE23-4665-E8B2-CD25BE2997DC HTTP/1.1" 200 1254
[urllib3.connectionpool][debug] https://www.deviantart.com:443 "GET /api/v1/oauth2/deviation/metadata?deviationids%5B0%5D=6CCCCB2C-CE23-4665-E8B2-CD25BE2997DC&mature_content=true HTTP/
1.1" 200 407
[deviantart][debug] Active postprocessor modules: [MetadataPP, MetadataPP]
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com:443
[urllib3.connectionpool][debug] https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com:443 "GET /f/31a92255-861d-40f4-ad78-a2efd309b0d2/dfeguwe-57e680e2-fd92-4589-8e18-93e381045622.jp
g?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI
6W1t7InBhdGgiOiJcL2ZcLzMxYTkyMjU1LTg2MWQtNDBmNC1hZDc4LWEyZWZkMzA5YjBkMlwvZGZlZ3V3ZS01N2U2ODBlMi1mZDkyLTQ1ODktOGUxOC05M2UzODEwNDU2MjIuanBnIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmx
vYWQiXX0.r2oYFPiSc9pXxT4k6Y29ebBBxo5vWhSYhfGXZVa3CGE HTTP/1.1" 200 968988
[downloader.http][debug] Unable to resume partial download
  C:\Users\USERNAME\gallery-dl\deviantart\sandara\Windsurfing-sandara-931293806.jpg[deviantart][error] An unexpected error occurred: NameError - name 'width' is not defined. Please run 
gallery-dl again with the --verbose flag, copy its output and report this issue on https://github.com/mikf/gallery-dl/issues .
[deviantart][debug] 
Traceback (most recent call last):
  File "C:\Users\USERNAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gallery_dl\job.py", line 97, in run
    self.dispatch(msg)
  File "C:\Users\USERNAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gallery_dl\job.py", line 141, in dispatch
    self.handle_url(url, kwdict)
  File "C:\Users\USERNAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gallery_dl\job.py", line 291, in handle_url
    callback(pathfmt)
  File "C:\Users\USERNAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gallery_dl\job.py", line 549, in _call_hook
    if condition(pathfmt.kwdict):
  File "<expr>", line 1, in <module>
NameError: name 'width' is not defined

Here's the postprocessor with the filter that I was using in this particular case.

        {
          "name": "metadata",
          "filter": "width < 2000",
          "filename": "{title}-{author[username]}-{index}.html",
          "content-format": "\fT C:\\Users\\USERNAME\\gallery-dl\\templates\\da_template_lightbox.html"
        },
BlueSpiders99 commented 1 year ago

Fixed. It was "filter": "content['width'] < 2000",