示例#1
0
    def add(self, attrs={}, update_after=True):

        db = get_session()

        l = db.query(Library).filter_by(
            identifier=attrs.get('identifier')).first()
        if not l:
            status = fireEvent('status.get', 'needs_update', single=True)
            l = Library(year=attrs.get('year'),
                        identifier=attrs.get('identifier'),
                        plot=attrs.get('plot'),
                        tagline=attrs.get('tagline'),
                        status_id=status.get('id'))

            title = LibraryTitle(title=attrs.get('title'))

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after:
            fireEventAsync('library.update',
                           identifier=l.identifier,
                           default_title=attrs.get('title', ''))

        return l.to_dict(self.default_dict)
示例#2
0
    def add(self, attrs={}, update_after=True):

        db = get_session()

        l = db.query(Library).filter_by(identifier=attrs.get("identifier")).first()
        if not l:
            status = fireEvent("status.get", "needs_update", single=True)
            l = Library(
                year=attrs.get("year"),
                identifier=attrs.get("identifier"),
                plot=toUnicode(attrs.get("plot")),
                tagline=toUnicode(attrs.get("tagline")),
                status_id=status.get("id"),
            )

            title = LibraryTitle(
                title=toUnicode(attrs.get("title")), simple_title=self.simplifyTitle(attrs.get("title"))
            )

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after is not False:
            handle = fireEventAsync if update_after is "async" else fireEvent
            handle("library.update", identifier=l.identifier, default_title=attrs.get("title", ""))

        return l.to_dict(self.default_dict)
示例#3
0
    def add(self, attrs={}, update_after=True):

        db = get_session()

        l = db.query(Library).filter_by(
            identifier=attrs.get('identifier')).first()
        if not l:
            status = fireEvent('status.get', 'needs_update', single=True)
            l = Library(year=attrs.get('year'),
                        identifier=attrs.get('identifier'),
                        plot=toUnicode(attrs.get('plot')),
                        tagline=toUnicode(attrs.get('tagline')),
                        status_id=status.get('id'))

            title = LibraryTitle(title=toUnicode(attrs.get('title')),
                                 simple_title=self.simplifyTitle(
                                     attrs.get('title')))

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after is not False:
            handle = fireEventAsync if update_after is 'async' else fireEvent
            handle('library.update',
                   identifier=l.identifier,
                   default_title=toUnicode(attrs.get('title', '')))

        library_dict = l.to_dict(self.default_dict)

        return library_dict
示例#4
0
    def add(self, attrs = {}, update_after = True):

        db = get_session()

        l = db.query(Library).filter_by(identifier = attrs.get('identifier')).first()
        if not l:
            status = fireEvent('status.get', 'needs_update', single = True)
            l = Library(
                year = attrs.get('year'),
                identifier = attrs.get('identifier'),
                plot = attrs.get('plot'),
                tagline = attrs.get('tagline'),
                status_id = status.get('id')
            )

            title = LibraryTitle(
                title = attrs.get('title')
            )

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after:
            fireEventAsync('library.update', identifier = l.identifier, default_title = attrs.get('title', ''))

        return l.to_dict(self.default_dict)
示例#5
0
    def add(self, attrs = {}, update_after = True):

        db = get_session()

        l = db.query(Library).filter_by(identifier = attrs.get('identifier')).first()
        if not l:
            status = fireEvent('status.get', 'needs_update', single = True)
            l = Library(
                year = attrs.get('year'),
                identifier = attrs.get('identifier'),
                plot = toUnicode(attrs.get('plot')),
                tagline = toUnicode(attrs.get('tagline')),
                status_id = status.get('id')
            )

            title = LibraryTitle(
                title = toUnicode(attrs.get('title')),
                simple_title = self.simplifyTitle(attrs.get('title')),
            )

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after is not False:
            handle = fireEventAsync if update_after is 'async' else fireEvent
            handle('library.update', identifier = l.identifier, default_title = toUnicode(attrs.get('title', '')))

        library_dict = l.to_dict(self.default_dict)

        return library_dict
示例#6
0
文件: main.py 项目: Xice/CouchPotato
    def add(self, attrs={}):

        db = get_session()

        l = db.query(Library).filter_by(
            identifier=attrs.get('identifier')).first()
        if not l:
            l = Library(year=attrs.get('year'),
                        identifier=attrs.get('identifier'),
                        plot=attrs.get('plot'),
                        tagline=attrs.get('tagline'))

            title = LibraryTitle(title=attrs.get('title'))

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        fireEventAsync('library.update',
                       library=l,
                       default_title=attrs.get('title', ''))

        #db.remove()
        return l
示例#7
0
    def add(self, attrs=None, update_after=True):
        if not attrs: attrs = {}

        primary_provider = attrs.get('primary_provider', 'imdb')

        try:
            db = get_session()

            l = db.query(Library).filter_by(
                identifier=attrs.get('identifier')).first()
            if not l:
                status = fireEvent('status.get', 'needs_update', single=True)
                l = Library(year=attrs.get('year'),
                            identifier=attrs.get('identifier'),
                            plot=toUnicode(attrs.get('plot')),
                            tagline=toUnicode(attrs.get('tagline')),
                            status_id=status.get('id'),
                            info={})

                title = LibraryTitle(
                    title=toUnicode(attrs.get('title')),
                    simple_title=self.simplifyTitle(attrs.get('title')),
                )

                l.titles.append(title)

                db.add(l)
                db.commit()

            # Update library info
            if update_after is not False:
                handle = fireEventAsync if update_after is 'async' else fireEvent
                handle('library.update.movie',
                       identifier=l.identifier,
                       default_title=toUnicode(attrs.get('title', '')))

            library_dict = l.to_dict(self.default_dict)
            return library_dict
        except:
            log.error('Failed adding media: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return {}
示例#8
0
    def add(self, attrs = None, update_after = True):
        if not attrs: attrs = {}

        primary_provider = attrs.get('primary_provider', 'imdb')

        try:
            db = get_session()

            l = db.query(Library).filter_by(identifier = attrs.get('identifier')).first()
            if not l:
                status = fireEvent('status.get', 'needs_update', single = True)
                l = Library(
                    year = attrs.get('year'),
                    identifier = attrs.get('identifier'),
                    plot = toUnicode(attrs.get('plot')),
                    tagline = toUnicode(attrs.get('tagline')),
                    status_id = status.get('id'),
                    info = {}
                )

                title = LibraryTitle(
                    title = toUnicode(attrs.get('title')),
                    simple_title = self.simplifyTitle(attrs.get('title')),
                )

                l.titles.append(title)

                db.add(l)
                db.commit()

            # Update library info
            if update_after is not False:
                handle = fireEventAsync if update_after is 'async' else fireEvent
                handle('library.update.movie', identifier = l.identifier, default_title = toUnicode(attrs.get('title', '')))

            library_dict = l.to_dict(self.default_dict)
            return library_dict
        except:
            log.error('Failed adding media: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return {}
示例#9
0
    def add(self, attrs={}, update_after=True):
        # movies don't yet contain these, so lets make sure to set defaults
        type = attrs.get('type', 'movie')
        primary_provider = attrs.get('primary_provider', 'imdb')

        db = get_session()

        l = db.query(Library).filter_by(
            type=type, identifier=attrs.get('identifier')).first()
        if not l:
            status = fireEvent('status.get', 'needs_update', single=True)
            l = Library(type=type,
                        primary_provider=primary_provider,
                        year=attrs.get('year'),
                        identifier=attrs.get('identifier'),
                        plot=toUnicode(attrs.get('plot')),
                        tagline=toUnicode(attrs.get('tagline')),
                        status_id=status.get('id'),
                        info={},
                        parent=None)

            title = LibraryTitle(
                title=toUnicode(attrs.get('title')),
                simple_title=self.simplifyTitle(attrs.get('title')),
            )

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after is not False:
            handle = fireEventAsync if update_after is 'async' else fireEvent
            handle('library.update.movie',
                   identifier=l.identifier,
                   default_title=toUnicode(attrs.get('title', '')))

        library_dict = l.to_dict(self.default_dict)

        db.expire_all()
        return library_dict
示例#10
0
    def add(self, attrs={}, update_after=True):
        # movies don't yet contain these, so lets make sure to set defaults
        type = attrs.get("type", "movie")
        primary_provider = attrs.get("primary_provider", "imdb")

        db = get_session()

        l = db.query(Library).filter_by(type=type, identifier=attrs.get("identifier")).first()
        if not l:
            status = fireEvent("status.get", "needs_update", single=True)
            l = Library(
                type=type,
                primary_provider=primary_provider,
                year=attrs.get("year"),
                identifier=attrs.get("identifier"),
                plot=toUnicode(attrs.get("plot")),
                tagline=toUnicode(attrs.get("tagline")),
                status_id=status.get("id"),
                info={},
                parent=None,
            )

            title = LibraryTitle(
                title=toUnicode(attrs.get("title")), simple_title=self.simplifyTitle(attrs.get("title"))
            )

            l.titles.append(title)

            db.add(l)
            db.commit()

        # Update library info
        if update_after is not False:
            handle = fireEventAsync if update_after is "async" else fireEvent
            handle("library.update.movie", identifier=l.identifier, default_title=toUnicode(attrs.get("title", "")))

        library_dict = l.to_dict(self.default_dict)

        db.expire_all()
        return library_dict