Skip to content
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

[Question] How to use condition? #525

Closed
rEnr3n opened this issue Dec 20, 2019 · 8 comments
Closed

[Question] How to use condition? #525

rEnr3n opened this issue Dec 20, 2019 · 8 comments

Comments

@rEnr3n
Copy link

rEnr3n commented Dec 20, 2019

I want to make use of the end part of this url for my directory naming. https://www.instagram.com/p/B6RlaWXJZ3k/

$ gallery-dl -K https://www.instagram.com/p/B6RlaWXJZ3k/
...
sidecar_shortcode
  B6RlaWXJZ3k
...
$ gallery-dl -K https://www.instagram.com/p/B6FtwTBHTUh/
...
sidecar_shortcode
  B6FtwTBHTUh
...
$ gallery-dl -K https://www.instagram.com/p/B5VYa8PHt2w/
...
shortcode
  B5VYa8PHt2w
...
$ gallery-dl -K https://www.instagram.com/p/B432IL0HgiJ/
...
shortcode
  B432IL0HgiJ
...

IG posts with multiple media has sidecar_shortcode while posts with single media has shortcode. How can I use shortcode instead if sidecar_shortcode is missing?

"directory": ["{category}", "{username}", "{date:%Y-%m-%dT%H:%M:%SZ} {sidecar_shortcode}"]
This is my config right now.

@mikf
Copy link
Owner

mikf commented Dec 20, 2019

Not possible at the moment, but it'll probably look something like {sidecar_shortcode|shortcode} (meaning: "use sidecar_shortcode and, if that's not defined, fall back to shortcode")

Maybe it would also be in order to change/cleanup the (sidecar_)shortcode labels, so that shortcode is always the top-level code and sidecar_shortcode (or some other name) is the code of child media objects

@rEnr3n
Copy link
Author

rEnr3n commented Dec 21, 2019

Not possible at the moment, but it'll probably look something like {sidecar_shortcode|shortcode} (meaning: "use sidecar_shortcode and, if that's not defined, fall back to shortcode")

I would like this as a generic solution.

Maybe it would also be in order to change/cleanup the (sidecar_)shortcode labels, so that shortcode is always the top-level code and sidecar_shortcode (or some other name) is the code of child media objects

And +1 for consistency.

mikf added a commit that referenced this issue Feb 16, 2020
The format string '{a|b|c}' will now try to use the value from 'a' and
fall back to 'b' and 'c' if accessing a field raises an exception or
if its value is None.
@mikf
Copy link
Owner

mikf commented Feb 16, 2020

I would like this as a generic solution.

That's now implemented in v.1.13.0.

And +1 for consistency

Well, I ultimately didn't change anything in that regard, because it actually is consistent as is:

  • shortcode always references the individual image/video in question and is also the top-level code for posts with just one image/video
  • sidecar_shortcode references the top-level "SideCar" object for posts with multiple images/videos

So {shortcode} is always the image shortcode and {sidecar_shortcode|shortcode} is always the top-level shortcode

@God-damnit-all
Copy link
Contributor

God-damnit-all commented Sep 17, 2020

@mikf I'm dealing with a submission that erroneously has a None date. Unfortunately, my filename string breaks when you customize the format string like this: {date:.%Y%m%d_%H%M%S}
[error] FilenameFormatError: Applying filename format string failed (TypeError: unsupported format string passed to NoneType.__format__)

When changed to just {date}, it instead prints the text 'None'. A fallback will work without customizing the date format, but all my files are already in the other style. Ideally, I want it to be blank when I hit a rogue submission that doesn't have date metadata for whatever reason.

Ideally I would like something akin to {date:.%Y%m%d_%H%M%S|} (a pipe with no fallback), where if it catches that NoneType.__format__ error, it is instead blank.

@mikf
Copy link
Owner

mikf commented Sep 17, 2020

Try {date:?//%Y%m%d_%H%M%S}. This will either be the formatted date, or an empty string if date is None (or any other falsey value).

The | gets only recognized in the data-selection part before the :, by the way: {date1|date2|date3:%Y%m%d}

@God-damnit-all
Copy link
Contributor

@mikf That works, thank you.

@rEnr3n
Copy link
Author

rEnr3n commented Sep 18, 2020

@mikf For twitter, how can I fallback to tweet_id if retweet_id is 0?

I want my config like this:
"directory": ["{category}", "{author[name]}", "{date:%Y-%m-%dT%H:%M:%SZ} {retweet_id|tweet_id}"]

mikf added a commit that referenced this issue Sep 20, 2020
… and not just None (#525)

It would be better to consistently use None for all non-existent
fields and/or fields without a valid value, but this is a good
enough workaround for now.
@mikf
Copy link
Owner

mikf commented Sep 20, 2020

@rEnr3n {retweet_id|tweet_id} should now work: 65744a7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants