Ejemplo n.º 1
0
    def add(self):

        params = getParams()
        db = get_session();

        library = fireEvent('library.add', single = True, attrs = params)
        status = fireEvent('status.add', 'active', single = True)

        m = db.query(Movie).filter_by(library_id = library.id).first()
        if not m:
            m = Movie(
                library_id = library.id,
                profile_id = params.get('profile_id')
            )
            db.add(m)

        m.status_id = status.id
        db.commit()

        return jsonified({
            'success': True,
            'added': True,
            'movie': m.to_dict(deep = {
                'releases': {'status': {}, 'quality': {}},
                'library': {'titles': {}}
            })
        })
Ejemplo n.º 2
0
    def add(self):

        params = getParams()
        db = get_session()

        library = fireEvent('library.add', single=True, attrs=params)
        status = fireEvent('status.add', 'active', single=True)

        m = db.query(Movie).filter_by(library_id=library.id).first()
        if not m:
            m = Movie(library_id=library.id,
                      profile_id=params.get('profile_id'))
            db.add(m)

        m.status_id = status.id
        db.commit()

        return jsonified({
            'success':
            True,
            'added':
            True,
            'movie':
            m.to_dict(
                deep={
                    'releases': {
                        'status': {},
                        'quality': {}
                    },
                    'library': {
                        'titles': {}
                    }
                })
        })
Ejemplo n.º 3
0
    def add(self, params = {}, force_readd = True, search_after = True):

        library = fireEvent('library.add', single = True, attrs = params, update_after = False)

        # Status
        status_active = fireEvent('status.add', 'active', single = True)
        status_snatched = fireEvent('status.add', 'snatched', single = True)

        default_profile = fireEvent('profile.default', single = True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id = library.get('id')).first()
        do_search = False
        if not m:
            m = Movie(
                library_id = library.get('id'),
                profile_id = params.get('profile_id', default_profile.get('id')),
                status_id = status_active.get('id'),
            )
            db.add(m)
            fireEvent('library.update', params.get('identifier'), default_title = params.get('title', ''))
            do_search = True
        elif force_readd:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get('id'):
                    release.delete()

            m.profile_id = params.get('profile_id', default_profile.get('id'))
        else:
            log.debug('Movie already exists, not updating: %s' % params)

        if force_readd:
            m.status_id = status_active.get('id')

        db.commit()

        # Remove releases
        available_status = fireEvent('status.get', 'available', single = True)
        for rel in m.releases:
            if rel.status_id is available_status.get('id'):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if (force_readd or do_search) and search_after:
            fireEventAsync('searcher.single', movie_dict)

        db.close()
        return movie_dict
Ejemplo n.º 4
0
    def add(self, params={}, force_readd=True):

        library = fireEvent("library.add", single=True, attrs=params, update_after=False)

        # Status
        status_active = fireEvent("status.add", "active", single=True)
        status_snatched = fireEvent("status.add", "snatched", single=True)

        default_profile = fireEvent("profile.default", single=True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id=library.get("id")).first()
        do_search = False
        if not m:
            m = Movie(library_id=library.get("id"), profile_id=params.get("profile_id", default_profile.get("id")))
            db.add(m)
            fireEvent("library.update", params.get("identifier"), default_title=params.get("title", ""))
            do_search = True
        elif force_readd:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get("id"):
                    release.delete()

            m.profile_id = params.get("profile_id", default_profile.get("id"))
        else:
            log.debug("Movie already exists, not updating: %s" % params)

        if force_readd:
            m.status_id = status_active.get("id")

        db.commit()

        # Remove releases
        available_status = fireEvent("status.get", "available", single=True)
        for rel in m.releases:
            if rel.status_id is available_status.get("id"):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if force_readd or do_search:
            fireEventAsync("searcher.single", movie_dict)

        return movie_dict
Ejemplo n.º 5
0
    def add(self):

        params = getParams()
        db = get_session();

        library = fireEvent('library.add', single = True, attrs = params)

        # Status
        status_active = fireEvent('status.add', 'active', single = True)
        status_snatched = fireEvent('status.add', 'snatched', single = True)

        m = db.query(Movie).filter_by(library_id = library.get('id')).first()
        if not m:
            m = Movie(
                library_id = library.get('id'),
                profile_id = params.get('profile_id')
            )
            db.add(m)
        else:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get('id'):
                    release.delete()

            m.profile_id = params.get('profile_id')

        m.status_id = status_active.get('id')
        db.commit()

        movie_dict = m.to_dict(self.default_dict)

        fireEventAsync('searcher.single', movie_dict)

        return jsonified({
            'success': True,
            'added': True,
            'movie': movie_dict,
        })
Ejemplo n.º 6
0
    def add(self):

        params = getParams()
        db = get_session()

        library = fireEvent('library.add', single=True, attrs=params)

        # Status
        status_active = fireEvent('status.add', 'active', single=True)
        status_snatched = fireEvent('status.add', 'snatched', single=True)

        m = db.query(Movie).filter_by(library_id=library.get('id')).first()
        if not m:
            m = Movie(library_id=library.get('id'),
                      profile_id=params.get('profile_id'))
            db.add(m)
        else:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get('id'):
                    release.delete()

            m.profile_id = params.get('profile_id')

        m.status_id = status_active.get('id')
        db.commit()

        movie_dict = m.to_dict(self.default_dict)

        fireEventAsync('searcher.single', movie_dict)

        return jsonified({
            'success': True,
            'added': True,
            'movie': movie_dict,
        })
Ejemplo n.º 7
0
    def add(self, params = {}, force_readd = True, search_after = True, update_library = False, status_id = None):

        if not params.get('identifier'):
            msg = 'Can\'t add movie without imdb identifier.'
            log.error(msg)
            fireEvent('notify.frontend', type = 'movie.is_tvshow', message = msg)
            return False
        else:
            try:
                is_movie = fireEvent('movie.is_movie', identifier = params.get('identifier'), single = True)
                if not is_movie:
                    msg = 'Can\'t add movie, seems to be a TV show.'
                    log.error(msg)
                    fireEvent('notify.frontend', type = 'movie.is_tvshow', message = msg)
                    return False
            except:
                pass


        library = fireEvent('library.add', single = True, attrs = params, update_after = update_library)

        # Status
        status_active, snatched_status, ignored_status, done_status, downloaded_status = \
            fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True)

        default_profile = fireEvent('profile.default', single = True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id = library.get('id')).first()
        added = True
        do_search = False
        if not m:
            m = Movie(
                library_id = library.get('id'),
                profile_id = params.get('profile_id', default_profile.get('id')),
                status_id = status_id if status_id else status_active.get('id'),
            )
            db.add(m)
            db.commit()

            onComplete = None
            if search_after:
                onComplete = self.createOnComplete(m.id)

            fireEventAsync('library.update', params.get('identifier'), default_title = params.get('title', ''), on_complete = onComplete)
            search_after = False
        elif force_readd:

            # Clean snatched history
            for release in m.releases:
                if release.status_id in [downloaded_status.get('id'), snatched_status.get('id'), done_status.get('id')]:
                    if params.get('ignore_previous', False):
                        release.status_id = ignored_status.get('id')
                    else:
                        fireEvent('release.delete', release.id, single = True)

            m.profile_id = params.get('profile_id', default_profile.get('id'))
        else:
            log.debug('Movie already exists, not updating: %s', params)
            added = False

        if force_readd:
            m.status_id = status_id if status_id else status_active.get('id')
            m.last_edit = int(time.time())
            do_search = True

        db.commit()

        # Remove releases
        available_status = fireEvent('status.get', 'available', single = True)
        for rel in m.releases:
            if rel.status_id is available_status.get('id'):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if do_search and search_after:
            onComplete = self.createOnComplete(m.id)
            onComplete()

        if added:
            fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = 'Successfully added "%s" to your wanted list.' % params.get('title', ''))

        db.expire_all()
        return movie_dict
Ejemplo n.º 8
0
    def add(self,
            params={},
            force_readd=True,
            search_after=True,
            update_library=False,
            status_id=None):

        if not params.get('identifier'):
            msg = 'Can\'t add movie without imdb identifier.'
            log.error(msg)
            fireEvent('notify.frontend', type='movie.is_tvshow', message=msg)
            return False
        else:
            try:
                is_movie = fireEvent('movie.is_movie',
                                     identifier=params.get('identifier'),
                                     single=True)
                if not is_movie:
                    msg = 'Can\'t add movie, seems to be a TV show.'
                    log.error(msg)
                    fireEvent('notify.frontend',
                              type='movie.is_tvshow',
                              message=msg)
                    return False
            except:
                pass

        library = fireEvent('library.add',
                            single=True,
                            attrs=params,
                            update_after=update_library)

        # Status
        status_active, snatched_status, ignored_status, done_status, downloaded_status = \
            fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True)

        default_profile = fireEvent('profile.default', single=True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id=library.get('id')).first()
        added = True
        do_search = False
        if not m:
            m = Movie(
                library_id=library.get('id'),
                profile_id=params.get('profile_id', default_profile.get('id')),
                status_id=status_id if status_id else status_active.get('id'),
            )
            db.add(m)
            db.commit()

            onComplete = None
            if search_after:
                onComplete = self.createOnComplete(m.id)

            fireEventAsync('library.update',
                           params.get('identifier'),
                           default_title=params.get('title', ''),
                           on_complete=onComplete)
            search_after = False
        elif force_readd:

            # Clean snatched history
            for release in m.releases:
                if release.status_id in [
                        downloaded_status.get('id'),
                        snatched_status.get('id'),
                        done_status.get('id')
                ]:
                    if params.get('ignore_previous', False):
                        release.status_id = ignored_status.get('id')
                    else:
                        fireEvent('release.delete', release.id, single=True)

            m.profile_id = params.get('profile_id', default_profile.get('id'))
        else:
            log.debug('Movie already exists, not updating: %s', params)
            added = False

        if force_readd:
            m.status_id = status_id if status_id else status_active.get('id')
            m.last_edit = int(time.time())
            do_search = True

        db.commit()

        # Remove releases
        available_status = fireEvent('status.get', 'available', single=True)
        for rel in m.releases:
            if rel.status_id is available_status.get('id'):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if do_search and search_after:
            onComplete = self.createOnComplete(m.id)
            onComplete()

        if added:
            fireEvent('notify.frontend',
                      type='movie.added',
                      data=movie_dict,
                      message='Successfully added "%s" to your wanted list.' %
                      params.get('title', ''))

        db.expire_all()
        return movie_dict
Ejemplo n.º 9
0
    def add(self, params={}, force_readd=True, search_after=True):

        if not params.get('identifier'):
            log.error('Can\'t add movie without imdb identifier.')
            return False

        library = fireEvent(
            'library.add', single=True, attrs=params, update_after=False)

        # Status
        status_active = fireEvent('status.add', 'active', single=True)
        status_snatched = fireEvent('status.add', 'snatched', single=True)

        default_profile = fireEvent('profile.default', single=True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id=library.get('id')).first()
        added = True
        do_search = False
        if not m:
            m = Movie(
                library_id=library.get('id'),
                profile_id=params.get('profile_id', default_profile.get('id')),
                status_id=status_active.get('id'),
            )
            db.add(m)
            db.commit()

            onComplete = None
            if search_after:
                onComplete = self.createOnComplete(m.id)

            fireEventAsync(
                'library.update',
                params.get('identifier'),
                default_title=params.get('title', ''),
                on_complete=onComplete)
            search_after = False
        elif force_readd:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get('id'):
                    release.delete()

            m.profile_id = params.get('profile_id', default_profile.get('id'))
        else:
            log.debug('Movie already exists, not updating: %s', params)
            added = False

        if force_readd:
            m.status_id = status_active.get('id')
            do_search = True

        db.commit()

        # Remove releases
        available_status = fireEvent('status.get', 'available', single=True)
        for rel in m.releases:
            if rel.status_id is available_status.get('id'):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if do_search and search_after:
            onComplete = self.createOnComplete(m.id)
            onComplete()

        if added:
            fireEvent('notify.frontend', type='movie.added', data=movie_dict)

        #db.close()
        return movie_dict
Ejemplo n.º 10
0
    def add(self, params={}, force_readd=True, search_after=True):

        if not params.get("identifier"):
            msg = "Can't add movie without imdb identifier."
            log.error(msg)
            fireEvent("notify.frontend", type="movie.is_tvshow", message=msg)
            return False
        else:
            try:
                url = "http://thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=%s" % params.get("identifier")
                tvdb = self.getCache("thetvdb.%s" % params.get("identifier"), url=url, show_error=False)
                if tvdb and "series" in tvdb.lower():
                    msg = "Can't add movie, seems to be a TV show."
                    log.error(msg)
                    fireEvent("notify.frontend", type="movie.is_tvshow", message=msg)
                    return False
            except:
                pass

        library = fireEvent("library.add", single=True, attrs=params, update_after=False)

        # Status
        status_active = fireEvent("status.add", "active", single=True)
        status_snatched = fireEvent("status.add", "snatched", single=True)

        default_profile = fireEvent("profile.default", single=True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id=library.get("id")).first()
        added = True
        do_search = False
        if not m:
            m = Movie(
                library_id=library.get("id"),
                profile_id=params.get("profile_id", default_profile.get("id")),
                status_id=status_active.get("id"),
            )
            db.add(m)
            db.commit()

            onComplete = None
            if search_after:
                onComplete = self.createOnComplete(m.id)

            fireEventAsync(
                "library.update",
                params.get("identifier"),
                default_title=params.get("title", ""),
                on_complete=onComplete,
            )
            search_after = False
        elif force_readd:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get("id"):
                    release.delete()

            m.profile_id = params.get("profile_id", default_profile.get("id"))
        else:
            log.debug("Movie already exists, not updating: %s", params)
            added = False

        if force_readd:
            m.status_id = status_active.get("id")
            do_search = True

        db.commit()

        # Remove releases
        available_status = fireEvent("status.get", "available", single=True)
        for rel in m.releases:
            if rel.status_id is available_status.get("id"):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if do_search and search_after:
            onComplete = self.createOnComplete(m.id)
            onComplete()

        if added:
            fireEvent(
                "notify.frontend",
                type="movie.added",
                data=movie_dict,
                message='Successfully added "%s" to your wanted list.' % params.get("title", ""),
            )

        # db.close()
        return movie_dict
Ejemplo n.º 11
0
    def add(self, params = {}, force_readd = True, search_after = True):

        if not params.get('identifier'):
            log.error('Can\'t add movie without imdb identifier.')
            return False

        library = fireEvent('library.add', single = True, attrs = params, update_after = False)

        # Status
        status_active = fireEvent('status.add', 'active', single = True)
        status_snatched = fireEvent('status.add', 'snatched', single = True)

        default_profile = fireEvent('profile.default', single = True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id = library.get('id')).first()
        added = True
        do_search = False
        if not m:
            m = Movie(
                library_id = library.get('id'),
                profile_id = params.get('profile_id', default_profile.get('id')),
                status_id = status_active.get('id'),
            )
            db.add(m)
            db.commit()

            onComplete = None
            if search_after:
                onComplete = self.createOnComplete(m.id)

            fireEventAsync('library.update', params.get('identifier'), default_title = params.get('title', ''), on_complete = onComplete)
            search_after = False
        elif force_readd:
            # Clean snatched history
            for release in m.releases:
                if release.status_id == status_snatched.get('id'):
                    release.delete()

            m.profile_id = params.get('profile_id', default_profile.get('id'))
        else:
            log.debug('Movie already exists, not updating: %s', params)
            added = False

        if force_readd:
            m.status_id = status_active.get('id')
            do_search = True

        db.commit()

        # Remove releases
        available_status = fireEvent('status.get', 'available', single = True)
        for rel in m.releases:
            if rel.status_id is available_status.get('id'):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if do_search and search_after:
            onComplete = self.createOnComplete(m.id)
            onComplete()

        if added:
            fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = 'Successfully added "%s" to your wanted list.' % params.get('title', ''))

        #db.close()
        return movie_dict
Ejemplo n.º 12
0
    def add(self, params={}, force_readd=True, search_after=True, update_library=False, status_id=None):

        if not params.get("identifier"):
            msg = "Can't add movie without imdb identifier."
            log.error(msg)
            fireEvent("notify.frontend", type="movie.is_tvshow", message=msg)
            return False
        else:
            try:
                is_movie = fireEvent("movie.is_movie", identifier=params.get("identifier"), single=True)
                if not is_movie:
                    msg = "Can't add movie, seems to be a TV show."
                    log.error(msg)
                    fireEvent("notify.frontend", type="movie.is_tvshow", message=msg)
                    return False
            except:
                pass

        library = fireEvent("library.add", single=True, attrs=params, update_after=update_library)

        # Status
        status_active, snatched_status, ignored_status, done_status, downloaded_status = fireEvent(
            "status.get", ["active", "snatched", "ignored", "done", "downloaded"], single=True
        )

        default_profile = fireEvent("profile.default", single=True)

        db = get_session()
        m = db.query(Movie).filter_by(library_id=library.get("id")).first()
        added = True
        do_search = False
        if not m:
            m = Movie(
                library_id=library.get("id"),
                profile_id=params.get("profile_id", default_profile.get("id")),
                status_id=status_id if status_id else status_active.get("id"),
            )
            db.add(m)
            db.commit()

            onComplete = None
            if search_after:
                onComplete = self.createOnComplete(m.id)

            fireEventAsync(
                "library.update",
                params.get("identifier"),
                default_title=params.get("title", ""),
                on_complete=onComplete,
            )
            search_after = False
        elif force_readd:

            # Clean snatched history
            for release in m.releases:
                if release.status_id in [downloaded_status.get("id"), snatched_status.get("id"), done_status.get("id")]:
                    if params.get("ignore_previous", False):
                        release.status_id = ignored_status.get("id")
                    else:
                        fireEvent("release.delete", release.id, single=True)

            m.profile_id = params.get("profile_id", default_profile.get("id"))
        else:
            log.debug("Movie already exists, not updating: %s", params)
            added = False

        if force_readd:
            m.status_id = status_id if status_id else status_active.get("id")
            m.last_edit = int(time.time())
            do_search = True

        db.commit()

        # Remove releases
        available_status = fireEvent("status.get", "available", single=True)
        for rel in m.releases:
            if rel.status_id is available_status.get("id"):
                db.delete(rel)
                db.commit()

        movie_dict = m.to_dict(self.default_dict)

        if do_search and search_after:
            onComplete = self.createOnComplete(m.id)
            onComplete()

        if added:
            fireEvent(
                "notify.frontend",
                type="movie.added",
                data=movie_dict,
                message='Successfully added "%s" to your wanted list.' % params.get("title", ""),
            )

        # db.close()
        return movie_dict