Ejemplo n.º 1
0
    def check_plex_condition(entity):
        try:
            if ModelSetting.get_int('plex_condition') == 0:
                return False

            rx_keyword = r'(?P<keyword>.*?)\s*?(\(|\[).*'
            rx_year = r'\((?P<year>\d{4})\)'
            title = entity.title2 if entity.title2 != '' else entity.title
            return False

            # TODO:
            """
            from plex import LogicNormal as PlexLogic
            return True
            """
        except Exception as e:
            logger.error('Exception %s', e)
            logger.error(traceback.format_exc())
            return '-'
Ejemplo n.º 2
0
    def scheduled_copy(sheet_id):
        try:
            wsentity = WSModelItem.get(sheet_id)
            wsentity.is_running = True
            wsentity.save()

            # COPY items
            succeed = 0
            failed = 0

            copy_mode = ModelSetting.get_int('copy_mode')
            if copy_mode == 0: return

            # keyword rule 적용: 미사용-너무느림
            #rules = ModelSetting.get_list('keyword_rules', '|') if copy_mode == 1 else ModelSetting.get_list('except_keyword_rules', '|')

            # TODO:Plex 연동저건에 따른 처리: 0 연동안함, 1: 있으면 skip, 2: 용량크면복사
            #plex_condition = ModelSetting.get_int('plex_condition')

            for entity in ListModelItem.get_schedule_target_items(sheet_id):
                # keyword rule 적용: 파일타입의 경우만
                if entity.mimetype == 1:
                    rules = ModelSetting.get_list(
                        'keyword_rules',
                        '|') if copy_mode == 1 else ModelSetting.get_list(
                            'except_keyword_rules', '|')
                    copy_flag = True
                    for rule in rules:
                        copy_flag = False if copy_mode == 1 else True
                        if entity.title.find(rule) != -1:
                            copy_flag = not copy_flag
                            logger.debug(
                                'keyword(%s) is matched, copy_flag(%s)', rule,
                                copy_flag)
                            break
                    if not copy_flag: continue
                    if entity.copy_count > 1: continue

                # keyword rule 적용: 미사용-너무느림
                """ 
                from gd_share_client.model import ModelSetting as gscModelSetting
                remote_path = 'gc:{%s}' % entity.folder_id
                ret = RcloneTool.lsjson(gscModelSetting.get('rclone_path'), gscModelSetting.get('rclone_config_path'), remote_path)
                if len(ret) == 0: continue

                for f in ret:
                    mtype = f['MimeType']
                    if not mtype.startswith('video/'):
                        continue

                    fname = f['Name']
                    # copy_mode: 1-whitelist, 2-blacklist
                    for rule in rules:
                        copy_flag = False if copy_mode == 1 else True
                        if fname.find(rule) != -1:
                            copy_flag = not copy_flag
                            logger.debug('keyword(%s) is matched, copy_flag(%s)', rule, copy_flag)
                            break

                if not copy_flag: continue
                """
                # TODO: Plex 연동 조건에 따른 복사 처리: 20.09.10
                #if not LogicGSeet.check_plex_condition(entity):
                #continue

                logger.info(
                    'copy target: %s, %s, %s, %s',
                    entity.title2 if entity.title2 != u"" else entity.title,
                    entity.folder_id, entity.category, entity.str_size)
                ret = LogicGSheet.gclone_copy(entity.id)

                logger.info(ret['data'])
                if ret['ret']: succeed += 1
                else: failed += 1

            total = succeed + failed
            logger.info('scheduled_copy: total(%d), succeed(%d), failed(%d)',
                        total, succeed, failed)
            ret = {
                'ret':
                True,
                'data':
                'copy result: total({total}), succeed({succeed}), failed({failed})'
                .format(total=total, succeed=succeed, failed=failed)
            }
        except Exception as e:
            logger.error('Exception %s', e)
            logger.error(traceback.format_exc())
            ret = {'ret': False, 'data': 'Exception'}
        finally:
            wsentity.is_running = False
            wsentity.save()
            return ret