Repository: Flexget/Flexget

Issue:
metainfo_series NoneType split
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->
### Expected behaviour:
metainfo_series with no issues.

### Actual behaviour:
metainfo_series crashes when calling `parser_common.normalize_name`

### Steps to reproduce:
- Step 1: Have a naughtily named file like "Ep 02.mkv"
- Step 2: Use metainfo_series

#### Config:
N/A
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
2018-12-10 19:39 DEBUG    parser_guessit moving_anime    Parsing series: `Ep 02` [options: {'name': None, 'identified_by': 'auto', 'allow_seasonless': False}]
2018-12-10 19:39 DEBUG    parser_guessit moving_anime    Parsing result: <SeriesParseResult(data=Ep 02,name=None,id=2,season=0,season_pack=False,episode=2,quality=unknown,pro
per=0,special=False,status=OK)> (in 31.31600000006074 ms)
2018-12-10 19:39 CRITICAL task          moving_anime    BUG: Unhandled error in plugin metainfo_series: 'NoneType' object has no attribute 'split'
2018-12-10 19:39 CRITICAL manager       moving_anime    An unexpected crash has occurred. Writing crash report to /config/crash_report.2018.12.10.193956695553.log. Please ver
ify you are running the latest version of flexget by using "flexget -V" from CLI or by using version_checker plugin at http://flexget.com/wiki/Plugins/version_checker. You ar
e currently using version 2.17.18
2018-12-10 19:39 DEBUG    manager       moving_anime    Traceback:
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/flexget/task.py", line 486, in __run_plugin
    return method(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/flexget/event.py", line 23, in __call__
    return self.func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/flexget/plugins/metainfo/series.py", line 32, in on_task_metainfo
    self.guess_entry(entry)
  File "/usr/lib/python3.6/site-packages/flexget/plugins/metainfo/series.py", line 49, in guess_entry
    parsed.name = normalize_name(remove_dirt(parsed.name))
  File "/usr/lib/python3.6/site-packages/flexget/plugins/parsers/parser_common.py", line 103, in normalize_name
    name = capwords(name)
  File "/usr/lib/python3.6/string.py", line 48, in capwords
    return (sep or ' ').join(x.capitalize() for x in s.split(sep))
AttributeError: 'NoneType' object has no attribute 'split'
2018-12-10 19:39 WARNING  task          moving_anime    Aborting task (plugin: metainfo_series)
```
</details>

### Additional information:

- FlexGet version: 2.17.18
- Python version: 3.6ish
- Installation method: docker, through pip
- Using daemon (yes/no): yes
- OS and version: Alpine Linux 3.8 (docker container)

I was going to fix this myself, but wasn't sure the best way to do it. The option lies between `metainfo_series` and `parser_common`. However, in `parser_common`, all the function does is call `str.capwords`.  As I type this out, it is probably ideal to handle this in the `normalize_name` function so others don't have to implement this. I'll hash this out right now in a pull request.
 
<!---
In config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.

Please verify that the following data is present before submitting your issue:

- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.
- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).
- FlexGet version (use `flexget -V` to get it).
- Full Python version, for example `2.7.11` (use `python -V` to get it). Note that FlexGet is not supported for use with Python v3.0, 3.1, 3.2 or 3.6.
- Installation method (pip, git install, etc).
- Whether or not you're running FlexGet as a daemon.
- OS and version.
- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.
--->



Discussion:
Seems like a `parser_guessit` problem to me. It doesn't invalidate the parsing properly as I mentioned in Gitter.
Probably add a check here to see if there was a parsed name, then return invalid if there isn't one. https://github.com/Flexget/Flexget/blob/develop/flexget/plugins/parsers/parser_guessit.py#L228

Resolving patch:
diff --git a/flexget/plugins/parsers/parser_guessit.py b/flexget/plugins/parsers/parser_guessit.py
--- a/flexget/plugins/parsers/parser_guessit.py
+++ b/flexget/plugins/parsers/parser_guessit.py
@@ -226,7 +226,9 @@ def parse_series(self, data, **kwargs):
         country = guess_result.get('country')
         if not name:
             name = guess_result.get('title')
-            if country and hasattr(country, 'alpha2'):
+            if not name:
+                valid = False
+            elif country and hasattr(country, 'alpha2'):
                 name += ' (%s)' % country.alpha2
         elif guess_result.matches['title']:
             # Make sure the name match is up to FlexGet standards


Test patch: