'Add downloaded movies to the database'

def on_task_learn(self, task, config):

    log.debug(u'check    for    learning')
    for entry in task.accepted:
        if (u'imdb_id' not in entry):
            log.debug((u'`%s`    does    not    have    imdb_id' % entry[u'title']))
            continue
        parser = get_plugin_by_name(u'parsing').instance.parse_movie(entry[u'title'])
        quality = parser.quality.name
        log.debug((u'quality:    %s' % quality))
        log.debug((u'imdb_id:    %s' % entry[u'imdb_id']))
        log.debug((u'proper    count:    %s' % parser.proper_count))
        proper_movie = task.session.query(ProperMovie).filter((ProperMovie.imdb_id == entry[u'imdb_id'])).filter((ProperMovie.quality == quality)).filter((ProperMovie.proper_count == parser.proper_count)).first()
        if (not proper_movie):
            pm = ProperMovie()
            pm.title = entry[u'title']
            pm.task = task.name
            pm.imdb_id = entry[u'imdb_id']
            pm.quality = quality
            pm.proper_count = parser.proper_count
            task.session.add(pm)
            log.debug((u'added    %s' % pm))
        else:
            log.debug((u'%s    already    exists' % proper_movie))
