Skip to content

[add] anilist: Include more metadata (al_date_start, al_date_end, mal_id)#3273

Merged
gazpachoking merged 4 commits intoFlexget:developfrom
BrutuZ:anilist-patch
Dec 14, 2021
Merged

[add] anilist: Include more metadata (al_date_start, al_date_end, mal_id)#3273
gazpachoking merged 4 commits intoFlexget:developfrom
BrutuZ:anilist-patch

Conversation

@BrutuZ
Copy link
Copy Markdown
Contributor

@BrutuZ BrutuZ commented Dec 7, 2021

Motivation for changes:

Needed the airing dates (start and end) for additional filtering in my config.
Could also use other databases' IDs - AniDB in particular - to optimize Plex matching by automatically generating anidb2.id files for ASS\HAMA upon entry acceptance)

Detailed changes:

  • Additional fields on existing GraphQL request
  • New request to API that crossmatches different Databases
  • Renamed al_idMal field for more sensible mal_id

Config usage if relevant (new plugin or updated schema):

- {{al_idMal}}
+ {{mal_id}}
+ {{al_date_start}} {{al_date_end}}

raise plugin.PluginWarning(f'Couldn\'t fetch additional IDs - {e}')

entry = Entry()
entry['al_id'] = anime.get('id') or ids.get('anilist')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally it's better to do

anime.get('id', ids.get('anilist'))

because using or depends how return value of "id" evaluates in boolean context, not if the field is present or not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I did get scolded once in another project for nesting and chaining get() so I "learned" to favor the or syntax 😅

TBF this fallback isn't even necessary, id is a required field (possibly the only one) as it's the index. This or ends up more like a documentation that the field is available from that second API due to the short-circuit, so I could just comment it instead.
idMAL on the other hand might not be present, but if it is the value is also an integer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaa, yeah. I am always a bit torn on this subject. But I think the nesting is correct way as using or does not work as expected if value is 0 or "" for example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely unexpected, both 0 and "" would be invalid after all xD

@paranoidi
Copy link
Copy Markdown
Member

Looks good to me

@BrutuZ BrutuZ requested a review from paranoidi December 8, 2021 22:46
json={'anilist': anime.get('id')},
).json()
except RequestException as e:
ids = {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set ids to empty dict here? It's not used ... ?

Also, exception chaining is generally a good idea.

(Besides this PR, holy batman that's a wide exception handing for ValueError)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the request isn't successful and ids isn't set then the ids.get() calls below will return exceptions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you're raising PluginWarning immediately after .. which stops the whole plugin execution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realise PluginWarning also stopped execution, thought it just... warned, and PluginError was the one that'd stop execution

@paranoidi
Copy link
Copy Markdown
Member

Feel free to merge this in any time, I think you have the rights :)

@BrutuZ
Copy link
Copy Markdown
Contributor Author

BrutuZ commented Dec 9, 2021

holy batman that's a wide exception handing for ValueError

That never happened 🤐

@BrutuZ
Copy link
Copy Markdown
Contributor Author

BrutuZ commented Dec 14, 2021

Feel free to merge this in any time, I think you have the rights :)

I do not. Usually @gazpachoking pushes the button that does the thing xD

Side-note: GitHub's diff view doesn't do any favors when lines only have indentation changes 👀

@gazpachoking gazpachoking merged commit e3f2fb5 into Flexget:develop Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants