Пример #1
0
    def save(self):

        params = getParams()

        db = get_session()

        p = db.query(Profile).filter_by(id=params.get("id")).first()
        if not p:
            p = Profile()
            db.add(p)

        p.label = params.get("label")
        p.order = params.get("order", p.order if p.order else 0)
        p.core = params.get("core", False)

        # delete old types
        [db.delete(t) for t in p.types]

        order = 0
        for type in params.get("types", []):
            t = ProfileType(
                order=order,
                finish=type.get("finish"),
                wait_for=params.get("wait_for"),
                quality_id=type.get("quality_id"),
            )
            p.types.append(t)

            order += 1

        db.commit()

        return jsonified({"success": True, "profile": p.to_dict(deep={"types": {}})})
Пример #2
0
    def save(self, **kwargs):

        db = get_session()

        p = db.query(Profile).filter_by(id=kwargs.get("id")).first()
        if not p:
            p = Profile()
            db.add(p)

        p.label = toUnicode(kwargs.get("label"))
        p.order = kwargs.get("order", p.order if p.order else 0)
        p.core = kwargs.get("core", False)

        # delete old types
        [db.delete(t) for t in p.types]

        order = 0
        for type in kwargs.get("types", []):
            t = ProfileType(
                order=order,
                finish=type.get("finish") if order > 0 else 1,
                wait_for=kwargs.get("wait_for"),
                quality_id=type.get("quality_id"),
            )
            p.types.append(t)

            order += 1

        db.commit()

        profile_dict = p.to_dict(self.to_dict)

        return {"success": True, "profile": profile_dict}
Пример #3
0
    def save(self, **kwargs):

        try:
            db = get_session()

            p = db.query(Profile).filter_by(id = kwargs.get('id')).first()
            if not p:
                p = Profile()
                db.add(p)

            p.label = toUnicode(kwargs.get('label'))
            p.order = kwargs.get('order', p.order if p.order else 0)
            p.core = kwargs.get('core', False)

            #delete old types
            [db.delete(t) for t in p.types]

            order = 0
            for type in kwargs.get('types', []):
                t = ProfileType(
                    order = order,
                    finish = type.get('finish') if order > 0 else 1,
                    wait_for = kwargs.get('wait_for'),
                    quality_id = type.get('quality_id')
                )
                p.types.append(t)

                order += 1

            db.commit()

            profile_dict = p.to_dict(self.to_dict)

            return {
                'success': True,
                'profile': profile_dict
            }
        except:
            log.error('Failed: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return {
            'success': False
        }
Пример #4
0
    def fill(self):

        try:
            db = get_session()

            order = 0
            for q in self.qualities:

                # Create quality
                qual = db.query(Quality).filter_by(
                    identifier=q.get('identifier')).first()

                if not qual:
                    log.info('Creating quality: %s', q.get('label'))
                    qual = Quality()
                    qual.order = order
                    qual.identifier = q.get('identifier')
                    qual.label = toUnicode(q.get('label'))
                    qual.size_min, qual.size_max = q.get('size')

                    db.add(qual)

                # Create single quality profile
                prof = db.query(Profile).filter(Profile.core == True).filter(
                    Profile.types.any(quality=qual)).all()

                if not prof:
                    log.info('Creating profile: %s', q.get('label'))
                    prof = Profile(core=True,
                                   label=toUnicode(qual.label),
                                   order=order)
                    db.add(prof)

                    profile_type = ProfileType(quality=qual,
                                               profile=prof,
                                               finish=True,
                                               order=0)
                    prof.types.append(profile_type)

                order += 1

            db.commit()

            time.sleep(0.3)  # Wait a moment

            return True
        except:
            log.error('Failed: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return False
Пример #5
0
    def save(self, **kwargs):

        db = get_session()

        p = db.query(Profile).filter_by(id=kwargs.get('id')).first()
        if not p:
            p = Profile()
            db.add(p)

        p.label = toUnicode(kwargs.get('label'))
        p.order = kwargs.get('order', p.order if p.order else 0)
        p.core = kwargs.get('core', False)

        #delete old types
        [db.delete(t) for t in p.types]

        order = 0
        for type in kwargs.get('types', []):
            t = ProfileType(order=order,
                            finish=type.get('finish') if order > 0 else 1,
                            wait_for=kwargs.get('wait_for'),
                            quality_id=type.get('quality_id'))
            p.types.append(t)

            order += 1

        db.commit()

        profile_dict = p.to_dict(self.to_dict)

        return {'success': True, 'profile': profile_dict}
Пример #6
0
    def save(self):

        params = getParams()

        db = get_session()

        p = db.query(Profile).filter_by(id = params.get('id')).first()
        if not p:
            p = Profile()
            db.add(p)

        p.label = toUnicode(params.get('label'))
        p.order = params.get('order', p.order if p.order else 0)
        p.core = params.get('core', False)

        #delete old types
        [db.delete(t) for t in p.types]

        order = 0
        for type in params.get('types', []):
            t = ProfileType(
                order = order,
                finish = type.get('finish') if order > 0 else 1,
                wait_for = params.get('wait_for'),
                quality_id = type.get('quality_id')
            )
            p.types.append(t)

            order += 1

        db.commit()

        profile_dict = p.to_dict(self.to_dict)

        #db.close()
        return jsonified({
            'success': True,
            'profile': profile_dict
        })
Пример #7
0
    def fill(self):

        try:
            db = get_session()

            profiles = [{
                'label': 'Best',
                'qualities': ['720p', '1080p', 'brrip', 'dvdrip']
            }, {
                'label': 'HD',
                'qualities': ['720p', '1080p']
            }, {
                'label': 'SD',
                'qualities': ['dvdrip', 'dvdr']
            }]

            # Create default quality profile
            order = -2
            for profile in profiles:
                log.info('Creating default profile: %s', profile.get('label'))
                p = Profile(label=toUnicode(profile.get('label')), order=order)
                db.add(p)

                quality_order = 0
                for quality in profile.get('qualities'):
                    quality = fireEvent('quality.single',
                                        identifier=quality,
                                        single=True)
                    profile_type = ProfileType(quality_id=quality.get('id'),
                                               profile=p,
                                               finish=True,
                                               wait_for=0,
                                               order=quality_order)
                    p.types.append(profile_type)

                    quality_order += 1

                order += 1

            db.commit()

            return True
        except:
            log.error('Failed: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return False
Пример #8
0
    def fill(self):

        db = get_session();

        order = 0
        for q in self.qualities:

            # Create quality
            quality = db.query(Quality).filter_by(identifier = q.get('identifier')).first()

            if not quality:
                log.info('Creating quality: %s' % q.get('label'))
                quality = Quality()
                db.add(quality)

            quality.order = order
            quality.identifier = q.get('identifier')
            quality.label = q.get('label')
            quality.size_min, quality.size_max = q.get('size')

            # Create single quality profile
            profile = db.query(Profile).filter(
                    Profile.core == True
                ).filter(
                    Profile.types.any(quality = quality)
                ).all()

            if not profile:
                log.info('Creating profile: %s' % q.get('label'))
                profile = Profile(
                    core = True,
                    label = toUnicode(quality.label),
                    order = order
                )
                db.add(profile)

                profile_type = ProfileType(
                    quality = quality,
                    profile = profile,
                    finish = True,
                    order = 0
                )
                profile.types.append(profile_type)

            order += 1
            db.commit()

        return True
Пример #9
0
    def fill(self):

        db = get_session();

        profiles = [{
            'label': 'Best',
            'qualities': ['720p', '1080p', 'brrip', 'dvdrip']
        }, {
            'label': 'HD',
            'qualities': ['720p', '1080p']
        }]

        # Create default quality profile
        order = -2
        for profile in profiles:
            log.info('Creating default profile: %s' % profile.get('label'))
            p = Profile(
                label = toUnicode(profile.get('label')),
                order = order
            )
            db.add(p)

            quality_order = 0
            for quality in profile.get('qualities'):
                quality = fireEvent('quality.single', identifier = quality, single = True)
                profile_type = ProfileType(
                    quality_id = quality.get('id'),
                    profile = p,
                    finish = True,
                    wait_for = 0,
                    order = quality_order
                )
                p.types.append(profile_type)

                db.commit()
                quality_order += 1

            order += 1

        return True
Пример #10
0
    def save(self):

        params = getParams()

        db = get_session()

        p = db.query(Profile).filter_by(id = params.get('id')).first()
        if not p:
            p = Profile()
            db.add(p)

        p.label = params.get('label')
        p.order = params.get('order', p.order if p.order else 0)
        p.core = params.get('core', False)

        #delete old types
        [db.delete(t) for t in p.types]

        order = 0
        for type in params.get('types', []):
            t = ProfileType(
                order = order,
                finish = type.get('finish') if order > 0 else 1,
                wait_for = params.get('wait_for'),
                quality_id = type.get('quality_id')
            )
            p.types.append(t)

            order += 1

        db.commit()

        profile_dict = p.to_dict(deep = {'types': {}})

        return jsonified({
            'success': True,
            'profile': profile_dict
        })