コード例 #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': {}
                    }
                })
        })
コード例 #2
0
ファイル: main.py プロジェクト: Xice/CouchPotato
    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': {}}
            })
        })
コード例 #3
0
ファイル: main.py プロジェクト: SpLord/CouchPotatoServer
    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
コード例 #4
0
ファイル: main.py プロジェクト: gthicks/CouchPotatoServer
    def add(self, group):

        db = get_session()

        identifier = '%s.%s.%s' % (group['library']['identifier'],
                                   group['meta_data'].get('audio', 'unknown'),
                                   group['meta_data']['quality']['identifier'])

        done_status, snatched_status = fireEvent('status.get',
                                                 ['done', 'snatched'],
                                                 single=True)

        # Add movie
        movie = db.query(Movie).filter_by(
            library_id=group['library'].get('id')).first()
        if not movie:
            movie = Movie(library_id=group['library'].get('id'),
                          profile_id=0,
                          status_id=done_status.get('id'))
            db.add(movie)
            db.commit()

        # Add Release
        rel = db.query(Relea).filter(
            or_(
                Relea.identifier == identifier,
                and_(
                    Relea.identifier.startswith(
                        group['library']['identifier']),
                    Relea.status_id == snatched_status.get('id')))).first()
        if not rel:
            rel = Relea(identifier=identifier,
                        movie=movie,
                        quality_id=group['meta_data']['quality'].get('id'),
                        status_id=done_status.get('id'))
            db.add(rel)
            db.commit()

        # Add each file type
        added_files = []
        for type in group['files']:
            for cur_file in group['files'][type]:
                added_file = self.saveFile(cur_file,
                                           type=type,
                                           include_media_info=type is 'movie')
                added_files.append(added_file.get('id'))

        # Add the release files in batch
        try:
            added_files = db.query(File).filter(
                or_(*[File.id == x for x in added_files])).all()
            rel.files.extend(added_files)
            db.commit()
        except:
            log.debug('Failed to attach "%s" to release: %s',
                      (added_files, traceback.format_exc()))

        fireEvent('movie.restatus', movie.id)

        return True
コード例 #5
0
ファイル: main.py プロジェクト: blackjid/CouchPotatoServer
    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
コード例 #6
0
ファイル: main.py プロジェクト: Selissi/CouchPotatoServer
    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,
        })
コード例 #7
0
ファイル: main.py プロジェクト: babbel4ever/PBI
    def add(self, group):
        db = get_session()

        identifier = '%s.%s.%s' % (group['library']['identifier'],
                                   group['meta_data'].get('audio', 'unknown'),
                                   group['meta_data']['quality']['identifier'])

        # Add movie
        done_status = fireEvent('status.get', 'done', single=True)
        movie = db.query(Movie).filter_by(
            library_id=group['library'].get('id')).first()
        if not movie:
            movie = Movie(library_id=group['library'].get('id'),
                          profile_id=0,
                          status_id=done_status.get('id'))
            db.add(movie)
            db.commit()

        # Add Release
        snatched_status = fireEvent('status.get', 'snatched', single=True)
        rel = db.query(Relea).filter(
            or_(
                Relea.identifier == identifier,
                and_(
                    Relea.identifier.startswith(
                        group['library']['identifier']),
                    Relea.status_id == snatched_status.get('id')))).first()
        if not rel:
            rel = Relea(identifier=identifier,
                        movie=movie,
                        quality_id=group['meta_data']['quality'].get('id'),
                        status_id=done_status.get('id'))
            db.add(rel)
            db.commit()

        # Add each file type
        for type in group['files']:
            for cur_file in group['files'][type]:
                added_file = self.saveFile(cur_file,
                                           type=type,
                                           include_media_info=type is 'movie')
                try:
                    added_file = db.query(File).filter_by(
                        id=added_file.get('id')).one()
                    rel.files.append(added_file)
                    db.commit()
                except Exception, e:
                    log.debug('Failed to attach "%s" to release: %s',
                              (cur_file, e))
コード例 #8
0
ファイル: main.py プロジェクト: Selissi/CouchPotatoServer
    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,
        })
コード例 #9
0
ファイル: main.py プロジェクト: Bernt87/CouchPotatoServer
    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
コード例 #10
0
ファイル: main.py プロジェクト: ragnvaldur/CouchPotatoServer
    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
コード例 #11
0
ファイル: main.py プロジェクト: solo2424/CouchPotatoServer
    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
コード例 #12
0
ファイル: main.py プロジェクト: kevmeon/CouchPotatoServer
    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
コード例 #13
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
コード例 #14
0
ファイル: main.py プロジェクト: kanters/CouchPotatoServer
    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