Repository: Flexget/Flexget

Issue:
AniList crashing with custom lists
### Expected behaviour:
Parse AniList by status, ignore custom lists since they are duplicate entries from status lists.

### Actual behaviour:
Trying to parse custom lists cause a crash
### Steps to reproduce:
- Step 1: Try to parse an AniList account with a custom list.

#### Config:
```yaml
Paste FULL config and remove any personal info if config is too long, attach the file to the ticket.
If issue is with a single task, you can get get resulting configuration by running:
  flexget execute --task <NAME> --dump-config
Make sure to redact any personal information (passwords, api keys, etc) !
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
2020-03-18 10:22:25 CRITICAL task_queue                    BUG: Unhandled exception during task queue run loop.
2020-03-18 10:22:25 DEBUG    scheduler                     task finished executing: fill-anime-movies-list
Traceback (most recent call last):
  File "github\flexget\flexget\task_queue.py", line 46, in run
    self.current_task.execute()
  File "github\flexget\flexget\task.py", line 80, in wrapper
    return func(self, *args, **kw)
  File "github\flexget\flexget\task.py", line 697, in execute
    self._execute()
  File "github\flexget\flexget\task.py", line 663, in _execute
    self.__run_task_phase(phase)
  File "github\flexget\flexget\task.py", line 492, in __run_task_phase
    for e in response:
  File "github\flexget\flexget\utils\cached_input.py", line 217, in __iter__
    for item in self.iterable:
  File "github\flexget\flexget\plugins\input\anilist.py", line 133, in on_task_input
    entry['al_list_status'] = list_status['status'].capitalize()
AttributeError: 'NoneType' object has no attribute 'capitalize'
```
</details>

### Additional information:

- FlexGet version: 3.1.34
- Python version: 3.7
- Installation method: git
- Using daemon (yes/no): yes
- OS and version: Win10
- Link to crash log: N/A



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
@@ -26,7 +26,7 @@ class AniList(object):
 
     Syntax:
     anilist:
-      username: <value>
+      username: <string>
       status:
         - <current|planning|completed|dropped|paused|repeating>
         - <current|planning|completed|dropped|paused|repeating>
@@ -39,6 +39,10 @@ class AniList(object):
         - <all|tv|tv_short|movie|special|ova|ona>
         - <tv|tv_short|movie|special|ova|ona>
         ...
+      list:
+        - <string>
+        - <string>
+        ...
     """
 
     schema = {
@@ -57,6 +61,7 @@ class AniList(object):
                     'format': one_or_more(
                         {'type': 'string', 'enum': ANIME_FORMAT}, unique_items=True
                     ),
+                    'list': one_or_more({'type': 'string'}),
                 },
                 'required': ['username'],
                 'additionalProperties': False,
@@ -68,11 +73,10 @@ class AniList(object):
     def on_task_input(self, task, config):
         if isinstance(config, str):
             config = {'username': config}
-        selected_list_status = config['status'] if 'status' in config else ['current', 'planning']
-        selected_release_status = (
-            config['release_status'] if 'release_status' in config else ['all']
-        )
-        selected_formats = config['format'] if 'format' in config else ['all']
+        selected_list_status = config.get('status', ['current', 'planning'])
+        selected_release_status = config.get('release_status', ['all'])
+        selected_formats = config.get('format', ['all'])
+        selected_list_name = config.get('list', [])
 
         if not isinstance(selected_list_status, list):
             selected_list_status = [selected_list_status]
@@ -83,6 +87,10 @@ def on_task_input(self, task, config):
         if not isinstance(selected_formats, list):
             selected_formats = [selected_formats]
 
+        if not isinstance(selected_list_name, list):
+            selected_list_name = [selected_list_name]
+        selected_list_name = [i.lower() for i in selected_list_name]
+
         logger.debug('Selected List Status: {}', selected_list_status)
         logger.debug('Selected Release Status: {}', selected_release_status)
         logger.debug('Selected Formats: {}', selected_formats)
@@ -99,7 +107,8 @@ def on_task_input(self, task, config):
                 f'query ($user: String){{ collection: MediaListCollection(userName: $user, '
                 f'type: ANIME, perChunk: 500, chunk: {req_chunk}, status_in: '
                 f'[{", ".join([s.upper() for s in selected_list_status])}]) {{ hasNextChunk, '
-                f'statuses: lists{{ status, list: entries{{ anime: media{{ {req_fields} }}}}}}}}}}'
+                f'statuses: lists{{ status, name, list: entries{{ anime: media{{ {req_fields}'
+                f' }}}}}}}}}}'
             )
 
             try:
@@ -114,6 +123,11 @@ def on_task_input(self, task, config):
                 list_response = list_response.json()['data']
                 logger.debug('JSON output: {}', list_response)
                 for list_status in list_response['collection']['statuses']:
+                    if (
+                        selected_list_name
+                        and list_status['name'].lower() not in selected_list_name
+                    ):
+                        continue
                     for anime in list_status['list']:
                         anime = anime['anime']
                         has_selected_release_status = (
@@ -130,7 +144,12 @@ def on_task_input(self, task, config):
                             entry['al_title'] = anime['title']
                             entry['al_format'] = anime['format']
                             entry['al_release_status'] = anime['status'].capitalize()
-                            entry['al_list_status'] = list_status['status'].capitalize()
+                            entry['al_list'] = list_status['name']
+                            entry['al_list_status'] = (
+                                list_status['status'].capitalize()
+                                if list_status.get('status')
+                                else ''
+                            )
                             entry['alternate_name'] = anime.get('synonyms', [])
                             if (
                                 anime['title'].get('english')


Test patch: