Repository: Flexget/Flexget

Issue:
Unhandled errors on anilist plugin
Hello,

After updating to v3.2.7, I've found two new bugs where introduced on the anilist plugin on 3.2.5. downgrading to 3.2.4 works fine on the same config.

**Partial start/endDate**

When an entry on anilist has a partial date (lacking day or month), start/endDate gets returned as `None` on the request. Passing a default value to get doesn't work as the key is set, causing an exception `an integer is required (got type NoneType)` at datetime().

Sample metadata which triggers this error (see `'day': None` at the very end):
```
{'anime': {'id': 127401, 'status': 'RELEASING', 'title': {'romaji': 'Platinum End', 'english': 'Platinum End'}, 'synonyms': [], 'siteUrl': 'https://anilist.co/anime/127401', 'idMal': 44961, 'format': 'TV', 'episodes': 24, 'trailer': {'site': 'youtube', 'id': 'CVj14rLT1A8'}, 'coverImage':{'large': 'https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx127401-fVKVbuIE5W5Q.jpg'}, 'bannerImage': 'https://s4.anilist.co/file/anilistcdn/media/anime/banner/127401-e27CVSLfGjnb.jpg', 'genres': ['Drama', 'Mystery', 'Psychological', 'Romance', 'Supernatural'], 'tags': [{'name': 'Battle Royale'}, {'name': 'Angels'}, {'name': 'Gods'}, {'name': 'Survival'}, {'name': 'Tragedy'}, {'name': 'Male Protagonist'}, {'name': 'Urban Fantasy'}, {'name': 'Religion'}, {'name': 'Suicide'}, {'name': 'Urban'}, {'name': 'Crime'}, {'name': 'Philosophy'}, {'name': 'Heterosexual'}, {'name': 'Gore'}, {'name': 'Shounen'}, {'name': 'Conspiracy'}, {'name': 'CGI'}, {'name': 'Bullying'}, {'name': 'Yandere'}, {'name': 'Politics'}, {'name': 'Time Skip'}], 'externalLinks': [{'site': 'Twitter', 'url': 'https://twitter.com/ani_platinumend'}, {'site': 'Official Site', 'url': 'https://anime-platinumend.com/'}, {'site': 'Instagram', 'url': 'https://instagram.com/ani_platinumend/'}, {'site': 'Funimation', 'url': 'https://www.funimation.com/shows/platinum-end/'}, {'site': 'Crunchyroll', 'url': 'https://crunchyroll.com/series/G8DHV722J'}, {'site': 'VRV', 'url': 'https://vrv.co/series/G8DHV722J/Platinum-End'}, {'site': 'Hulu', 'url': 'https://www.hulu.com/series/b8a90716-56bd-4831-9027-a5af4ac9a3ab'}], 'startDate': {'year': 2021, 'month': 10, 'day': 8}, 'endDate': {'year': 2022, 'month': 3, 'day': None}}}
```

Stacktrace:
```
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/flexget/components/series/configure_series.py", line 61, in on_task_prepare
    for entry in result:
  File "/usr/local/lib/python3.9/site-packages/flexget/utils/cached_input.py", line 231, in __iter__
    for item in self.iterable:
  File "/usr/local/lib/python3.9/site-packages/flexget/plugins/input/anilist.py", line 163, in on_task_input
    datetime(
TypeError: an integer is required (got type NoneType)
```

**Error on unmapped anime at relations.yuna.moe**

relations.yuna.moe returns HTTP 200 and _null_ body for unmapped anime. This doesn't trigger an `RequestException`, which results in `ids = Null`, causing an error later on `ids.get()`

Sample request: https://relations.yuna.moe/api/ids?source=anilist&id=142329
Stacktrace:
```
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flexget/task.py", line 547, in __run_plugin
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/flexget/event.py", line 20, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/flexget/components/series/configure_series.py", line 61, in on_task_prepare
    for entry in result:
  File "/usr/local/lib/python3.9/site-packages/flexget/utils/cached_input.py", line 231, in __iter__
    for item in self.iterable:
  File "/usr/local/lib/python3.9/site-packages/flexget/plugins/input/anilist.py", line 159, in on_task_input
    entry['al_id'] = anime.get('id', ids.get('anilist'))
AttributeError: 'NoneType' object has no attribute 'get'
```


Discussion:

Resolving patch:
diff --git a/flexget/plugins/input/anilist.py b/flexget/plugins/input/anilist.py
--- a/flexget/plugins/input/anilist.py
+++ b/flexget/plugins/input/anilist.py
@@ -151,6 +151,10 @@ def on_task_input(self, task, config):
                             ids = {}
                             raise plugin.PluginWarning(f'Couldn\'t fetch additional IDs - {e}')
 
+                        if not ids:
+                            ids = {}
+                            raise plugin.PluginWarning(f'Additional IDs not available.')
+
                         entry = Entry()
                         entry['al_id'] = anime.get('id', ids.get('anilist'))
                         entry['anidb_id'] = ids.get('anidb')
@@ -161,8 +165,8 @@ def on_task_input(self, task, config):
                         entry['al_date_end'] = (
                             datetime(
                                 year=anime.get('endDate').get('year'),
-                                month=anime.get('endDate').get('month', 1),
-                                day=anime.get('endDate').get('day', 1),
+                                month=(anime.get('endDate').get('month') or 1),
+                                day=(anime.get('endDate').get('day') or 1),
                             )
                             if anime.get('endDate').get('year')
                             else None
@@ -170,8 +174,8 @@ def on_task_input(self, task, config):
                         entry['al_date_start'] = (
                             datetime(
                                 year=anime.get('startDate').get('year'),
-                                month=anime.get('startDate').get('month', 1),
-                                day=anime.get('startDate').get('day', 1),
+                                month=(anime.get('startDate').get('month') or 1),
+                                day=(anime.get('startDate').get('day') or 1),
                             )
                             if anime.get('startDate').get('year')
                             else None


Test patch: