Repository: Flexget/Flexget

Issue:
trakt_list does not retrieve watched episodes
<!---
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:
Flexget retrieves a list of all watched Episodes from Trakt.
<!---
Please don't just say "it doesn't crash" or "it works". Explain what the expected result is.
--->

### Actual behaviour:
The trakt_list plugin returns a CRITICAL error of Could not retrieve list from trakt (405 Client Error: Method Not Allowed for url: https://api.trakt.tv/users/me/watched/episodes)

### Steps to reproduce:
- Step 1: Set up the Trakt plugin with a valid login.
- Step 2: Create a config to retrieve trakt_list / watched / episodes as per the config below...
- Step 3: Execute the code.

#### Config:
```
tasks:
  get_trakt_watched_eps:
    seen: local
    trakt_list:
      account: xxxxxxxx
      list: watched
      type: episodes
    accept_all: yes
    list_add:
      - entry_list: watched_eps
```
  
#### Log:
```
2018-01-05 22:29 VERBOSE  trakt_list    get_trakt_watched_eps Retrieving `episodes` list `watched`
2018-01-05 22:29 CRITICAL plugin        get_trakt_watched_eps Could not retrieve list from trakt (405 Client Error: Method Not Allowed for url: https://api.trakt.tv/users/me/watched/episodes)
2018-01-05 22:29 WARNING  task          get_trakt_watched_eps Aborting task (plugin: trakt_list)
```

### Additional information:

- FlexGet version: 2.11.18
- Python version: 2.7.10
- Installation method: pip
- Using daemon (yes/no): yes
- OS and version: macOS 10.13.3
- Link to crash log: n/a

For info, my Trakt config works for retrieving watched Series or watched Movies but not Episodes. 

<!---
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:
This is not supported by the Trakt API (https://trakt.docs.apiary.io/#reference/users/watched/get-watched). This is therefore not a bug but a feature request. I'd ask you to reopen this on feathub but it appears to be down, so I'll leave this open for now.
As discovered by gazpachoking there's an endpoint that could support it if trakt_list would get updated.

```
[22:05:18]  gazpachoking	https://trakt.docs.apiary.io/#reference/sync/get-history/get-watched-history
[22:05:23]  gazpachoking	I think that could do it
[22:05:37]  gazpachoking	Might just be a matter of updating our trakt_list to support it
```

Resolving patch:
diff --git a/flexget/plugins/list/trakt_list.py b/flexget/plugins/list/trakt_list.py
--- a/flexget/plugins/list/trakt_list.py
+++ b/flexget/plugins/list/trakt_list.py
@@ -245,9 +245,14 @@ def invalidate_cache(self):
         self._items = None
 
     def get_list_endpoint(self, remove=False, submit=False):
-        # Api restriction, but we could easily extract season and episode info from the 'shows' type
         if not submit and self.config['list'] in ['collection', 'watched'] and self.config['type'] == 'episodes':
-            raise plugin.PluginError('`type` cannot be `%s` for %s list.' % (self.config['type'], self.config['list']))
+            # API restriction as they don't have an endpoint for collected episodes yet
+            if self.config['list'] == 'collection':
+                raise plugin.PluginError('`type` cannot be `episodes` for collection list.')
+            if self.config.get('account'):
+                return ('sync', 'history', 'episodes')
+            else:
+                raise plugin.PluginError('A trakt `account` needs to be configured to get the episode history.')
 
         if self.config['list'] in ['collection', 'watchlist', 'watched', 'ratings']:
             if self.config.get('account'):


Test patch: