Repository: Flexget/Flexget

Issue:
list_match: _find_entry does not find a movie title with punctuation stripped, in a list of movies that have not had punctuation stripped
<!---
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!
--->

When using list_match to search for a movie in a movie list, it's not correctly stripping punctuation.  It correctly ignores uppercase/lowercase differences, but gets thrown a single : out of place.

It looks like the issue is in plugins/list/movie_list.py in the `_find_entry` function.  It uses `.lower` to downcase everything when searching, but doesn't strip punctuation.
```res = (self._db_list(session).movies.filter(func.lower(MovieListMovie.title) == name.lower())
               .filter(MovieListMovie.year == year).first())
```

I can't figure out how to change the behavior of the `movies.filter` line correctly or I'd do this myself and submit a pull request (sorry!)

### Expected behaviour:
When supplying a movie title with the punctuation stripped from it (eg a torrent name returned by a tracker plugin during a 'discover'), and search for that in a movie list containing the same title with punctuation intact, it should return the correct movie.

### Actual behaviour:
When supplying a movie title with the punctuation stripped from it (eg a torrent name returned by a tracker plugin during a 'discover'), and search for that in a movie list containing the same title with punctuation intact, it fails to find any matches.

### Steps to reproduce:
- Step 1: Identify a movie on a torrent site that has punctuation in it's title
   eg "Test Movie: The Last Test 2017"
- Step 2: Create a movie-list containing that single movie with punctuation in the title (eg a colon character)
   eg "testlist"
- Step 3: Search for this via a torrent plugin and call list_match from the movie list on the results with an 'accept' action.
- Step 4: Observe that the movie is found by the torrent plugin but remains in the 'undecided' list instead of being accepted

#### Config:
```
variables: secrets.yml

templates:
  global:
    pathscrub: windows
################################################################
# Download settings
  dl-deluge:
    deluge:
      path: /**REDACTED**
      queuetotop: yes
      username: '{? deluge.username ?}'
      password: '{? deluge.password ?}'
      label: "flexget"
################################################################
# Source settings

  # Some extra settings for ratio vs non-ratio sites
  ratiosite:
    set:
      removeatratio: no
    series:
      settings:
        global:
          propers: no
          exact: yes
  torrentleech:
    set:
      identified_by: ep
    template:
      - ratiosite
  type-movie:
    regexp:
      reject:
        - german
        - spanish
        - french
    quality:
      - webrip+ 720p
    proper_movies: no
    content_size:
      min: 300
      max: 10240
      strict: no
################################################################
# Notification settings
  movie-notify:
    notify:
      entries:
        title: 'New Movie'
        message: '"{{title}}"'
        via:
          - email:
              from: flexget@**REDACTED**
              to: **REDACTED**@**REDACTED**
              smtp_host: localhost
              html: yes
################################################################
tasks:
  TORRENTLEECH-TEST:
    discover:
      what:
        - movie_list:
            list_name: "testlist"
            strip_year: no
      from:
        - torrentleech:
            rss_key: '{? torrentleech.rss_key ?}'
            username: '{? torrentleech.username ?}'
            password: '{? torrentleech.password ?}'
      release_estimations: loose
      interval: 2 hours

    # The actual accept step, if the movie we found is in the
    #  list of movies we want (duh), accept it
    # Note that this can get tangled up with special characters if they are
    #  omitted from the titles in the search results
    list_match:
      from:
        - movie_list:
            list_name: "testlist"
            strip_year: no
      action: accept
    template:
      - type-movie
      - torrentleech
      - dl-deluge
      - movie-notify
```
  
#### Log:
(Some minor edits, including changing the movie name (but keeping the format and punctuation) and removing a big stack of rejected results, leaving only one example rejection and one example successful match (well, what *should* have been a successful match)
```
$ flexget -L debug execute --discover-now --tasks TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    manager                       Figuring out config load paths
2017-10-03 08:54 DEBUG    manager                       Adding virtualenv path
2017-10-03 08:54 DEBUG    manager                       Found config: /**REDACTED**/flexget/config.yml
2017-10-03 08:54 DEBUG    manager                       Config file /**REDACTED**/flexget/config.yml selected
2017-10-03 08:54 DEBUG    manager                       sys.defaultencoding: ascii
2017-10-03 08:54 DEBUG    manager                       sys.getfilesystemencoding: UTF-8
2017-10-03 08:54 DEBUG    manager                       flexget detected io encoding: utf-8
2017-10-03 08:54 DEBUG    manager                       os.path.supports_unicode_filenames: False
2017-10-03 08:54 DEBUG    plugin                        Trying to load plugins from: [u'/**REDACTED**/flexget/plugins', '/**REDACTED**/flexget/flexget/local/lib/python2.7/site-packages/flexget/plugins']
2017-10-03 08:54 DEBUG    deluge                        ConfigManager started..
2017-10-03 08:54 DEBUG    plugin                        (u'Plugin `%s` requires `%s` to load.', u'memusage', u'ext lib `guppy`')
2017-10-03 08:54 DEBUG    plugin                        Plugins took 1.76 seconds to load. 276 plugins in registry.
2017-10-03 08:54 DEBUG    manager                       Connecting to: sqlite:////**REDACTED**db-config.sqlite
2017-10-03 08:54 DEBUG    manager                       config_name: config
2017-10-03 08:54 DEBUG    manager                       config_base: /**REDACTED**/flexget
2017-10-03 08:54 DEBUG    variables                     trying to load variables from file
2017-10-03 08:54 DEBUG    variables                     updating DB with variable file contents
2017-10-03 08:54 DEBUG    manager                       New config data loaded.
2017-10-03 08:54 DEBUG    schema                        current flexget version already exist in db 2.10.31
2017-10-03 08:54 DEBUG    parsing                       setting default movie parser to internal. (options: {u'internal': <flexget.plugins.parsers.parser_internal.ParserInternal object at 0x7fe5ced2bf10>, u'guessit': <flexget.plugins.parsers.parser_guessit.ParserGuessit object at 0x7fe5ced2b750>})
2017-10-03 08:54 DEBUG    parsing                       setting default series parser to internal. (options: {u'internal': <flexget.plugins.parsers.parser_internal.ParserInternal object at 0x7fe5ced2bf10>, u'guessit': <flexget.plugins.parsers.parser_guessit.ParserGuessit object at 0x7fe5ced2b750>})
2017-10-03 08:54 DEBUG    cron_env                      Encoding UTF-8 stored
2017-10-03 08:54 DEBUG    util.simple_persistence                 setting key terminal_encoding value 'UTF-8'
2017-10-03 08:54 DEBUG    task_queue                    task queue shutdown requested
2017-10-03 08:54 INFO     ipc.rpyc                      server started on [127.0.0.1]:42321
2017-10-03 08:54 DEBUG    task          TORRENTLEECH-TEST executing TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    template      TORRENTLEECH-TEST Merging template type-movie into task TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    template      TORRENTLEECH-TEST Merging template torrentleech into task TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    template      TORRENTLEECH-TEST Merging template dl-deluge into task TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    template      TORRENTLEECH-TEST Merging template movie-notify into task TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    template      TORRENTLEECH-TEST Merging template global into task TORRENTLEECH-TEST
2017-10-03 08:54 DEBUG    template      TORRENTLEECH-TEST Merging template ratiosite into task TORRENTLEECH-TEST

2017-10-03 08:54 VERBOSE  discover      TORRENTLEECH-TEST Discovering 1 titles ...
2017-10-03 08:54 INFO     discover      TORRENTLEECH-TEST Ignoring interval because of --discover-now
2017-10-03 08:54 VERBOSE  discover      TORRENTLEECH-TEST Searching for `Test Movie: The Last Test` with plugin `torrentleech` (1 of 1)
2017-10-03 08:54 DEBUG    utils.requests TORRENTLEECH-TEST Fetching URL https://www.torrentleech.org/user/account/login/ with args () and kwargs {'data': {u'username': u'**REDACTED**', u'password': u'**REDACTED**'}, u'timeout': 30}
2017-10-03 08:54 DEBUG    torrentleech  TORRENTLEECH-TEST Using https://www.torrentleech.org/torrents/browse/index/query/Test%20Movie%20The%20Last%20Test/categories/0 as torrentleech search url
2017-10-03 08:54 DEBUG    utils.requests TORRENTLEECH-TEST Fetching URL https://www.torrentleech.org/torrents/browse/index/query/Test%20Movie%20The%20Last%20Test/categories/0 with args () and kwargs {'cookies': <RequestsCookieJar[Cookie(version=0, name='PHPSESSID', value='**REDACTED**', port=None, port_specified=False, domain='www.torrentleech.org', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)]>, u'allow_redirects': True, u'timeout': 30}
2017-10-03 08:54 DEBUG    torrentleech  TORRENTLEECH-TEST link phase: Test Movie The Last Test 2017 1080p 3D Blu-ray Re-Encoded MVC Atmos 7 1-munk
2017-10-03 08:54 DEBUG    torrentleech  TORRENTLEECH-TEST RSS-ified download link: https://www.torrentleech.org/rss/download/**REDACTED**/Test.Movie.The.Last.Test.2017.1080p.3D.Blu-ray.Re-Encoded.MVC.Atmos.7.1-munk.torrent
2017-10-03 08:54 DEBUG    torrentleech  TORRENTLEECH-TEST link phase:Test Movie The Last Test 2017 REPACK 720p BluRay x264-WiKi
2017-10-03 08:54 DEBUG    torrentleech  TORRENTLEECH-TEST RSS-ified download link: https://www.torrentleech.org/rss/download/**REDACTED**/Test.Movie.The.Last.Test.2017.REPACK.720p.BluRay.x264-WiKi.torrent

2017-10-03 08:54 DEBUG    discover      TORRENTLEECH-TEST Discovered 2 entries from torrentleech
2017-10-03 08:54 DEBUG    backlog       TORRENTLEECH-TEST 0 entries purged from backlog
2017-10-03 08:54 VERBOSE  details       TORRENTLEECH-TEST Produced 2 entries.

2017-10-03 08:54 VERBOSE  task          TORRENTLEECH-TEST REJECTED: `Test Movie The Last Test 2017 1080p 3D Blu-ray Re-Encoded MVC Atmos 7 1-munk` by quality plugin because 1080p bluray does not match quality requirement [<Requirements(webrip+ 720p)>]

2017-10-03 08:54 DEBUG    content_size  TORRENTLEECH-TEST Test Movie The Last Test 2017 REPACK 720p BluRay x264-WiKi size 7810.59265137 MB
2017-10-03 08:54 DEBUG    parser_internal TORRENTLEECH-TEST Parsing movie: `Test Movie The Last Test 2017 REPACK 720p BluRay x264-WiKi` kwargs: {}
2017-10-03 08:54 DEBUG    movieparser   TORRENTLEECH-TEST parts: [u'Test', u'Movie', u'The', u'Last', u'Test', u'2017', u'REPACK', u'720p', u'BluRay', u'x264-WiKi'], cut is: 2017
2017-10-03 08:54 DEBUG    movieparser   TORRENTLEECH-TEST after parts check, cut data would be: `Test Movie The Last Test` abs_cut: 28
2017-10-03 08:54 DEBUG    movieparser   TORRENTLEECH-TEST quality start: 41
2017-10-03 08:54 DEBUG    movieparser   TORRENTLEECH-TEST data cut to `Test Movie The Last Test` - this will be the name
2017-10-03 08:54 DEBUG    parser_internal TORRENTLEECH-TEST Parsing result: <MovieParser(name=Test Movie The Last Test,year=2017,quality=720p bluray h264)> (in 1.516 ms)
2017-10-03 08:54 DEBUG    movie_list    TORRENTLEECH-TEST trying to match movie based of name: Test Movie The Last Test and year: 2017
2017-10-03 08:54 DEBUG    urlrewriter   TORRENTLEECH-TEST Checking 0 entries
2017-10-03 08:54 VERBOSE  details       TORRENTLEECH-TEST Summary - Accepted: 0 (Rejected: 1 Undecided: 1 Failed: 0)
2017-10-03 08:54 DEBUG    notify_entry  TORRENTLEECH-TEST No entries to notify about.
2017-10-03 08:54 DEBUG    series        TORRENTLEECH-TEST on_task_learn
2017-10-03 08:54 DEBUG    proper_movies TORRENTLEECH-TEST check for learning
2017-10-03 08:54 DEBUG    util.simple_persistence TORRENTLEECH-TEST Flushing simple persistence for task TORRENTLEECH-TEST to db.
2017-10-03 08:54 DEBUG    task_queue                    task queue shut down
2017-10-03 08:54 INFO     ipc.rpyc                      listener closed
2017-10-03 08:54 INFO     ipc.rpyc                      server has terminated
2017-10-03 08:54 DEBUG    util.simple_persistence                 Flushing simple persistence for task None to db.
2017-10-03 08:54 DEBUG    manager                       Shutting down
2017-10-03 08:54 DEBUG    manager                       Removed /**REDACTED**/flexget/.config-lock
```

### Additional information:

- FlexGet version: 2.10.31
- Python version: Python 2.7.12
- Installation method: Virtualenv / Pip
- Using daemon (yes/no): no
- OS and version: Linux Ubuntu 16.04
- Link to crash log: n/a

<!---
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:

Resolving patch:
diff --git a/flexget/plugins/api_rottentomatoes.py b/flexget/plugins/api_rottentomatoes.py
--- a/flexget/plugins/api_rottentomatoes.py
+++ b/flexget/plugins/api_rottentomatoes.py
@@ -3,6 +3,7 @@
 import logging
 import difflib
 import random
+import urllib
 from datetime import datetime, timedelta
 from urllib2 import URLError
 
@@ -423,9 +424,10 @@ def _set_movie_details(movie, session, movie_data=None, api_key=None):
     if movie_data:
         if movie.id:
             log.debug("Updating movie info (actually just deleting the old info and adding the new)")
-            session.delete(movie)
-            session.flush()
-            movie = RottenTomatoesMovie()
+            del movie.release_dates[:]
+            del movie.posters[:]
+            del movie.alternate_ids[:]
+            del movie.links[:]
         movie.update_from_dict(movie_data)
         movie.update_from_dict(movie_data.get('ratings'))
         genres = movie_data.get('genres')
@@ -508,7 +510,7 @@ def lists(list_type, list_name, limit=20, page_limit=20, page=None, api_key=None
 
 def movies_search(q, page_limit=None, page=None, api_key=None):
     if isinstance(q, basestring):
-        q = q.replace(' ', '+').encode('utf-8')
+        q = urllib.quote_plus(q.encode('latin-1', errors='ignore'))
 
     if not api_key:
         api_key = API_KEY


Test patch: