linkkf 로직수정중
This commit is contained in:
@@ -116,7 +116,11 @@ class SupportFfmpeg(object):
|
||||
header_count = 0
|
||||
if self.proxy is None:
|
||||
if self.headers is None:
|
||||
command = [self.__ffmpeg_path, '-y', '-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
if platform.system() == 'Windows':
|
||||
command = [self.__ffmpeg_path, '-y', '-i', f'"{self.url}"', '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
else:
|
||||
command = [self.__ffmpeg_path, '-y', '-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
|
||||
else:
|
||||
headers_command = []
|
||||
tmp = ""
|
||||
@@ -136,9 +140,15 @@ class SupportFfmpeg(object):
|
||||
if len(tmp) > 0:
|
||||
headers_command.append('-headers')
|
||||
headers_command.append(f'{tmp}')
|
||||
command = [self.__ffmpeg_path, '-y'] + headers_command + ['-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
if platform.system() == 'Windows':
|
||||
command = [self.__ffmpeg_path, '-y'] + headers_command + ['-i', f'"{self.url}"', '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
else:
|
||||
command = [self.__ffmpeg_path, '-y'] + headers_command + ['-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
else:
|
||||
command = [self.__ffmpeg_path, '-y', '-http_proxy', self.proxy, '-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
if platform.system() == 'Windows':
|
||||
command = [self.__ffmpeg_path, '-y', '-http_proxy', self.proxy, '-i', f'"{self.url}"', '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
else:
|
||||
command = [self.__ffmpeg_path, '-y', '-http_proxy', self.proxy, '-i', self.url, '-c', 'copy', '-bsf:a', 'aac_adtstoasc']
|
||||
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
@@ -159,7 +169,7 @@ class SupportFfmpeg(object):
|
||||
return
|
||||
except:
|
||||
pass
|
||||
#logger.error(' '.join(command))
|
||||
logger.error(' '.join(command))
|
||||
command = SupportSubprocess.command_for_windows(command)
|
||||
|
||||
if platform.system() == 'Windows' and header_count > 1:
|
||||
@@ -216,8 +226,8 @@ SET CRLF=^
|
||||
else:
|
||||
if os.path.exists(self.temp_fullpath):
|
||||
os.remove(self.temp_fullpath)
|
||||
except Exception as exception:
|
||||
logger.error('Exception:%s', exception)
|
||||
except Exception as e:
|
||||
logger.error(f"Exception:{str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
arg = {'type':'last', 'status':self.status, 'data' : self.get_data()}
|
||||
@@ -347,6 +357,7 @@ SET CRLF=^
|
||||
return data
|
||||
|
||||
def send_to_listener(self, **arg):
|
||||
print(arg)
|
||||
if self.total_callback_function != None:
|
||||
self.total_callback_function(**arg)
|
||||
if self.callback_function is not None and self.callback_function != self.total_callback_function:
|
||||
|
||||
27
lib/support/expand/ffprobe.py
Normal file
27
lib/support/expand/ffprobe.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import traceback
|
||||
|
||||
from support import SupportSubprocess, logger
|
||||
|
||||
|
||||
class SupportFfprobe:
|
||||
__ffprobe_path = 'ffprobe'
|
||||
|
||||
@classmethod
|
||||
def initialize(cls, __ffprobe_path):
|
||||
cls.__ffprobe_path = __ffprobe_path
|
||||
|
||||
@classmethod
|
||||
def ffprobe(cls, filepath, ffprobe_path=None, option=None):
|
||||
try:
|
||||
if ffprobe_path == None:
|
||||
ffprobe_path = cls.__ffprobe_path
|
||||
|
||||
command = [ffprobe_path, '-v', 'quiet', '-print_format', 'json', '-show_format', '-show_streams', filepath]
|
||||
if option is not None:
|
||||
command += option
|
||||
logger.warning(' '.join(command))
|
||||
ret = SupportSubprocess.execute_command_return(command, format='json')
|
||||
return ret['log']
|
||||
except Exception as e:
|
||||
logger.error(f"Exception:{str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
@@ -204,9 +204,9 @@ class GoogleSheetBase:
|
||||
break
|
||||
except gspread.exceptions.APIError:
|
||||
self.sleep_exception()
|
||||
except Exception as exception:
|
||||
except Exception as e:
|
||||
logger.error(f"{key} - {value}")
|
||||
logger.error('Exception:%s', exception)
|
||||
logger.error(f"Exception:{str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
logger.error(self.header_info)
|
||||
self.sleep_exception()
|
||||
|
||||
197
lib/support/expand/rclone.py
Normal file
197
lib/support/expand/rclone.py
Normal file
@@ -0,0 +1,197 @@
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from support import SupportSubprocess, d, logger
|
||||
|
||||
|
||||
class SupportRclone(object):
|
||||
__instance_list = []
|
||||
|
||||
__rclone_path = 'rclone'
|
||||
__rclone_config_path = 'rclone.conf'
|
||||
|
||||
|
||||
@classmethod
|
||||
def initialize(cls, __rclone_path, __rclone_config_path):
|
||||
cls.__rclone_path = __rclone_path
|
||||
cls.__rclone_config_path = __rclone_config_path
|
||||
|
||||
@classmethod
|
||||
def get_rclone_path(cls):
|
||||
return cls.__rclone_path
|
||||
|
||||
@classmethod
|
||||
def __get_cmd(cls, config_path=None):
|
||||
command = [cls.__rclone_path]
|
||||
if config_path == None:
|
||||
command += ['--config', cls.__rclone_config_path]
|
||||
else:
|
||||
command += ['--config', config_path]
|
||||
return command
|
||||
|
||||
|
||||
@classmethod
|
||||
def rclone_cmd(cls):
|
||||
return [cls.__rclone_path, '--config', cls.__rclone_config_path]
|
||||
|
||||
@classmethod
|
||||
def get_version(cls, rclone_path=None):
|
||||
try:
|
||||
if rclone_path == None:
|
||||
rclone_path = cls.__rclone_path
|
||||
cmd = [rclone_path, '--version']
|
||||
result = SupportSubprocess.execute_command_return(cmd)
|
||||
if result != None and result['status'] == 'finish':
|
||||
return result['log']
|
||||
except Exception as e:
|
||||
logger.error(f'Exception:{str(e)}')
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@classmethod
|
||||
def config_list(cls, rclone_path=None, rclone_config_path=None, option=None):
|
||||
try:
|
||||
if rclone_path == None:
|
||||
rclone_path = cls.__rclone_path
|
||||
if rclone_config_path == None:
|
||||
rclone_config_path = cls.__rclone_config_path
|
||||
if os.path.exists(rclone_config_path) == False:
|
||||
return
|
||||
command = [rclone_path, '--config', rclone_config_path, 'config', 'dump']
|
||||
if option is not None:
|
||||
command += option
|
||||
result = SupportSubprocess.execute_command_return(command, format='json')
|
||||
for key, value in result['log'].items():
|
||||
if 'token' in value and value['token'].startswith('{'):
|
||||
value['token'] = json.loads(value['token'])
|
||||
return result['log']
|
||||
except Exception as e:
|
||||
logger.error(f'Exception:{str(e)}')
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
@classmethod
|
||||
def get_config(cls, remote_name, rclone_path=None, rclone_config_path=None, option=None):
|
||||
try:
|
||||
data = cls.config_list(rclone_path=rclone_path, rclone_config_path=rclone_config_path, option=option)
|
||||
return data.get(remote_name, None)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Exception:{str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@classmethod
|
||||
def lsjson(cls, remote_path, config_path=None, option=None):
|
||||
return cls.__execute_one_param('lsjson', remote_path, config_path=config_path, option=option, format='json')
|
||||
|
||||
|
||||
@classmethod
|
||||
def lsf(cls, remote_path, config_path=None, option=None):
|
||||
if option == None:
|
||||
option = ['--max-depth=1']
|
||||
return cls.__execute_one_param('lsf', remote_path, config_path=config_path, option=option, format='json')
|
||||
|
||||
|
||||
@classmethod
|
||||
def size(cls, remote_path, config_path=None, option=None):
|
||||
if option == None:
|
||||
option = ['--json']
|
||||
return cls.__execute_one_param('size', remote_path, config_path=config_path, option=option, format='json')
|
||||
|
||||
|
||||
@classmethod
|
||||
def mkdir(cls, remote_path, config_path=None, option=None):
|
||||
return cls.__execute_one_param('mkdir', remote_path, config_path=config_path, option=option, format='json')
|
||||
|
||||
@classmethod
|
||||
def purge(cls, remote_path, config_path=None, option=None):
|
||||
return cls.__execute_one_param('purge', remote_path, config_path=config_path, option=option, format='json')
|
||||
|
||||
|
||||
@classmethod
|
||||
def __execute_one_param(cls, command, remote_path, config_path=None, option=None, format=None):
|
||||
try:
|
||||
command = cls.__get_cmd(config_path) + [command, remote_path]
|
||||
if option is not None:
|
||||
command += option
|
||||
result = SupportSubprocess.execute_command_return(command, format=format)
|
||||
ret = None
|
||||
if result != None and result['status'] == 'finish':
|
||||
ret = result['log']
|
||||
return ret
|
||||
except Exception as e:
|
||||
logger.error(f'Exception:{str(e)}')
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@classmethod
|
||||
def copy(cls, src, tar, config_path=None, option=None):
|
||||
return cls.__execute_two_param('copy', src, tar, config_path=config_path, option=option)
|
||||
|
||||
@classmethod
|
||||
def copy_server_side(cls, src, tar, config_path=None, option=None):
|
||||
if option == None:
|
||||
option = ['--drive-server-side-across-configs=true', '--delete-empty-src-dirs']
|
||||
return cls.__execute_two_param('copy', src, tar, config_path=config_path, option=option)
|
||||
|
||||
@classmethod
|
||||
def move(cls, src, tar, config_path=None, option=None):
|
||||
return cls.__execute_two_param('move', src, tar, config_path=config_path, option=option)
|
||||
|
||||
@classmethod
|
||||
def move_server_side(cls, src, tar, config_path=None, option=None):
|
||||
if option == None:
|
||||
option = ['--drive-server-side-across-configs=true', '--delete-empty-src-dirs']
|
||||
return cls.__execute_two_param('move', src, tar, config_path=config_path, option=option)
|
||||
|
||||
@classmethod
|
||||
def __execute_two_param(cls, command, src, tar, config_path=None, option=None, format=None):
|
||||
try:
|
||||
command = cls.__get_cmd(config_path) + [command, src, tar]
|
||||
if option is not None:
|
||||
command += option
|
||||
result = SupportSubprocess.execute_command_return(command, format=format)
|
||||
ret = None
|
||||
if result != None and result['status'] == 'finish':
|
||||
ret = result['log']
|
||||
return ret
|
||||
except Exception as e:
|
||||
logger.error(f'Exception:{str(e)}')
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def getid(cls, remote_path, config_path=None, option=None):
|
||||
try:
|
||||
command = cls.__get_cmd(config_path) + ['backend', 'getid', remote_path]
|
||||
if option is not None:
|
||||
command += option
|
||||
result = SupportSubprocess.execute_command_return(command)
|
||||
ret = None
|
||||
if result != None and result['status'] == 'finish':
|
||||
ret = result['log']
|
||||
if ret is not None and (len(ret.split(' ')) > 1 or ret == ''):
|
||||
ret = None
|
||||
return ret
|
||||
except Exception as e:
|
||||
logger.error(f"Exception:{str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@classmethod
|
||||
def chpar(cls, src, tar, config_path=None, option=None):
|
||||
try:
|
||||
command = cls.__get_cmd(config_path) + ['backend', 'chpar', src, tar, '-o', 'depth=1', '-o', 'delete-empty-src-dir', '--drive-use-trash=false']
|
||||
if option is not None:
|
||||
command += option
|
||||
result = SupportSubprocess.execute_command_return(command)
|
||||
ret = None
|
||||
if result != None and result['status'] == 'finish':
|
||||
ret = result['log']
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Exception:{str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
return False
|
||||
114
lib/support/expand/simple_selenium.py
Normal file
114
lib/support/expand/simple_selenium.py
Normal file
@@ -0,0 +1,114 @@
|
||||
import os
|
||||
|
||||
from support import d, logger
|
||||
|
||||
try:
|
||||
from selenium import webdriver
|
||||
except:
|
||||
os.system("pip install --upgrade selenium")
|
||||
from selenium import webdriver
|
||||
|
||||
import base64
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from selenium import webdriver
|
||||
from selenium.common.exceptions import UnexpectedAlertPresentException
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import Select, WebDriverWait
|
||||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
|
||||
|
||||
class SupportSimpleSelenium(object):
|
||||
|
||||
def __init__(self, P, mode="local", headless=False, remote=None):
|
||||
self.P = P
|
||||
self.driver = None
|
||||
self.timeout = 5
|
||||
self.driver_init(mode=mode, headless=headless, remote=remote)
|
||||
|
||||
|
||||
def driver_init(self, mode='local', headless=False, remote=None):
|
||||
if mode == 'local':
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
options = Options()
|
||||
if headless:
|
||||
options.add_argument('headless')
|
||||
self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
|
||||
elif mode == 'remote':
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
options = Options()
|
||||
#options.set_preference("general.useragent.override", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36")
|
||||
#options.set_preference("general.platform.override", "Win32")
|
||||
self.driver = webdriver.Remote(remote, options=options)
|
||||
|
||||
|
||||
def get_pagesoruce(self, url, wait_xpath="/html/body", retry=True):
|
||||
try:
|
||||
self.driver.get(url)
|
||||
WebDriverWait(self.driver, self.timeout).until(lambda driver: driver.find_element(By.XPATH, wait_xpath))
|
||||
return self.driver.page_source
|
||||
except Exception as e:
|
||||
logger.error('Exception:%s', e)
|
||||
logger.error(traceback.format_exc())
|
||||
self.driver_quit()
|
||||
if retry:
|
||||
return self.get_pagesoruce(url, wait_xpath=wait_xpath, retry=False)
|
||||
|
||||
|
||||
def driver_quit(self):
|
||||
if self.driver != None:
|
||||
def func():
|
||||
self.driver.quit()
|
||||
self.driver = None
|
||||
#self.logger.debug('driver quit..')
|
||||
th = threading.Thread(target=func, args=())
|
||||
th.setDaemon(True)
|
||||
th.start()
|
||||
|
||||
def get_downloaded_files(self):
|
||||
if not self.driver.current_url.startswith("chrome://downloads"):
|
||||
self.driver.get("chrome://downloads/")
|
||||
#driver.implicitly_wait(4)
|
||||
self.driver.implicitly_wait(2)
|
||||
return self.driver.execute_script( \
|
||||
"return document.querySelector('downloads-manager') "
|
||||
" .shadowRoot.querySelector('#downloadsList') "
|
||||
" .items.filter(e => e.state === 'COMPLETE') "
|
||||
" .map(e => e.filePath || e.file_path || e.fileUrl || e.file_url); ")
|
||||
|
||||
|
||||
|
||||
def get_file_content(self, path):
|
||||
elem = self.driver.execute_script( \
|
||||
"var input = window.document.createElement('INPUT'); "
|
||||
"input.setAttribute('type', 'file'); "
|
||||
"input.hidden = true; "
|
||||
"input.onchange = function (e) { e.stopPropagation() }; "
|
||||
"return window.document.documentElement.appendChild(input); " )
|
||||
|
||||
elem._execute('sendKeysToElement', {'value': [ path ], 'text': path})
|
||||
|
||||
result = self.driver.execute_async_script( \
|
||||
"var input = arguments[0], callback = arguments[1]; "
|
||||
"var reader = new FileReader(); "
|
||||
"reader.onload = function (ev) { callback(reader.result) }; "
|
||||
"reader.onerror = function (ex) { callback(ex.message) }; "
|
||||
"reader.readAsDataURL(input.files[0]); "
|
||||
"input.remove(); "
|
||||
, elem)
|
||||
|
||||
if not result.startswith('data:') :
|
||||
raise Exception("Failed to get file content: %s" % result)
|
||||
|
||||
return base64.b64decode(result[result.find('base64,') + 7:])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# docker run -d --name selenium_chromium -it -p 4446:4444 -p 5902:5900 -p 7902:7900 --shm-size 2g seleniarm/standalone-chromium:latest
|
||||
Reference in New Issue
Block a user