3
from flexget.plugin import register_plugin, priority, PluginError, get_plugin_by_name
4
from flexget.utils.imdb import extract_id
5
from flexget.utils.titles.movie import MovieParser
7
log = logging.getLogger('exists_movie')
10
class FilterExistsMovie(object):
13
Reject existing movies.
17
exists_movie: /storage/movies/
20
skip = ['cd1', 'cd2', 'subs', 'sample']
26
from flexget import validator
27
root = validator.factory()
29
bundle = root.accept('list')
33
def build_config(self, config):
34
# if only a single path is passed turn it into a 1 element list
35
if isinstance(config, basestring):
39
def on_process_start(self, feed, config):
43
def on_feed_filter(self, feed, config):
45
log.debug('nothing accepted, aborting')
48
config = self.build_config(config)
49
imdb_lookup = get_plugin_by_name('imdb_lookup').instance
52
incompatible_entries = 0
56
# list of imdb ids gathered from paths / cache
60
# see if this path has already been scanned
61
if path in self.cache:
62
log.verbose('Using cached scan for %s ...' % path)
63
imdb_ids.extend(self.cache[path])
68
# with unicode it crashes on some paths ..
69
path = str(os.path.expanduser(path))
70
if not os.path.exists(path):
71
log.critical('Path %s does not exist' % path)
74
log.verbose('Scanning path %s ...' % path)
76
# Help debugging by removing a lot of noise
77
#logging.getLogger('movieparser').setLevel(logging.WARNING)
78
#logging.getLogger('imdb_lookup').setLevel(logging.WARNING)
81
for root, dirs, files in os.walk(path):
82
# convert filelists into utf-8 to avoid unicode problems
83
dirs = [x.decode('utf-8', 'ignore') for x in dirs]
84
# files = [x.decode('utf-8', 'ignore') for x in files]
86
# TODO: add also video files?
88
if item.lower() in self.skip:
96
imdb_id = imdb_lookup.imdb_id_lookup(movie_title=movie.name,
99
if imdb_id in path_ids:
100
log.trace('duplicate %s' % item)
102
if imdb_id is not None:
103
log.trace('adding: %s' % imdb_id)
104
path_ids.append(imdb_id)
105
except PluginError, e:
106
log.trace('%s lookup failed (%s)' % (item, e.value))
107
incompatible_dirs += 1
109
# store to cache and extend to found list
110
self.cache[path] = path_ids
111
imdb_ids.extend(path_ids)
113
log.debug('-- Start filtering entries ----------------------------------')
115
# do actual filtering
116
for entry in feed.accepted:
118
if not entry.get('imdb_id', eval_lazy=False):
120
imdb_lookup.lookup(entry)
121
except PluginError, e:
122
log.trace('entry %s imdb failed (%s)' % (entry['title'], e.value))
123
incompatible_entries += 1
127
if entry['imdb_id'] in imdb_ids:
128
feed.reject(entry, 'movie exists')
130
if incompatible_dirs or incompatible_entries:
131
log.verbose('There were some incompatible items. %s of %s entries '
132
'and %s of %s directories could not be verified.' %
133
(incompatible_entries, count_entries, incompatible_dirs, count_dirs))
135
log.debug('-- Finished filtering entries -------------------------------')
137
register_plugin(FilterExistsMovie, 'exists_movie', groups=['exists'], api_ver=2)