Repository: Flexget/Flexget

Issue:
Movie name is parsed incorrectly when added to movie queue
Movie name is parsed incorrectly when added to movie queue:

```
C:\Python27\Scripts>flexget.exe -c "C:\Users\orcar_000\Dropbox\Flexget Data\config.yml" -L debug movie-queue add tt3385516
2015-12-20 11:15 DEBUG    manager                       Config file C:\Users\orcar_000\Dropbox\Flexget Data\config.yml selected
2015-12-20 11:15 DEBUG    manager                       sys.defaultencoding: ascii
2015-12-20 11:15 DEBUG    manager                       sys.getfilesystemencoding: mbcs
2015-12-20 11:15 DEBUG    manager                       os.path.supports_unicode_filenames: True
There is a FlexGet process already running for this config, sending execution there.
2015-12-20 11:15 DEBUG    manager                       Sending command to running FlexGet process: [u'-c', u'C:\\Users\\orcar_000\\Dropbox\\Flexget Data\\config.yml', u'-L', u'debug', u'movie-queue',
 u'add', u'tt3385516']
2015-12-20 11:15 DEBUG    task                          Marking config for retreive_from_couchpotato as changed.
2015-12-20 11:15 DEBUG    task                          Marking config for remove_existing_movies_from_queue as changed.
2015-12-20 11:15 DEBUG    task                          Marking config for download_from_trakt_list as changed.
2015-12-20 11:15 DEBUG    task                          Marking config for download_movie_task as changed.
2015-12-20 11:15 DEBUG    task                          Marking config for download_tv_shows as changed.
2015-12-20 11:15 DEBUG    imdb_lookup                   No title passed. Lookup for tt3385516
2015-12-20 11:15 VERBOSE  imdb_lookup                   Parsing imdb for ``
2015-12-20 11:15 DEBUG    requests                      Fetching http://www.imdb.com/title/tt3385516/
2015-12-20 11:15 DEBUG    utils.imdb                    No rating found for tt3385516
2015-12-20 11:15 DEBUG    utils.imdb                    No original title found for tt3385516
2015-12-20 11:15 DEBUG    utils.imdb                    No votes found for tt3385516
2015-12-20 11:15 DEBUG    utils.imdb                    No score found for tt3385516
2015-12-20 11:15 INFO     movie_queue                   Adding X-Men: Apocalypse\n                   (2016)\n                   \n             to movie queue with quality=any.
```



Discussion:
That commit should fix the source problem with the imdb parser, but we could add a db upgrade that looks for newlines in the movie queue names and fixes the data.


Resolving patch:
diff --git a/flexget/plugins/filter/movie_queue.py b/flexget/plugins/filter/movie_queue.py
--- a/flexget/plugins/filter/movie_queue.py
+++ b/flexget/plugins/filter/movie_queue.py
@@ -21,7 +21,7 @@
                                  message='movie_queue requires the queue_base plugin')
 
 log = logging.getLogger('movie_queue')
-Base = db_schema.versioned_base('movie_queue', 2)
+Base = db_schema.versioned_base('movie_queue', 3)
 
 
 @event('manager.lock_acquired')
@@ -65,6 +65,22 @@ def upgrade(ver, session):
                 session.execute(update(movie_table, movie_table.c.id == row['id'],
                                        {'quality': 'ANY'}))
         ver = 2
+    if ver == 2:
+        from flexget.utils.imdb import ImdbParser
+        # Corrupted movie titles may be in the queue due to imdb layout changes. GitHub #729
+        movie_table = table_schema('movie_queue', session)
+        queue_base_table = table_schema('queue', session)
+        query = select([movie_table.c.id, movie_table.c.imdb_id, queue_base_table.c.title])
+        query = query.where(movie_table.c.id == queue_base_table.c.id)
+        for row in session.execute(query):
+            if row['imdb_id'] and (not row['title'] or row['title'] == 'None' or '\n' in row['title']):
+                log.info('Fixing movie_queue title for %s' % row['imdb_id'])
+                parser = ImdbParser()
+                parser.parse(row['imdb_id'])
+                if parser.name:
+                    session.execute(update(queue_base_table, queue_base_table.c.id == row['id'],
+                                           {'title': parser.name}))
+        ver = 3
     return ver
 
 


Test patch: