ryry-cli 2.27__tar.gz → 2.29__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {ryry_cli-2.27/ryry_cli.egg-info → ryry_cli-2.29}/PKG-INFO +1 -1
  2. ryry_cli-2.29/ryry/constant.py +5 -0
  3. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/ryry_server_socket.py +9 -3
  4. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/ryry_webapi.py +2 -6
  5. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/ryry_widget.py +2 -1
  6. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/script_template/run.py +1 -5
  7. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/server_func.py +37 -18
  8. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/store.py +13 -16
  9. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/task.py +12 -57
  10. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/taskUtils.py +7 -0
  11. ryry_cli-2.29/ryry/upload.py +245 -0
  12. {ryry_cli-2.27 → ryry_cli-2.29/ryry_cli.egg-info}/PKG-INFO +1 -1
  13. {ryry_cli-2.27 → ryry_cli-2.29}/setup.py +1 -1
  14. ryry_cli-2.27/ryry/constant.py +0 -5
  15. ryry_cli-2.27/ryry/upload.py +0 -106
  16. {ryry_cli-2.27 → ryry_cli-2.29}/LICENSE +0 -0
  17. {ryry_cli-2.27 → ryry_cli-2.29}/README.md +0 -0
  18. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/__init__.py +0 -0
  19. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/main.py +0 -0
  20. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/ryry_service.py +0 -0
  21. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/script_template/__init__.py +0 -0
  22. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/script_template/main.py +0 -0
  23. {ryry_cli-2.27 → ryry_cli-2.29}/ryry/utils.py +0 -0
  24. {ryry_cli-2.27 → ryry_cli-2.29}/ryry_cli.egg-info/SOURCES.txt +0 -0
  25. {ryry_cli-2.27 → ryry_cli-2.29}/ryry_cli.egg-info/dependency_links.txt +0 -0
  26. {ryry_cli-2.27 → ryry_cli-2.29}/ryry_cli.egg-info/entry_points.txt +0 -0
  27. {ryry_cli-2.27 → ryry_cli-2.29}/ryry_cli.egg-info/requires.txt +0 -0
  28. {ryry_cli-2.27 → ryry_cli-2.29}/ryry_cli.egg-info/top_level.txt +0 -0
  29. {ryry_cli-2.27 → ryry_cli-2.29}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ryry-cli
3
- Version: 2.27
3
+ Version: 2.29
4
4
  Summary: ryry tools
5
5
  Home-page: https://github.com/dalipenMedia
6
6
  Author: dalipen
@@ -0,0 +1,5 @@
1
+ #!!!!! do not change this file !!!!!
2
+ app_version="2.29"
3
+ app_bulld_number=229
4
+ app_bulld_anchor="Noh_2024-08-14 18:08:47.761550"
5
+ app_name="ryry-cli"
@@ -56,12 +56,17 @@ class RyryTaskExecutor(Thread):
56
56
  if data is None:
57
57
  break
58
58
  try:
59
+ print(f"======= get data = {data}")
59
60
  taskUUID = data["taskUUID"]
61
+ domain = ""
62
+ params_tmp = json.loads(data["data"])
63
+ if "domain" in params_tmp:
64
+ domain = params_tmp["domain"]
60
65
  timeout = 600
61
66
  if "timeout" in data:
62
67
  timeout = data["timeout"]
63
68
  taskUtils.taskPrint(taskUUID, f"{current_thread().name} === receive task : {taskUUID}")
64
- _appendTask(taskUUID)
69
+ _appendTask(taskUUID, domain)
65
70
  is_ok, msg, result = task.runTask(data, timeout)
66
71
  if is_ok == False:
67
72
  taskUtils.notifyTaskFail(taskUUID, msg)
@@ -113,11 +118,12 @@ def _readTaskConfig():
113
118
  def _saveTaskConfig(data):
114
119
  with open(task_config_file, 'w') as f:
115
120
  json.dump(data, f)
116
- def _appendTask(taskUUID):
121
+ def _appendTask(taskUUID, subDomain):
117
122
  lock.acquire()
118
123
  task_config = _readTaskConfig()
119
124
  task_config[taskUUID] = {
120
- "pts": calendar.timegm(time.gmtime())
125
+ "pts": calendar.timegm(time.gmtime()),
126
+ "domain": subDomain
121
127
  }
122
128
  task_config["last_task_pts"] = task_config[taskUUID]["pts"]
123
129
  _saveTaskConfig(task_config)
@@ -38,12 +38,8 @@ def _aigc_post(func, params, files={}, timeout=10):
38
38
  #======================================== Task Function ==============================
39
39
  def _extend():
40
40
  extInfo = store.readDeviceInfo()
41
- extInfo["app_version"] = constant.app_version
42
- extInfo["app_bulld_number"] = constant.app_bulld_number
43
- extInfo["app_name"] = constant.app_name
44
- extInfo["dts"] = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S_%f')
45
- extInfo["trace_id"] = ''.join(str(uuid.uuid4()).split('-'))
46
- extInfo["host_name"] = utils.get_hostname()
41
+ extInfo["app"] = constant.app_name + " " + constant.app_version
42
+ extInfo["host"] = utils.get_hostname()
47
43
  return json.dumps(extInfo)
48
44
 
49
45
  def GetTask():
@@ -174,8 +174,9 @@ def addWidgetToEnv(root, mute=False):
174
174
  return
175
175
  data = GetWidgetConfig(root)
176
176
  widget_id = data["widget_id"]
177
+ name = data["name"]
177
178
  mainPythonPath = os.path.join(root, "main.py")
178
- store.insertWidget(widget_id, mainPythonPath)
179
+ store.insertWidget(widget_id, name, mainPythonPath)
179
180
  if mute == False:
180
181
  print(f"add {widget_id.ljust(len(widget_id)+4)} {mainPythonPath}")
181
182
 
@@ -10,11 +10,7 @@ def runTask(data):
10
10
  "type" : "text", #text audio image video
11
11
  "content": [
12
12
  "hello world"
13
- ],
14
- "extension" : {
15
- "info": "",
16
- "cover_url": ""
17
- }
13
+ ]
18
14
  }
19
15
  ],
20
16
  "status" : 0, #0 is success
@@ -1,9 +1,10 @@
1
- import time, urllib3, sys, os
1
+ import time, urllib3, sys, os, uuid
2
2
  from threading import Thread, Lock
3
3
 
4
4
  from ryry import ryry_webapi
5
- from ryry import store
5
+ from ryry import upload
6
6
  from ryry import taskUtils
7
+ from ryry import task
7
8
 
8
9
  lock = Lock()
9
10
  def print_progress_bar(iteration, total, name, idx, total_bars):
@@ -35,25 +36,37 @@ class TaskThread(Thread):
35
36
  if self.call_back == None:
36
37
  raise Exception("need callback function")
37
38
  self.start()
39
+
38
40
  def run(self):
39
41
  self.checking = False
40
42
  self.result = False, "Unknow"
41
43
  if len(self.func) > 0:
42
- self.checkUUID = ryry_webapi.createTask(self.func, self.params)
43
- print("")
44
- self.checking = True
45
- self.checkCount = 0
46
- time.sleep(5)
47
- while self.checking and self.checkCount < 200:
48
- finish, success, data, progress = ryry_webapi.checkTask(self.checkUUID)
49
- print_progress_bar(progress, 100, f"Task{self.idx} {self.func}", self.idx+1, self.total)
50
- if finish:
51
- self.checking = False
52
- if success:
53
- self.call_back(self.idx, data)
54
- return
55
- self.checkCount += 1
56
- time.sleep(3)
44
+ cmd = task.cmdWithWidgetName(self.func)
45
+ if cmd:
46
+ print("======")
47
+ executeSuccess, result_obj = task.executeLocalPython("local_" + ''.join(str(uuid.uuid4()).split('-')), cmd, self.params)
48
+ print(result_obj)
49
+ if executeSuccess and result_obj["status"] == 0:
50
+ self.call_back(self.idx, result_obj["result"])
51
+ return
52
+ else:
53
+ print("=====123123123=")
54
+ # run_server
55
+ self.checkUUID = ryry_webapi.createTask(self.func, self.params)
56
+ print("")
57
+ self.checking = True
58
+ self.checkCount = 0
59
+ time.sleep(5)
60
+ while self.checking and self.checkCount < 200:
61
+ finish, success, data, progress = ryry_webapi.checkTask(self.checkUUID)
62
+ print_progress_bar(progress, 100, f"Task{self.idx} {self.func}", self.idx+1, self.total)
63
+ if finish:
64
+ self.checking = False
65
+ if success:
66
+ self.call_back(self.idx, data)
67
+ return
68
+ self.checkCount += 1
69
+ time.sleep(3)
57
70
  else:
58
71
  print(f"widget {self.func} not found")
59
72
  self.call_back(self.idx, None)
@@ -65,7 +78,7 @@ class TaskThread(Thread):
65
78
  class Task:
66
79
  thread_data = {}
67
80
 
68
- def __init__(self, func: str, multi_params: list[dict], fromUUID=None):
81
+ def __init__(self, func: str, multi_params: list[dict], fromUUID=""):
69
82
  urllib3.disable_warnings()
70
83
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
71
84
 
@@ -73,11 +86,17 @@ class Task:
73
86
  if realTaskUUID == None or len(realTaskUUID) <= 0:
74
87
  realTaskUUID = taskUtils.taskInfoWithFirstTask()
75
88
 
89
+ support_subdomain = upload.getFirstSupportSubdomain()
90
+ domain = ""
91
+ if support_subdomain:
92
+ domain = support_subdomain["readpath"]
93
+
76
94
  def _callback(idx, data):
77
95
  self.thread_data[str(idx)]["result"] = data
78
96
  idx = 0
79
97
  for param in multi_params:
80
98
  param["fromUUID"] = realTaskUUID
99
+ param["domain"] = domain
81
100
  self.thread_data[str(idx)] = {
82
101
  "thread" : TaskThread(idx, len(multi_params), func, param, _callback),
83
102
  "result" : None
@@ -29,14 +29,6 @@ class Store(object):
29
29
  def write(self, data):
30
30
  with open(self.path, 'w') as f:
31
31
  json.dump(data, f)
32
-
33
- def token():
34
- sp = Store()
35
- read_data = sp.read()
36
- if "token" in read_data:
37
- return read_data["token"]
38
- else:
39
- return ""
40
32
 
41
33
  #============================== widget ================================
42
34
  def isCreateWidget():
@@ -61,7 +53,7 @@ def widgetMap():
61
53
  else:
62
54
  return {}
63
55
 
64
- def insertWidget(widget_id, path):
56
+ def insertWidget(widget_id, name, path):
65
57
  sp = Store()
66
58
  read_data = sp.read()
67
59
  if "widgets" not in read_data:
@@ -72,7 +64,8 @@ def insertWidget(widget_id, path):
72
64
  else:
73
65
  widgetsMap[widget_id] = {
74
66
  "isBlock": False,
75
- "path" : path
67
+ "path" : path,
68
+ "name" : name
76
69
  }
77
70
  for k in list(widgetsMap.keys()):
78
71
  if isinstance(widgetsMap[k], (dict)):
@@ -135,13 +128,17 @@ def writeDeviceInfo(data):
135
128
  read_data["deviceInfo"] = data
136
129
  sp.write(read_data)
137
130
 
131
+ cache_device_info = None
138
132
  def readDeviceInfo():
139
- sp = Store()
140
- read_data = sp.read()
141
- if "deviceInfo" in read_data:
142
- return read_data["deviceInfo"]
143
- else:
144
- return {}
133
+ global cache_device_info
134
+ if cache_device_info == None:
135
+ sp = Store()
136
+ read_data = sp.read()
137
+ if "deviceInfo" in read_data:
138
+ cache_device_info = read_data["deviceInfo"]
139
+ else:
140
+ cache_device_info = {}
141
+ return cache_device_info
145
142
 
146
143
  def is_multithread():
147
144
  return get_multithread() > 1
@@ -30,8 +30,6 @@ def runTask(it, timeout):
30
30
  msg = ""
31
31
  if len(result_obj["message"]) > 0:
32
32
  msg = str(result_obj["message"])
33
- if is_ok:
34
- checkResult(taskUUID, result_obj)
35
33
  taskUtils.taskPrint(taskUUID, f"{current_thread().name}=== task {taskUUID} is_ok={is_ok} ")
36
34
  taskUtils.saveCounter(taskUUID, (calendar.timegm(time.gmtime()) - start_time), is_ok)
37
35
  return is_ok, msg, json.dumps(result_obj["result"], separators=(',', ':'))
@@ -51,7 +49,15 @@ def cmdWithWidget(widget_id):
51
49
  return path
52
50
  return None
53
51
 
54
- def executeLocalPython(taskUUID, cmd, param, timeout):
52
+ def cmdWithWidgetName(name):
53
+ map = store.widgetMap()
54
+ for widget_id in map.keys():
55
+ if map[widget_id]["name"] == name and map[widget_id]["isBlock"] == False:
56
+ is_block = map[widget_id]["isBlock"]
57
+ return map[widget_id]["path"]
58
+ return None
59
+
60
+ def executeLocalPython(taskUUID, cmd, param, timeout=3600):
55
61
  inputArgs = os.path.join(os.path.dirname(os.path.abspath(__file__)), f"{taskUUID}.in")
56
62
  if os.path.exists(inputArgs):
57
63
  os.remove(inputArgs)
@@ -73,7 +79,7 @@ def executeLocalPython(taskUUID, cmd, param, timeout):
73
79
  process = None
74
80
  try:
75
81
  if timeout == 0:
76
- timeout = 60*60 #max 1 hour expire time
82
+ timeout = 60*30 #max half hour expire time
77
83
  process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
78
84
  timeout_killprocess(process, timeout)
79
85
  output, error = process.communicate()
@@ -127,58 +133,6 @@ def executeLocalPython(taskUUID, cmd, param, timeout):
127
133
  os.remove(outArgs)
128
134
  return executeSuccess, outData
129
135
 
130
- def _needChangeValue(taskUUID, data, type, key):
131
- if "type" not in data:
132
- taskUtils.taskPrint(taskUUID, "result is not avalid")
133
- return False
134
- if data["type"] != type:
135
- return False
136
- if "extension" not in data or key not in data["extension"] or len(data["extension"][key]) == 0:
137
- return True
138
- return False
139
-
140
- def checkResult(taskUUID, data):
141
- try:
142
- for it in data["result"]:
143
- if "extension" not in it:
144
- continue
145
- if _needChangeValue(taskUUID, it, "text", "cover_url"):
146
- it["extension"]["cover_url"] = ""
147
- if _needChangeValue(taskUUID, it, "audio", "cover_url"):
148
- it["extension"]["cover_url"] = ""
149
- if _needChangeValue(taskUUID, it, "image", "cover_url"):
150
- it["extension"]["cover_url"] = ""
151
- if _needChangeValue(taskUUID, it, "video", "cover_url"):
152
- it["extension"]["cover_url"] = ""
153
-
154
- if "cover_url" in it["extension"] and len(it["extension"]["cover_url"]) > 0:
155
- cover_url = str(it["extension"]["cover_url"]).replace('\\u0026', '&')
156
- parsed_url = urlparse(cover_url)
157
- params = parse_qs(parsed_url.query)
158
- #add width & height if need
159
- if "width" not in params and "height" not in params:
160
- w, h = utils.getOssImageSize(cover_url)
161
- if w > 0 and h > 0:
162
- params["width"] = w
163
- params["height"] = h
164
- it["extension"]["width"] = w
165
- it["extension"]["height"] = h
166
- #remove optional parameters
167
- for k in ["Expires","OSSAccessKeyId","Signature","security-token"]:
168
- params.pop(k, None)
169
- if "width" in it["extension"]:
170
- if isinstance(it["extension"]["width"], str):
171
- it["extension"]["width"] = int(it["extension"]["width"])
172
- if "height" in it["extension"]:
173
- if isinstance(it["extension"]["height"], str):
174
- it["extension"]["height"] = int(it["extension"]["height"])
175
- updated_query_string = urlencode(params, doseq=True)
176
- final_url = parsed_url._replace(query=updated_query_string).geturl()
177
- it["extension"]["cover_url"] = final_url
178
- except Exception as ex:
179
- taskUtils.taskPrint(taskUUID, f"result: {data} status is not valid, exception is {ex} , ignore")
180
- pass
181
-
182
136
  def updateProgress(data, progress=50, taskUUID=None):
183
137
  realTaskUUID = taskUUID
184
138
  if realTaskUUID == None or len(realTaskUUID) <= 0:
@@ -188,7 +142,8 @@ def updateProgress(data, progress=50, taskUUID=None):
188
142
  progress = 0
189
143
  if progress > 100:
190
144
  progress = 100
191
- return ryry_webapi.TaskUpdateProgress(realTaskUUID, progress, json.dumps(data))
145
+ if realTaskUUID.startswith("local_") == False:
146
+ return ryry_webapi.TaskUpdateProgress(realTaskUUID, progress, json.dumps(data))
192
147
 
193
148
  def timeout_killprocess(proc, timeout): # """超过指定的秒数后杀死进程"""
194
149
  import threading
@@ -19,6 +19,13 @@ def taskInfoWithFirstTask():
19
19
  if it not in ["last_task_pts"]:
20
20
  return it
21
21
  return None
22
+ def taskDomainWithUUID(taskUUID):
23
+ if os.path.exists(task_config_file):
24
+ with open(task_config_file, 'r') as f:
25
+ task_config = json.load(f)
26
+ if taskUUID in task_config:
27
+ return task_config[taskUUID]["domain"]
28
+ return ""
22
29
 
23
30
  WECHAT_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=f40c5fb0-2734-48b0-a2d0-0faedf7dd2e4"
24
31
  def uploadFile2Wechat(filepath):
@@ -0,0 +1,245 @@
1
+ from urllib.parse import *
2
+
3
+ def addtionExif(srcFile, taskUUID):
4
+ if taskUUID == None or len(taskUUID) == 0:
5
+ return
6
+ try:
7
+ from pathlib import Path
8
+ file_name = Path(srcFile).name
9
+ ext = file_name[file_name.index("."):].lower()
10
+ if ext in [".jpg", ".png", ".jpeg", ".bmp", ".webp", ".gif"]:
11
+ from PIL import Image
12
+ img = Image.open(srcFile)
13
+ exif_dict = {
14
+ "0th": { },
15
+ "Exif": { },
16
+ "1st": { },
17
+ "thumbnail": None,
18
+ "GPS": { }
19
+ }
20
+ import piexif
21
+ if taskUUID:
22
+ exif_dict["0th"] = {
23
+ piexif.ImageIFD.Software: f'make with ryry({taskUUID})'.encode(),
24
+ piexif.ImageIFD.Copyright: f'dalipen'.encode(),
25
+ }
26
+ exif_dict["Exif"] = {
27
+ piexif.ExifIFD.UserComment: f'make with ryry({taskUUID})'.encode(),
28
+ }
29
+ exif_dat = piexif.dump(exif_dict)
30
+ img.save(srcFile, "webp", quality=90, exif=exif_dat)
31
+ # elif ext in [".mp4",".mov",".avi",".wmv",".mpg",".mpeg",".rm",".ram",".flv",".swf",".ts"]:
32
+ # params = {}
33
+ # elif ext in [".mp3",".aac",".wav",".wma",".cda",".flac",".m4a",".mid",".mka",".mp2",".mpa",".mpc",".ape",".ofr",".ogg",".ra",".wv",".tta",".ac3",".dts"]:
34
+ # params = {}
35
+ # else:
36
+ # params = {}
37
+ except:
38
+ return
39
+
40
+ def transcode(srcFile):
41
+ try:
42
+ from pathlib import Path
43
+ from PIL import Image
44
+ file_name = Path(srcFile).name
45
+ ext = file_name[file_name.index("."):].lower()
46
+ if ext in [".jpg", ".png", ".jpeg", ".bmp"]:
47
+ image = Image.open(srcFile, "r")
48
+ format = image.format
49
+ if format.lower() != "webp":
50
+ fname = Path(srcFile).name
51
+ newFile = srcFile.replace(fname[fname.index("."):], ".webp")
52
+ image.save(newFile, "webp", quality=90)
53
+ image.close()
54
+ return True, newFile
55
+ except Exception as e:
56
+ pass
57
+ return False, srcFile
58
+
59
+ def additionalUrl(srcFile, ossUrl):
60
+ from pathlib import Path
61
+ from PIL import Image
62
+ try:
63
+ file_name = Path(srcFile).name
64
+ ext = file_name[file_name.index("."):].lower()
65
+ params = {}
66
+ if ext in [".jpg", ".png", ".jpeg", ".bmp", ".webp", ".gif"]:
67
+ img = Image.open(srcFile)
68
+ params["width"] = img.width
69
+ params["height"] = img.height
70
+ elif ext in [".mp4",".mov",".avi",".wmv",".mpg",".mpeg",".rm",".ram",".flv",".swf",".ts"]:
71
+ params = {}
72
+ elif ext in [".mp3",".aac",".wav",".wma",".cda",".flac",".m4a",".mid",".mka",".mp2",".mpa",".mpc",".ape",".ofr",".ogg",".ra",".wv",".tta",".ac3",".dts"]:
73
+ params = {}
74
+ else:
75
+ params = {}
76
+ parsed_url = urlparse(ossUrl)
77
+ updated_query_string = urlencode(params, doseq=True)
78
+ final_url = parsed_url._replace(query=updated_query_string).geturl()
79
+ return final_url
80
+ except:
81
+ return ossUrl
82
+
83
+ def upload(src, taskUUID, timeout=300, needTranscode=True):
84
+ import os
85
+ from pathlib import Path
86
+ from ryry import taskUtils
87
+ if os.path.exists(src) == False:
88
+ raise Exception(f"upload file not found")
89
+ if taskUUID==None or len(taskUUID) <= 0:
90
+ taskUUID = taskUtils.taskInfoWithFirstTask()
91
+ targetDomain = taskUtils.taskDomainWithUUID(taskUUID)
92
+
93
+ if needTranscode:
94
+ needDeleteSrc, newSrc = transcode(src)
95
+ else:
96
+ needDeleteSrc = False
97
+ newSrc = src
98
+ addtionExif(newSrc, taskUUID)
99
+ support_subdomain = getSubdomain(targetDomain)
100
+ if support_subdomain:
101
+ import uuid
102
+ file_name = Path(newSrc).name
103
+ ext = os.path.splitext(file_name)[-1][1:]
104
+ new_file_name = ''.join(str(uuid.uuid4()).split('-'))
105
+ ossurl = ftpUpload(newSrc, f"{new_file_name}.{ext}", support_subdomain)
106
+ else:
107
+ from ryry import ryry_webapi
108
+ file_name = Path(newSrc).name
109
+ ossurl = ryry_webapi.upload(newSrc, os.path.splitext(file_name)[-1][1:])
110
+
111
+ ossurl = additionalUrl(newSrc, ossurl)
112
+ if needDeleteSrc:
113
+ os.remove(newSrc)
114
+ return ossurl
115
+
116
+ def deepFtpUpload(file, new_file_name, ftp, writepath, readpath):
117
+ import ftplib, os
118
+ try:
119
+ ftp.cwd(writepath)
120
+ except ftplib.error_perm as e:
121
+ if e.args[0].startswith('550'):
122
+ ftp.mkd(writepath)
123
+ ftp.cwd(writepath)
124
+
125
+ with open(file, 'rb') as f:
126
+ ftp.storbinary(f'STOR {new_file_name}', f)
127
+ return f"{readpath}/{new_file_name}"
128
+
129
+ def ftpUpload(file, new_file_name, subdomain):
130
+ ip = subdomain["host"]
131
+ username = subdomain["username"]
132
+ password = subdomain["password"]
133
+ writepath = subdomain["writepath"]
134
+ readpath = subdomain["readpath"]
135
+ import ftplib
136
+ ftp = ftplib.FTP(ip)
137
+ ftp.login(username, password)
138
+
139
+ s = deepFtpUpload(file, new_file_name, ftp, writepath, readpath)
140
+ ftp.quit()
141
+ return s
142
+
143
+ def _can_connect_ftp(ip, username, password, writepath):
144
+ import ftplib
145
+ try:
146
+ ftp = ftplib.FTP(ip)
147
+ ftp.login(username, password)
148
+ try:
149
+ ftp.cwd(writepath)
150
+ except ftplib.error_perm as e:
151
+ if e.args[0].startswith('550'):
152
+ # 如果远程目录不存在,则创建它
153
+ ftp.mkd(writepath)
154
+ ftp.cwd(writepath)
155
+ ftp.quit()
156
+ return True
157
+ except Exception as e:
158
+ print(f"Failed to connect to FTP server {ip}:{writepath} {e}")
159
+ return False
160
+
161
+ SUBDOMAIN = {
162
+ "192.168.3.220": {
163
+ "host": "192.168.3.220",
164
+ "username" : "xinyu100",
165
+ "password" : "xinyu100.com",
166
+ "writepath" : "1TB01/data/cache/",
167
+ # "readpath" : "http://192.168.3.220/01/cache"
168
+ "readpath" : "ftp://192.168.3.220/1TB01/data/cache"
169
+ },
170
+ "192.168.50.113": {
171
+ "host" : "192.168.50.113",
172
+ "username" : "ftpuser",
173
+ "password" : "ftpuser",
174
+ "writepath" : "cache/",
175
+ "readpath" : "ftp://192.168.50.113/cache"
176
+ }
177
+ }
178
+ def getSubdomain(targetDomain):
179
+ if len(targetDomain) <= 0:
180
+ return None
181
+ for ip in SUBDOMAIN.keys():
182
+ if _can_connect_ftp(ip, SUBDOMAIN[ip]["username"], SUBDOMAIN[ip]["password"], SUBDOMAIN[ip]["writepath"]) and targetDomain == SUBDOMAIN[ip]["readpath"]:
183
+ return SUBDOMAIN[ip]
184
+ return None
185
+
186
+ def getFirstSupportSubdomain():
187
+ for ip in SUBDOMAIN.keys():
188
+ if _can_connect_ftp(ip, SUBDOMAIN[ip]["username"], SUBDOMAIN[ip]["password"], SUBDOMAIN[ip]["writepath"]):
189
+ return SUBDOMAIN[ip]
190
+ return None
191
+
192
+ def download(url, saveDir):
193
+ import uuid, requests, os
194
+ from urlparser import urlparser
195
+ from fake_useragent import UserAgent
196
+ if len(url) <= 0:
197
+ return None
198
+ try:
199
+ name = ''.join(str(uuid.uuid4()).split('-'))
200
+ ext = urlparser.urlparse(url).path[urlparser.urlparse(url).path.index("."):]
201
+ savePath = os.path.join(saveDir, f"{name}{ext}")
202
+
203
+ if url.startswith("ftp"):
204
+ import ftplib
205
+ parsed_url = urlparse(url)
206
+ host = parsed_url.hostname
207
+ if host in SUBDOMAIN:
208
+ ip = SUBDOMAIN[host]["host"]
209
+ username = SUBDOMAIN[host]["username"]
210
+ password = SUBDOMAIN[host]["password"]
211
+ writepath = SUBDOMAIN[host]["writepath"]
212
+ readpath = SUBDOMAIN[host]["readpath"]
213
+ ftp = ftplib.FTP(ip)
214
+ ftp.login(username, password)
215
+
216
+ remote_filepath = parsed_url.path[1:]
217
+ with open(savePath, 'wb') as f:
218
+ ftp.retrbinary(f'RETR {remote_filepath}', f.write)
219
+ ftp.quit()
220
+ else:
221
+ print(f"download fail: domain {host} not support")
222
+ elif url.startswith("http"):
223
+ requests.adapters.DEFAULT_RETRIES = 2
224
+ s = requests.session()
225
+ s.keep_alive = False
226
+ s.headers.update({'Connection':'close'})
227
+ ua = UserAgent()
228
+ file = s.get(url, verify=False, headers={'User-Agent': ua.random}, timeout=30)
229
+ if os.path.exists(savePath):
230
+ os.remove(savePath)
231
+ with open(savePath, "wb") as c:
232
+ c.write(file.content)
233
+ s.close()
234
+ if os.path.exists(savePath):
235
+ return savePath
236
+ else:
237
+ print(f"download success but file not found")
238
+ else:
239
+ print(f"url {url} not support")
240
+ except Exception as e:
241
+ print(f"download fail: {e}")
242
+ return None
243
+
244
+ # url = upload("D:\\0505.mp4", "111", 300)
245
+ # download(url, "D:\\")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ryry-cli
3
- Version: 2.27
3
+ Version: 2.29
4
4
  Summary: ryry tools
5
5
  Home-page: https://github.com/dalipenMedia
6
6
  Author: dalipen
@@ -3,7 +3,7 @@ import os
3
3
  import subprocess
4
4
  import datetime
5
5
 
6
- ryry_version = "2.27"
6
+ ryry_version = "2.29"
7
7
  ryry_build_number = int(ryry_version.replace(".",""))
8
8
  cur_dir = os.path.dirname(os.path.abspath(__file__))
9
9
  constanspy = os.path.join(cur_dir, "ryry", "constant.py")
@@ -1,5 +0,0 @@
1
- #!!!!! do not change this file !!!!!
2
- app_version="2.27"
3
- app_bulld_number=227
4
- app_bulld_anchor="Noh_2024-08-08 14:50:11.855975"
5
- app_name="ryry-cli"
@@ -1,106 +0,0 @@
1
- from urllib.parse import *
2
-
3
- def addtionExif(srcFile, taskUUID):
4
- if taskUUID == None or len(taskUUID) == 0:
5
- return
6
- try:
7
- from pathlib import Path
8
- file_name = Path(srcFile).name
9
- ext = file_name[file_name.index("."):].lower()
10
- if ext in [".jpg", ".png", ".jpeg", ".bmp", ".webp", ".gif"]:
11
- from PIL import Image
12
- img = Image.open(srcFile)
13
- exif_dict = {
14
- "0th": { },
15
- "Exif": { },
16
- "1st": { },
17
- "thumbnail": None,
18
- "GPS": { }
19
- }
20
- import piexif
21
- if taskUUID:
22
- exif_dict["0th"] = {
23
- piexif.ImageIFD.Software: f'make with ryry({taskUUID})'.encode(),
24
- piexif.ImageIFD.Copyright: f'dalipen'.encode(),
25
- }
26
- exif_dict["Exif"] = {
27
- piexif.ExifIFD.UserComment: f'make with ryry({taskUUID})'.encode(),
28
- }
29
- exif_dat = piexif.dump(exif_dict)
30
- img.save(srcFile, "webp", quality=90, exif=exif_dat)
31
- # elif ext in [".mp4",".mov",".avi",".wmv",".mpg",".mpeg",".rm",".ram",".flv",".swf",".ts"]:
32
- # params = {}
33
- # elif ext in [".mp3",".aac",".wav",".wma",".cda",".flac",".m4a",".mid",".mka",".mp2",".mpa",".mpc",".ape",".ofr",".ogg",".ra",".wv",".tta",".ac3",".dts"]:
34
- # params = {}
35
- # else:
36
- # params = {}
37
- except:
38
- return
39
-
40
- def transcode(srcFile):
41
- try:
42
- from pathlib import Path
43
- from PIL import Image
44
- file_name = Path(srcFile).name
45
- ext = file_name[file_name.index("."):].lower()
46
- if ext in [".jpg", ".png", ".jpeg", ".bmp"]:
47
- image = Image.open(srcFile, "r")
48
- format = image.format
49
- if format.lower() != "webp":
50
- fname = Path(srcFile).name
51
- newFile = srcFile.replace(fname[fname.index("."):], ".webp")
52
- image.save(newFile, "webp", quality=90)
53
- image.close()
54
- return True, newFile
55
- except Exception as e:
56
- pass
57
- return False, srcFile
58
-
59
- def additionalUrl(srcFile, ossUrl):
60
- from pathlib import Path
61
- from PIL import Image
62
- try:
63
- file_name = Path(srcFile).name
64
- ext = file_name[file_name.index("."):].lower()
65
- params = {}
66
- if ext in [".jpg", ".png", ".jpeg", ".bmp", ".webp", ".gif"]:
67
- img = Image.open(srcFile)
68
- params["width"] = img.width
69
- params["height"] = img.height
70
- elif ext in [".mp4",".mov",".avi",".wmv",".mpg",".mpeg",".rm",".ram",".flv",".swf",".ts"]:
71
- params = {}
72
- elif ext in [".mp3",".aac",".wav",".wma",".cda",".flac",".m4a",".mid",".mka",".mp2",".mpa",".mpc",".ape",".ofr",".ogg",".ra",".wv",".tta",".ac3",".dts"]:
73
- params = {}
74
- else:
75
- params = {}
76
- parsed_url = urlparse(ossUrl)
77
- updated_query_string = urlencode(params, doseq=True)
78
- final_url = parsed_url._replace(query=updated_query_string).geturl()
79
- return final_url
80
- except:
81
- return ossUrl
82
-
83
- def upload(src, taskUUID, timeout=300, needTranscode=True):
84
- import os
85
- from ryry import store
86
- from pathlib import Path
87
- from ryry import taskUtils
88
- from ryry import ryry_webapi
89
- import requests
90
- if os.path.exists(src) == False:
91
- raise Exception(f"upload file not found")
92
- if taskUUID==None or len(taskUUID) <= 0:
93
- taskUUID = taskUtils.taskInfoWithFirstTask()
94
-
95
- if needTranscode:
96
- needDeleteSrc, newSrc = transcode(src)
97
- else:
98
- needDeleteSrc = False
99
- newSrc = src
100
- addtionExif(newSrc, taskUUID)
101
- file_name = Path(newSrc).name
102
- ossurl = ryry_webapi.upload(newSrc, os.path.splitext(file_name)[-1][1:])
103
- ossurl = additionalUrl(newSrc, ossurl)
104
- if needDeleteSrc:
105
- os.remove(newSrc)
106
- return ossurl
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes