Repository: Flexget/Flexget

Issue:
seen_movies 'scope: local' not working properly.
This may be just a configuration issue, so, please advise.

```
 templates:
   local_template:
     disable:
       - seen
       - seen_info_hash
       - retry_failed

   local_movies_template:
     accept_all: yes
     imdb_lookup: yes
     <lots of unrelated stuff removed>

   local_movies_to_queue_template:
     imdb_required: yes
     exec:
       fail_entries: yes
       on_output:
         for_accepted:
           <lots of unrelated stuff removed>

 tasks:
   local_movies:
     filesystem:
       path: '{{secrets.paths.in}}/movies'
       regexp: '.*\.(avi|mkv|mp4|m4v|iso)$'
       recursive: true
       retrieve: files
     template:
       - local_template
       - local_movies_template
       - local_movies_to_queue_template
     seen_movies:
       matching: strict
       **scope: local**

```

```
2016-05-07 19:49 VERBOSE  task          **local_subs_movies** REJECTED: `Risen.2016.1080p.BluRay.x264.DTS-JYK` by seen_movies plugin because entry with imdb_id `tt3231054` is already marked seen in the task **local_movies** at 2016-05-06 10:41

```

```
$ sqlite3 db-local.sqlite 
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select local from seen_entry where feed='local_movies' group by local;
0
sqlite> 
```

Isn't it supposed to set local=1 to all seen_entry from this task/feed ?? Can it be some conflict because i disabled 'seen' plugin and still using 'seen_movies' ?



Discussion:

Resolving patch:
diff --git a/flexget/plugins/filter/seen.py b/flexget/plugins/filter/seen.py
--- a/flexget/plugins/filter/seen.py
+++ b/flexget/plugins/filter/seen.py
@@ -294,7 +294,7 @@ def learn(self, task, entry, fields=None, reason=None, local=False):
             remembered.append(entry[field])
             sf = SeenField(str(field), str(entry[field]))
             se.fields.append(sf)
-            log.debug("Learned '%s' (field: %s)" % (entry[field], field))
+            log.debug("Learned '%s' (field: %s, local: %d)" % (entry[field], field, local))
         # Only add the entry to the session if it has one of the required fields
         if se.fields:
             task.session.add(se)
diff --git a/flexget/plugins/filter/seen_movies.py b/flexget/plugins/filter/seen_movies.py
--- a/flexget/plugins/filter/seen_movies.py
+++ b/flexget/plugins/filter/seen_movies.py
@@ -63,6 +63,11 @@ def on_task_filter(self, task, config):
                     else:
                         accepted_ids[field].add(entry[field])
 
+    def on_task_learn(self, task, config):
+        if not isinstance(config, dict):
+            config = {'matching': config}
+        # call super
+        super(FilterSeenMovies, self).on_task_learn(task, config.get('scope', True))
 
 @event('plugin.register')
 def register_plugin():


Test patch:
diff --git a/tests/test_seen.py b/tests/test_seen.py
--- a/tests/test_seen.py
+++ b/tests/test_seen.py
@@ -110,6 +110,7 @@ class TestFilterSeenMovies(object):
               - {title: 'Seen movie title 4', url: 'http://localhost/seen_movie4', imdb_id: 'tt0103064'}
               - {title: 'Seen movie title 5', url: 'http://localhost/seen_movie5', imdb_id: 'tt0231264'}
               - {title: 'Seen movie title 6', url: 'http://localhost/seen_movie6', tmdb_id: 123}
+              - {title: 'Seen movie title 13', url: 'http://localhost/seen_movie13', imdb_id: 'tt9901062'}
             seen_movies: loose
 
           strict:
@@ -119,6 +120,14 @@ class TestFilterSeenMovies(object):
               - {title: 'Seen movie title 9', url: 'http://localhost/seen_movie9', tmdb_id: 456}
               - {title: 'Seen movie title 10', url: 'http://localhost/seen_movie10'}
             seen_movies: strict
+
+          local:
+            mock:
+              - {title: 'Seen movie title 11', url: 'http://localhost/seen_movie11', imdb_id: 'tt0103064', tmdb_id: 123}
+              - {title: 'Seen movie title 12', url: 'http://localhost/seen_movie12', imdb_id: 'tt9901062'}
+            accept_all: yes
+            seen_movies:
+              scope: local
     """
 
     def test_seen_movies(self, execute_task):
@@ -146,3 +155,13 @@ def test_seen_movies_strict(self, execute_task):
         task = execute_task('strict')
         assert len(task.rejected) == 1, 'Too many movies were rejected'
         assert not task.find_entry(title='Seen movie title 10'), 'strict should not have passed movie 10'
+
+    def test_seen_movies_local(self, execute_task):
+        task = execute_task('local')
+        assert task.find_entry('accepted', title='Seen movie title 11'), 'local should have passed movie 11'
+        # execute again
+        task.execute()
+        assert task.find_entry('rejected', title='Seen movie title 12'), 'Test movie entry 12 should be rejected in second execution'
+        # test a global scope after
+        task = execute_task('test_2')
+        assert not task.find_entry('rejected', title='Seen movie title 13'), 'Changing scope should not have rejected Seen movie title 13'