Пример #1
0
 def nginx_command(self, command, conf):
     conf = conf.replace("\r\n", "\n").replace("\r", "\n")
     write_file(conf, conf_filepath)
     if command == 'test':
         data = SystemLogicCommand.execute_command_return(['nginx', '-t'])
     elif command == 'reload':
         data = SystemLogicCommand.execute_command_return(
             ['nginx', '-s', 'reload'])
     return data.split('\n')
Пример #2
0
 def rclone_version():
     try:
         command = [u'%s' % Logic.path_rclone,  'version', '--config', Logic.path_config]
         ret = SystemLogicCommand.execute_command_return(command)
         return ret
     except Exception as exception: 
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Пример #3
0
 def process_ajax(sub, req):
     try:
         if sub == 'sa_create_new_only':
             python_file = os.path.join(os.path.dirname(__file__),
                                        'gen_sa_accounts.py')
             from system.logic_command import SystemLogicCommand
             return_log = SystemLogicCommand.start('AutoRclone', [
                 ['msg', '잠시만 기다리세요'],
                 [
                     'python', python_file, '--quick-setup', '1',
                     '--new-only', '--path',
                     ModelSetting.get('path_accounts'), '--credentials',
                     ModelSetting.get('path_credentials'), '--token',
                     ModelSetting.get('path_token')
                 ],
                 ['msg', '완료'],
             ])
             return jsonify('')
         elif sub == 'auth_step1':
             from .gen_sa_accounts import auth_step1
             url, _ = auth_step1(
                 credentials=ModelSetting.get('path_credentials'),
                 token=ModelSetting.get('path_token'))
             return jsonify(url)
         elif sub == 'auth_step2':
             from .gen_sa_accounts import auth_step2
             code = req.form['code']
             auth_step2(code, token=ModelSetting.get('path_token'))
             return jsonify(os.path.exists(ModelSetting.get('path_token')))
         elif sub == 'split_json':
             import glob
             accounts_dir = ModelSetting.get('path_accounts')
             sa_files = glob.glob(os.path.join(accounts_dir, '*.json'))
             count = 0
             for i, filename in enumerate(sa_files):
                 json_path = os.path.join(accounts_dir, filename)
                 data = json.loads(open(json_path, 'r').read())
                 target_dir = os.path.join(accounts_dir, data['project_id'])
                 if not os.path.exists(target_dir):
                     os.makedirs(target_dir)
                 shutil.move(json_path, target_dir)
                 count += 1
             return jsonify(count)
         elif sub == 'gen_email':
             import glob
             accounts_dir = ModelSetting.get('path_accounts')
             sa_files = glob.glob(os.path.join(accounts_dir, '*.json'))
             email_list = []
             for filename in sa_files:
                 json_path = os.path.join(accounts_dir, filename)
                 data = json.loads(open(json_path, 'r').read())
                 email_list.append(data['client_email'])
             return jsonify(email_list)
     except Exception as e:
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
Пример #4
0
def get_video_info(filepath):
    try:
        from system.logic_command import SystemLogicCommand
        command = [
            'ffprobe', '-v', 'error', '-print_format', 'json', '-show_format',
            '-show_streams',
            "%s" % filepath
        ]
        ret = SystemLogicCommand.execute_command_return(command, format='json')
        return ret
    except Exception as exception:
        logger.error('Exception:%s', exception)
        logger.error(traceback.format_exc())
Пример #5
0
 def mkdir(rclone_path, config_path, remote_path, option=None):
     try:
         from system.logic_command import SystemLogicCommand
         command = [
             rclone_path, '--config', config_path, 'mkdir', remote_path
         ]
         if option is not None:
             command += option
         logger.debug('MKDIR:%s', ' '.join(command))
         ret = SystemLogicCommand.execute_command_return(command)
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Пример #6
0
 def size(rclone_path, config_path, remote_path, option=None):
     try:
         from system.logic_command import SystemLogicCommand
         command = [
             rclone_path, '--config', config_path, 'size', remote_path,
             '--json'
         ]
         if option is not None:
             command += option
         ret = SystemLogicCommand.execute_command_return(command,
                                                         format='json')
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Пример #7
0
 def purge(rclone_path, config_path, remote_path, option=None):
     try:
         from system.logic_command import SystemLogicCommand
         command = [
             rclone_path, '--config', config_path, 'purge', remote_path,
             '--drive-use-trash=false', '-vv'
         ]
         if option is not None:
             command += option
         logger.debug('PURGE:%s', ' '.join(command))
         ret = SystemLogicCommand.execute_command_return(command,
                                                         force_log=True)
         logger.debug(ret)
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Пример #8
0
 def lsjson(rclone_path, config_path, remote_path, option=None):
     try:
         from system.logic_command import SystemLogicCommand
         command = [
             rclone_path, '--config', config_path, 'lsjson', remote_path
         ]
         if option is not None:
             command += option
         #logger.debug('LSJSON:%s', ' '.join(command))
         ret = SystemLogicCommand.execute_command_return(command,
                                                         format='json')
         if ret is not None:
             ret = list(sorted(ret, key=lambda k: k['Path']))
         return ret
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
Пример #9
0
    def getid(rclone_path, config_path, remote_path, option=None):
        try:
            from system.logic_command import SystemLogicCommand
            command = [
                rclone_path, '--config', config_path, 'backend', 'getid',
                remote_path
            ]
            if option is not None:
                command += option

            ret = SystemLogicCommand.execute_command_return(command).strip()
            logger.debug('GETID : %s\n%s', ' '.join(command), ret)
            if ret is not None and (len(ret.split(' ')) > 1 or ret == ''):
                ret = None
            return ret
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
Пример #10
0
 def process_menu(self, sub, req):
     arg = {'package_name': P.package_name, 'sub': self.name}
     if sub == 'setting':
         arg['status_isntall'] = SystemLogicCommand.execute_command_return(
             ['which', 'nginx'])
         if arg['status_isntall'] == '':
             arg['is_installed'] = False
             arg['status_isntall'] = 'nginx가 설치되어 있지 않습니다.'
             arg['status_running'] = '먼저 설치하세요'
         else:
             arg['is_installed'] = True
         if os.path.exists(conf_filepath):
             arg['conf'] = read_file(conf_filepath)
         return render_template('{package_name}_{sub}.html'.format(
             package_name=P.package_name, module_name=self.name, sub=sub),
                                arg=arg)
     return render_template('sample.html',
                            title='%s - %s' % (P.package_name, sub))
Пример #11
0
    def task():
        try:
            logger.debug('[tv_schedule] start tv scheduler')
            service = None
            service = LibGdrive.sa_authorize(ModelSetting.get('gdrive_auth_path'), return_service=True)
            if service == None:
                data = {'type':'warning', 'msg':u'서비스계정 인증에 실패하여 스케쥴러를 실행할 수 없습니다.'}
                socketio.emit("notify", data, namespace='/framework', broadcate=True)
                logger.error('[tv_schdule]: failed to authorize sa accounts(%s)', ModelSetting.get('gdrive_auth_path'))

            entities = ModelTvMvItem.get_onair_entities_with_shortcut()
            count = len(entities)
            logger.debug('[tv_schedule] target onair item: %d', count)

            for entity in entities:
                children = LibGdrive.get_children(entity.folder_id, time_after=entity.updated_time, service=service)
                if children == None:
                    logger.error('failed to get children files: skip!')
                    continue

                logger.debug(u'[tv_schedule] title:{}, 에피소드 추가 내역: {}'.format(entity.title, u'없음' if len(children) == 0 else '{} 건'.format(len(children))))
                if len(children) > 0:
                    logger.debug('[tv_schedule] new episode found, send_scan(%s)', entity.title)
                    fpath = os.path.join(entity.plex_path, children[0]['name'])
                    LogicBase.PlexScannerQueue.put({'id':entity.id, 'agent_type':entity.agent_type, 'path':fpath, 'action':'REFRESH', 'now':datetime.now()})

                    if os.path.isfile(ModelSetting.get('rclone_bin_path')):
                        from system.logic_command import SystemLogicCommand
                        # /usr/bin/rclone rc vfs/refresh recursive=true --rc-addr 127.0.0.1:5572 _async=true
                        rc_path = ScmUtil.get_rc_path(entity.plex_path)
                        command = [ModelSetting.get('rclone_bin_path'), 'rc', 'vfs/refresh', '--rc-addr', ModelSetting.get('rclone_rc_addr'), 'dir='+rc_path, '_async=true']
                        logger.debug('[tv_schedule] rc vfs/refresh: %s', rc_path)
                        data = SystemLogicCommand.execute_command_return(command)
                        if data.find('jobid') == -1:
                            data = {'type':'warning', 'msg':u'마운트 경로 갱신이 실패하였습니다.(mount rc확인필요)'}
                            socketio.emit("notify", data, namespace='/framework', broadcate=True)
                            logger.error('[tv_schdule]: failed to vfs/refresh(%s/%s)', ModelSetting.get('rclone_bin_path'), ModelSetting.get('rclone_rc_addr'))

            logger.debug('[tv_schedule] end tv scheduler')

        except Exception as e:
            logger.debug('Exception:%s', e)
            logger.debug(traceback.format_exc())
Пример #12
0
 def do_relay_completed(rclone_path, config_path, source_remote_path,
                        original_remote_path):
     try:
         command = [
             rclone_path, '--config', config_path, 'move',
             source_remote_path, original_remote_path,
             '--drive-server-side-across-configs=true', '-v',
             '--delete-empty-src-dirs', '--drive-use-trash=false'
         ]
         return_log = SystemLogicCommand.execute_command_return(command)
         if (return_log.find('Transferred') != -1
                 and return_log.find('100%') != -1) or (
                     return_log.find('Checks:') != -1
                     and return_log.find('100%') != -1):
             RcloneTool2.purge(rclone_path, config_path, source_remote_path)
             return True
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
     return False
Пример #13
0
    def get_size(id):
        try:
            entity = ListModelItem.get(id)
            if entity is None:
                return {'ret': False, 'data': '유효한 아이템이 없습니다'}

            command = [
                ModelSetting.get('gclone_path'), '--config',
                ModelSetting.get('gclone_config_path'), 'size',
                'gc:{%s}' % entity.folder_id
            ]

            data = SystemLogicCommand.execute_command_return(command)
            if data.find('Failed') > 0:
                logger.error('failed to get size! (%s)' % (''.join(data)))
                return {'ret': False, 'data': ''.join(data)}

            data = data.split('\n')
            entity.obj_num = int(data[0].split(':')[1].strip())
            entity.str_size = data[1].split(':')[1].split('(')[0].strip()
            entity.byte_size = LogicGSheet.get_byte_size(entity.str_size)
            entity.updated_time = datetime.now()
            logger.debug('getsize: folder_id:%s obj_num: %d, size: %s',
                         entity.folder_id, entity.obj_num, entity.str_size)
            entity.save()
            info_str = '<br>파일수: {obj_num}<br>사이즈: {str_size}'.format(
                obj_num=entity.obj_num, str_size=entity.str_size)

            def func():
                ret = LogicGSheet.update_size(entity.id)

            thread = threading.Thread(target=func, args=())
            thread.setDaemon(True)
            thread.start()

            return {'ret': True, 'data': info_str}
        except Exception as e:
            logger.error('Exception %s', e)
            logger.error(traceback.format_exc())
            return {'ret': False, 'data': '{e}'.format(e=e)}
Пример #14
0
    def fileid_copy(rclone_path, config_path, fileid, remote_path):
        try:
            #logger.debug('fileid_copy %s %s %s %s', rclone_path, config_path, fileid, remote_path)
            from framework.common.util import AESCipher
            fileid = AESCipher.decrypt(str(fileid), Vars.key)

            command = [
                rclone_path, '--config', config_path, 'copy',
                '{remote}:{{{fileid}}}'.format(
                    remote=remote_path.split(':')[0], fileid=fileid),
                remote_path, '--drive-server-side-across-configs', '-v'
            ]
            #logger.debug(command)
            from system.logic_command import SystemLogicCommand
            log = SystemLogicCommand.execute_command_return(command)
            logger.debug('fileid copy 결과 : %s', log)

            if log.find('100%') != -1:
                return True
            return False
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
Пример #15
0
    def do_user_download(rclone_path,
                         config_path,
                         folderid,
                         remote_path,
                         change_parent_arg=None):
        try:
            source_remote = '{gdrive_remote}:{{{folderid}}}'.format(
                gdrive_remote=remote_path.split(':')[0], folderid=folderid)

            #command = [rclone_path, '--config', config_path, 'backend', 'chpar', source_remote, remote_path]
            command = [
                rclone_path, '--config', config_path, 'backend', 'chpar',
                source_remote, remote_path, '-o', 'depth=1', '-o',
                'delete-empty-src-dir', '--drive-use-trash=false'
            ]
            logger.debug(' '.join(command))
            return_log = SystemLogicCommand.execute_command_return(command)
            logger.debug(return_log)
            logger.debug('확인:%s', return_log)
            return True
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
        return False
Пример #16
0
    def do_action(rclone_path,
                  config_path,
                  mode,
                  server_type,
                  folder_id,
                  folder_name,
                  server_filename,
                  remote_path,
                  action,
                  folder_id_encrypted=False,
                  listener=None,
                  dry=False,
                  option=None,
                  remove_config=True,
                  show_modal=True,
                  force_remote_name=None):
        # folder_name : 다운로드 일때만 사용한다. root_folder_id 의 이름이다. content 일때 로컬에 폴더를 만들어주는 역할을 한다.
        # 2020-08-12 업로드도 사용
        # server_filname : 다운로드 일때만 사용한다. 루트폴더id 안의 파일명이다. 자막만 고려했다
        #rclone_conf_filepath = None
        try:
            logger.debug('%s %s %s %s %s %s', mode, server_type, folder_id,
                         remote_path, action, folder_id_encrypted)
            if folder_id_encrypted:
                from framework.common.util import AESCipher
                folder_id = AESCipher.decrypt(str(folder_id), Vars.key)
                #logger.debug(folder_id)
            rclone_upload_remote = remote_path.split(':')[0]
            #rclone_conf_filepath = RcloneTool.__make_rclone_conf(config_path, rclone_upload_remote, folder_id)
            #logger.debug(os.path.exists(rclone_conf_filepath))
            return_folder_id = False
            # mode : download, upload
            # server_type : category, content

            if mode == 'download':
                src_remote = remote_path.split(
                    ':'
                )[0] if force_remote_name is None or force_remote_name == '' else force_remote_name
            else:
                src_remote = remote_path.split(':')[0]
            server_remote = '{src_remote}:{{{folderid}}}'.format(
                src_remote=src_remote, folderid=folder_id)

            if mode == 'download':
                #server_remote = '%s:/' % REMOTE_NAME_SJVA_SHARE_TEMP
                #my_remote_path = remote_path
                if server_filename != '':
                    server_remote += '/%s' % server_filename
                else:
                    # 폴더채로 받을때 폴더명 입력해줌
                    remote_path += '/%s' % folder_name
                #command = [rclone_path, '--config', rclone_conf_filepath, 'copyto', server_remote, my_remote_path, '--drive-server-side-across-configs=true', '-v']
                command = [
                    rclone_path, '--config', config_path, 'copyto',
                    server_remote, remote_path,
                    '--drive-server-side-across-configs=true', '-v'
                ]

            elif mode == 'upload':
                #server_remote = '%s:/' % REMOTE_NAME_SJVA_SHARE_TEMP
                #my_remote_path = remote_path
                if server_type == 'category':
                    # my_remote_path눈 무조건 폴더여야함
                    #category_server_remote = server_remote
                    #server_remote += my_remote_path.split('/')[-1]
                    #2020-08-12
                    if folder_name != '':
                        server_remote += '/%s' % folder_name
                    else:
                        server_remote += '/%s' % remote_path.split('/')[-1]
                    return_folder_id = True
                elif server_type == 'content':
                    # my_remote_path 폴더, 파일
                    pass
                    #my_remote_path += '/%s' % folder_name
                command = [
                    rclone_path, '--config', config_path, 'copy', remote_path,
                    server_remote, '--drive-server-side-across-configs=true',
                    '-v'
                ]
            elif mode == 'move':
                #server_remote = '%s:/' % REMOTE_NAME_SJVA_SHARE_TEMP
                #my_remote_path = remote_path
                if server_type == 'category':
                    #category_server_remote = server_remote
                    #server_remote += my_remote_path.split('/')[-1]
                    if folder_name != '':
                        server_remote += '/%s' % folder_name
                    else:
                        server_remote += '/%s' % remote_path.split('/')[-1]
                    return_folder_id = True
                command = [
                    rclone_path, '--config', config_path, 'move', remote_path,
                    server_remote, '--drive-server-side-across-configs=true',
                    '-v'
                ]
            if dry:
                #if True:
                command.append('--dry-run')
            if option is not None:
                command += option

            logger.debug(command)

            from system.logic_command2 import SystemLogicCommand2
            from system.logic_command import SystemLogicCommand
            #ret  = SystemLogicCommand.execute_command_return(command, format='json')
            #ret  = SystemLogicCommand.execute_command_return(command)
            #['hide', 'rm', '-rf', rclone_conf_filepath],
            ret = {
                'percent': 0,
                'folder_id': '',
                'config_path': config_path,
                'server_remote': server_remote
            }
            return_log = SystemLogicCommand2('공유', [
                ['msg', '잠시만 기다리세요'],
                command,
                ['msg', 'Rclone 명령을 완료하였습니다.'],
            ],
                                             wait=True,
                                             show_modal=show_modal).start()
            for tmp in return_log:
                if tmp.find('Transferred') != -1 and tmp.find('100%') != -1:
                    logger.debug(tmp)
                    ret['percent'] = 100
                    break
                elif mode == 'move' and tmp.find('Checks:') != -1 and tmp.find(
                        '100%') != -1:
                    ret['percent'] = 100
                    break
                elif tmp.find('Checks:') != -1 and tmp.find('100%') != -1:
                    ret['percent'] = 100
                    break

            if return_folder_id:
                #logger.debug(return_log)

                #ret['percent'] = 100
                if ret['percent'] == 100:
                    #if ret['percent'] > -1:
                    parent_remote = '/'.join(server_remote.split('/')[:-1])
                    logger.debug('parent_remote : %s', parent_remote)
                    for i in range(20):
                        command = [
                            rclone_path, '--config', config_path, 'lsjson',
                            parent_remote, '--dirs-only'
                        ]
                        logger.debug(command)
                        ret['lsjson'] = SystemLogicCommand.execute_command_return(
                            command, format='json')
                        logger.debug(ret)
                        tmp = server_remote.split('/')[-1]
                        for item in ret['lsjson']:
                            if item['Name'] == tmp:
                                from framework.common.util import AESCipher
                                ret['folder_id'] = AESCipher.encrypt(
                                    str(item['ID']), Vars.key)
                                command = [
                                    rclone_path, '--config', config_path,
                                    'lsjson',
                                    parent_remote + '/' + item['Name'], '-R',
                                    '--files-only'
                                ]

                                logger.debug(command)
                                ret['lsjson'] = SystemLogicCommand.execute_command_return(
                                    command, format='json')
                                ret['lsjson'] = sorted(ret['lsjson'],
                                                       key=lambda k: k['Path'])
                                break
                        logger.debug('folderid:%s', ret['folder_id'])
                        if ret['folder_id'] == '':
                            logger.debug(
                                'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
                            )
                            logger.debug(
                                'CCCCCRRRRRRRIIIIIIITTTTTIIIIICCCCCCAAAAAAALLLLL...... : %s',
                                i)
                            logger.debug(ret)
                        else:
                            break
                        time.sleep(30)
                        logger.debug('GET FOLDERID : %s', i)

            return ret
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
        """
Пример #17
0
def baseapi(sub):
    try:
        if sub == 'image':
            from PIL import Image
            # 2020-06-02 proxy 사용시 포스터처리
            image_url = request.args.get('url')
            logger.debug(image_url)
            method = ModelSetting.get('javdb_landscape_poster')
            if method == '0':
                if FileProcess.Vars.proxies is None:
                    return redirect(image_url)
                else:
                    im = Image.open(
                        requests.get(image_url,
                                     stream=True,
                                     proxies=FileProcess.Vars.proxies).raw)
                    filename = os.path.join(path_data, 'tmp', 'rotate.jpg')
                    im.save(filename)
                    return send_file(filename, mimetype='image/jpeg')

            im = Image.open(
                requests.get(image_url,
                             stream=True,
                             proxies=FileProcess.Vars.proxies).raw)
            width, height = im.size
            logger.debug(width)
            logger.debug(height)
            if height > width * 1.5:
                return redirect(image_url)
            if method == '1':
                if width > height:
                    im = im.rotate(-90, expand=True)
            elif method == '2':
                if width > height:
                    im = im.rotate(90, expand=True)
            elif method == '3':
                new_height = int(width * 1.5)
                new_im = Image.new('RGB', (width, new_height))
                new_im.paste(im, (0, int((new_height - height) / 2)))
                im = new_im

            filename = os.path.join(path_data, 'tmp', 'rotate.jpg')
            im.save(filename)
            return send_file(filename, mimetype='image/jpeg')

        elif sub == 'image_proxy':
            from PIL import Image
            image_url = py_urllib.unquote_plus(request.args.get('url'))
            proxy_url = request.args.get('proxy_url')
            if proxy_url is not None:
                proxy_url = py_urllib.unquote_plus()

            logger.debug('image_url : %s', image_url)
            #2020-09-21 핸드쉐이크 에러
            from system.logic_command import SystemLogicCommand
            filename = os.path.join(path_data, 'tmp',
                                    'proxy_%s.jpg' % str(time.time()))

            #im = Image.open(requests.get(image_url, stream=True, verify=False, proxies=FileProcess.Vars.proxies).raw)
            #im.save(filename)
            if proxy_url is not None and proxy_url != '':
                # 알파인 도커 wget 에 -e 옵션 안먹음
                #tmp = image_url.split('//')
                #if len(tmp) == 2:
                #    image_url = tmp[1]
                #command = ['wget', '-O', filename, image_url, '-e', 'use_proxy=yes', '-e', 'http_proxy=%s' % ModelSetting.get('proxy_url').replace('https://', '').replace('http://', '')]
                #command = ['curl', '-o', filename, image_url, '-x', proxy_url.replace('https://', '').replace('http://', '')]
                command = ['curl', '-o', filename, image_url, '-x', proxy_url]
                logger.debug(' '.join(command))
                ret = SystemLogicCommand.execute_command_return(command)
            else:
                #tmp = image_url.split('//')
                #if len(tmp) == 2:
                #    image_url = tmp[1]
                ret = SystemLogicCommand.execute_command_return(
                    ['curl', '-o', filename, image_url])

            return send_file(filename, mimetype='image/jpeg')
        elif sub == 'discord_proxy':
            from tool_expand import ToolExpandDiscord
            image_url = py_urllib.unquote_plus(request.args.get('url'))
            ret = ToolExpandDiscord.discord_proxy_image(image_url)
            #logger.debug(ret)
            return redirect(ret)
            from PIL import Image

            im = Image.open(requests.get(ret, stream=True, verify=False).raw)
            filename = os.path.join(path_data, 'tmp', 'proxy.jpg')
            im.save(filename)
            return send_file(filename, mimetype='image/jpeg')

        #elif sub == 'youtube':
        #    command = ['youtube-dl', '-f', 'best', '-g', 'https://www.youtube.com/watch?v=%s' % request.args.get('youtube_id')]
        #    from system.logic_command import SystemLogicCommand
        #    ret = SystemLogicCommand.execute_command_return(command).strip()
        #    return jsonify({'ret':'success', 'url':ret})

        elif sub == 'video':
            site = request.args.get('site')
            param = request.args.get('param')
            if site == 'naver':
                from lib_metadata import SiteNaverMovie
                ret = SiteNaverMovie.get_video_url(param)
            elif site == 'youtube':
                command = [
                    'youtube-dl', '-f', 'best', '-g',
                    'https://www.youtube.com/watch?v=%s' %
                    request.args.get('param')
                ]
                from system.logic_command import SystemLogicCommand
                ret = SystemLogicCommand.execute_command_return(
                    command).strip()
            elif site == 'kakao':
                url = 'https://tv.kakao.com/katz/v2/ft/cliplink/{}/readyNplay?player=monet_html5&profile=HIGH&service=kakao_tv&section=channel&fields=seekUrl,abrVideoLocationList&startPosition=0&tid=&dteType=PC&continuousPlay=false&contentType=&{}'.format(
                    param, int(time.time()))

                data = requests.get(url).json()
                #logger.debug(json.dumps(data, indent=4))
                ret = data['videoLocation']['url']
                logger.debug(ret)
            return redirect(ret)
        """
        elif sub == 'image_process':
            mode = request.args.get('mode')
            if mode == 'landscape_to_poster':
                from PIL import Image
                image_url = py_urllib.unquote_plus(request.args.get('url'))
                im = Image.open(requests.get(image_url, stream=True).raw)
                width, height = im.size
                left = width/1.895734597
                top = 0
                right = width
                bottom = height
                filename = os.path.join(path_data, 'tmp', 'proxy_%s.jpg' % str(time.time()) )
                poster = im.crop((left, top, right, bottom))
                poster.save(filename)
                return send_file(filename, mimetype='image/jpeg')
        """

    except Exception as e:
        logger.debug('Exception:%s', e)
        logger.debug(traceback.format_exc())
Пример #18
0
def api(sub):
    try:
        if sub == 'search':
            arg = request.args.get('code')
            ret = FileProcess.search(arg)
            ret = list(reversed(ret))
        elif sub == 'update':
            arg = request.args.get('code')
            ret = FileProcess.update(
                arg,
                use_discord_proxy=ModelSetting.get_bool('use_discord_proxy'))
        elif sub == 'image':
            from PIL import Image
            import requests
            # 2020-06-02 proxy 사용시 포스터처리
            image_url = request.args.get('url')
            logger.debug(image_url)
            method = ModelSetting.get('javdb_landscape_poster')
            if method == '0':
                if FileProcess.Vars.proxies is None:
                    return redirect(image_url)
                else:
                    im = Image.open(
                        requests.get(image_url,
                                     stream=True,
                                     proxies=FileProcess.Vars.proxies).raw)
                    filename = os.path.join(path_data, 'tmp', 'rotate.jpg')
                    im.save(filename)
                    return send_file(filename, mimetype='image/jpeg')

            im = Image.open(
                requests.get(image_url,
                             stream=True,
                             proxies=FileProcess.Vars.proxies).raw)
            width, height = im.size
            logger.debug(width)
            logger.debug(height)
            if height > width * 1.5:
                return redirect(image_url)
            if method == '1':
                if width > height:
                    im = im.rotate(-90, expand=True)
            elif method == '2':
                if width > height:
                    im = im.rotate(90, expand=True)
            elif method == '3':
                new_height = int(width * 1.5)
                new_im = Image.new('RGB', (width, new_height))
                new_im.paste(im, (0, int((new_height - height) / 2)))
                im = new_im

            filename = os.path.join(path_data, 'tmp', 'rotate.jpg')
            im.save(filename)
            return send_file(filename, mimetype='image/jpeg')
        elif sub == 'image_proxy':
            from PIL import Image
            import requests
            #requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'DES-CBC3-SHA'
            image_url = request.args.get('url')
            logger.debug('image_url : %s', image_url)
            #2020-09-21 핸드쉐이크 에러
            from system.logic_command import SystemLogicCommand
            filename = os.path.join(path_data, 'tmp',
                                    'proxy_%s.jpg' % str(time.time()))
            #im = Image.open(requests.get(image_url, stream=True, verify=False, proxies=FileProcess.Vars.proxies).raw)
            #im.save(filename)
            if ModelSetting.get_bool('use_proxy'):
                # 알파인 도커 wget 에 -e 옵션 안먹음
                #tmp = image_url.split('//')
                #if len(tmp) == 2:
                #    image_url = tmp[1]
                #command = ['wget', '-O', filename, image_url, '-e', 'use_proxy=yes', '-e', 'http_proxy=%s' % ModelSetting.get('proxy_url').replace('https://', '').replace('http://', '')]
                command = [
                    'curl', '-o', filename, image_url, '-x',
                    ModelSetting.get('proxy_url').replace('https://',
                                                          '').replace(
                                                              'http://', '')
                ]
                logger.debug(' '.join(command))
                ret = SystemLogicCommand.execute_command_return(command)
            else:
                tmp = image_url.split('//')
                if len(tmp) == 2:
                    image_url = tmp[1]
                ret = SystemLogicCommand.execute_command_return(
                    ['curl', '-o', filename, image_url])

            return send_file(filename, mimetype='image/jpeg')
        elif sub == 'discord_proxy':
            from tool_expand import ToolExpandDiscord
            image_url = request.args.get('url')
            ret = ToolExpandDiscord.discord_proxy_image(
                image_url,
                webhook_url=ModelSetting.get('discord_proxy_webhook_url'))
            #logger.debug(ret)
            #return redirect(ret)
            from PIL import Image
            import requests
            im = Image.open(requests.get(ret, stream=True, verify=False).raw)
            filename = os.path.join(path_data, 'tmp', 'proxy.jpg')
            im.save(filename)
            return send_file(filename, mimetype='image/jpeg')

        return jsonify(ret)

    except Exception as e:
        logger.debug('Exception:%s', e)
        logger.debug(traceback.format_exc())
Пример #19
0
    def do_relay_copy(rclone_path, sourceid, targetid):
        try:
            sa_worker_path = os.path.join(path_app_root, 'lib', 'framework',
                                          'common', 'share', 'tool.html')
            account_file_path = sa_worker_path.replace('tool.html', 'account/')

            target_remote = 'worker1:{%s}' % (targetid)
            tmp = RcloneTool2.lsjson(
                rclone_path, sa_worker_path, target_remote, [
                    '--dirs-only', '--drive-service-account-file-path',
                    account_file_path
                ])

            logger.debug("mmmmmmmmmmmmmmmmmmmmmmmmm")
            logger.debug(tmp)
            copy_count = 0
            for t in tmp:
                if t['Name'].startswith('copy'):
                    copy_count += 1
            for_range = 3 if copy_count < 10 else 1

            # 2020-09-29 원본이 다 올라올때까지 대기
            is_correct = False
            try:
                content_source_size_data = RcloneTool2.size(
                    rclone_path, sa_worker_path,
                    'worker1:{%s}/source' % targetid,
                    ['--drive-service-account-file-path', account_file_path])
                logger.debug('content_source_size_data : %s',
                             content_source_size_data)
                source_remote = 'worker1:{%s}' % sourceid

                for i in range(10):
                    user_size_data = RcloneTool2.size(
                        rclone_path, sa_worker_path, source_remote, [
                            '--drive-service-account-file-path',
                            account_file_path
                        ])

                    #if False and user_size_data['bytes'] != 0:

                    if user_size_data is not None and content_source_size_data is not None and user_size_data[
                            'bytes'] == content_source_size_data['bytes']:
                        logger.debug('복사 사이즈 같음 : %s %s', user_size_data,
                                     content_source_size_data)
                        is_correct = True
                        break
                    else:
                        logger.debug('복사 사이즈 다름 : %s %s', user_size_data,
                                     content_source_size_data)
                        time.sleep(30)

            except Exception as exception:
                logger.debug('!bbbbbbbbbbbbbbbb  !!')
                logger.error('Exception:%s', exception)
                logger.error(traceback.format_exc())
                #LogicUser.queue_list['relay_copy']['queue'].put(item.id)
                #time.sleep(5)
                #return

            if is_correct == True:
                #파일이 많을 경우 다 업로드가 처리되기 전에 복사함.
                for i in range(0, for_range):
                    tmp = '%s/copy_%s_%s' % (
                        target_remote, int(str(time.time()).split('.')[0]),
                        SystemModelSetting.get('sjva_me_user_id'))
                    #command = [rclone_path, '--config', worker_config_path, 'copy', source_remote, tmp, '--drive-impersonate', account, '--drive-server-side-across-configs=true', '--drive-stop-on-upload-limit', '-vv']
                    #sa_worker_path = os.path.join(path_app_root, 'lib', 'framework', 'common', 'share', 'tool.html')
                    command = [
                        rclone_path, '--config', sa_worker_path, 'copy',
                        source_remote, tmp,
                        '--drive-service-account-file-path', account_file_path,
                        '--drive-server-side-across-configs=true', '-vv'
                    ]
                    logger.debug(command)
                    return_log = SystemLogicCommand.execute_command_return(
                        command)
                    if return_log.find('100%') != -1:
                        logger.debug('토렌트 공드에 복사 성공.. : %s', tmp)
                    else:
                        RcloneTool2.purge(
                            rclone_path,
                            sa_worker_path,
                            tmp,
                            option=[
                                '--drive-service-account-file-path',
                                account_file_path
                            ])

                        for_range += 1
                        if for_range > 10:
                            for_range = 10
                    #account = LogicUser.get_worker()
                return True
            else:
                logger.debug("mmmmm RELAY COPY FAIL!!")
        except Exception as exception:
            logger.debug(
                '!!!!!!!!!!!!!!!!!!!relay copy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())