pixab 1.7.1 → 1.7.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b89f6322709aca8a7ed33e7e3352cf47ef06c8cd3af35867fb60681b3d46155
4
- data.tar.gz: 7bc4c348e66324c3cbdc138cbd02f5db37187b6d9f11a594c07b0436e2cb675d
3
+ metadata.gz: 84d54a1ab3a12281357538f78851d2b729803cf110e51570a17f2ee0e1c480de
4
+ data.tar.gz: 2223cb8f2541517bcde9f0490cc064061043ddfc964d42d93d4ea953eaf2e417
5
5
  SHA512:
6
- metadata.gz: fc02ace8ad4dbd1fb1a73c2441710df42b10b69c40e9cd2b4e4decee6afc74829607738078b2fad815354cf2c9d99e72c9f9e116298c20e2b334931601c1e432
7
- data.tar.gz: 7f992b1cb7bdcceed42e8aaab779ecb2073e9524d5032b436eda6defe1b2ac5938c9b81ee0ddad0c024649d45b51501ff1afe65407af0d668c1d6242c75431e7
6
+ metadata.gz: feb82c51f413c5a117ef86728574aa5498f9d5a13181eef65c555fc10b525af202f94dddbbf13f08b5b56c105dbb9fa0eb7e2fa376a1d95b8706b36ee0767c62
7
+ data.tar.gz: 43ad564e1d758c1ed30bc929207af08c25e5426b33f8a59f80b731d8d055881f93afb37a0017428759ae511a37b00feaf140924c358594e15b6a3ca339b85390
@@ -2,8 +2,7 @@ require 'net/http'
2
2
  require 'uri'
3
3
  require 'zip'
4
4
  require 'colored2'
5
- require 'rexml/document'
6
- include REXML
5
+ require 'nokogiri'
7
6
 
8
7
  module Pixab
9
8
 
@@ -15,6 +14,7 @@ module Pixab
15
14
  Localization_FILE_NAME = 'Localization.zip'
16
15
 
17
16
  Project_AirBrush = '6cd2db15-6325-43ae-9087-f78aca9bec9a'
17
+ Project_AirBrushVideo = '16cbeffd-bb6e-46e8-a32e-9c79d23a796f'
18
18
 
19
19
  attr_accessor :projects, :tags, :platform, :collections
20
20
 
@@ -35,6 +35,14 @@ module Pixab
35
35
  @platform = 'iOS'
36
36
  @tags = 'iOS'
37
37
  @collections = 'AirBrush'
38
+ when '--abv-iOS'
39
+ @projects = Project_AirBrushVideo
40
+ @platform = 'iOS'
41
+ @tags = 'iOS'
42
+ when '--abv-android'
43
+ @projects = Project_AirBrushVideo
44
+ @platform = 'android'
45
+ @tags = 'android'
38
46
  end
39
47
  end
40
48
 
@@ -84,17 +92,7 @@ module Pixab
84
92
  end
85
93
 
86
94
  # 第二步:循环尝试下载ZIP文件
87
- def download_zip_file_with_retry(download_url, export_id, max_retries=30)
88
- # 加载动画字符
89
- spinner = Enumerator.new do |e|
90
- loop do
91
- e.yield '|'
92
- e.yield '/'
93
- e.yield '-'
94
- e.yield '\\'
95
- end
96
- end
97
-
95
+ def download_zip_file_with_retry(download_url, export_id, max_retries=60)
98
96
  retries = 0
99
97
  while retries < max_retries
100
98
  uri = URI("#{download_url}/#{export_id}")
@@ -109,13 +107,11 @@ module Pixab
109
107
  File.open(Localization_FILE_NAME, "wb") { |file| file.write(response.body) }
110
108
  return true
111
109
  else
112
- # 等待1秒后重试
113
- # 打印动画字符
114
- print "\r#{spinner.next}"
115
- sleep 0.5
116
- print "\r#{spinner.next}"
117
- sleep 0.5
118
110
  retries += 1
111
+ dots = '.' * retries
112
+ print "\r#{dots}"
113
+ # 等待1秒后重试
114
+ sleep 1
119
115
  end
120
116
  end
121
117
 
@@ -145,10 +141,12 @@ module Pixab
145
141
  f_path = extract_localization_file_path(f.name)
146
142
  FileUtils.mkdir_p(File.dirname(f_path))
147
143
  content = f.get_input_stream.read
148
- localization_content = content.gsub(/=\s*".*";/) do |match|
149
- match.gsub('%s', '%@')
144
+ if projects == Project_AirBrush
145
+ content = content.gsub(/=\s*".*";/) do |match|
146
+ match.gsub('%s', '%@')
147
+ end
150
148
  end
151
- File.write(f_path, localization_content)
149
+ File.write(f_path, content)
152
150
  end
153
151
  end
154
152
 
@@ -160,16 +158,13 @@ module Pixab
160
158
  f_path = extract_localization_file_path(f.name)
161
159
  FileUtils.mkdir_p(File.dirname(f_path))
162
160
  content = f.get_input_stream.read
163
- document = Document.new(content)
164
- # 遍历所有文本节点
165
- XPath.each(document, '//text()') do |text_node|
166
- # 对文本中的单双引号进行转义处理
167
- text_node.value = text_node.value.gsub(/['"]/, '\0')
168
- end
169
- # 将修改后的XML内容写入新文件
170
- File.open(f_path, 'w') do |file|
171
- document.write(file)
161
+ document = Nokogiri::XML(content)
162
+ document.traverse do |node|
163
+ if node.text?
164
+ node.content = node.content.gsub(/['"]/, '\\\\\0')
165
+ end
172
166
  end
167
+ File.write(f_path, document.to_xml)
173
168
  end
174
169
  end
175
170
 
@@ -187,7 +182,11 @@ module Pixab
187
182
  template = nil
188
183
  if platform == 'android'
189
184
  format = 'android-xml'
190
- template = '{LOCALE:ANDROID}/strings_ph.xml'
185
+ if projects == Project_AirBrush
186
+ template = '{LOCALE:ANDROID}/strings_ph.xml'
187
+ else
188
+ template = '{LOCALE:ANDROID}/strings.xml'
189
+ end
191
190
  else
192
191
  format = 'ios-strings'
193
192
  template = '{LOCALE:IOS}.lproj/Localizable.strings'
@@ -204,39 +203,75 @@ module Pixab
204
203
  end
205
204
 
206
205
  def extract_localization_file_path(zip_file_path)
207
- if platform.nil? || platform != 'android'
208
- return zip_file_path
209
- end
206
+ case projects
207
+ when Project_AirBrush
208
+ if platform.nil? || platform != 'android'
209
+ return zip_file_path
210
+ end
210
211
 
211
-
212
- path = File.dirname(zip_file_path)
213
- localization = ''
214
- case path
215
- when 'en'
212
+ path = File.dirname(zip_file_path)
216
213
  localization = ''
217
- when 'fr'
218
- localization = '-fr-rFR'
219
- when 'ru'
220
- localization = '-ru-rRU'
221
- when 'zh-rHans'
222
- localization = '-zh-rCN'
223
- when 'tr'
224
- localization = '-tr-rTR'
225
- when 'pt-rBR'
226
- localization = '-pt'
227
- else
228
- localization = "-#{path}"
214
+ case path
215
+ when 'en'
216
+ localization = ''
217
+ when 'fr'
218
+ localization = '-fr-rFR'
219
+ when 'ru'
220
+ localization = '-ru-rRU'
221
+ when 'zh-rHans'
222
+ localization = '-zh-rCN'
223
+ when 'tr'
224
+ localization = '-tr-rTR'
225
+ when 'pt-rBR'
226
+ localization = '-pt'
227
+ else
228
+ localization = "-#{path}"
229
+ end
230
+ return "values#{localization}/#{File.basename(zip_file_path)}"
231
+
232
+ when Project_AirBrushVideo
233
+ if platform.nil?
234
+ return zip_file_path
235
+ end
236
+
237
+ case platform
238
+ when 'android'
239
+ path = File.dirname(zip_file_path)
240
+ localization = ''
241
+ case path
242
+ when 'en'
243
+ localization = ''
244
+ when 'zh-rHans'
245
+ localization = '-zh-rCN'
246
+ when 'zh-rHant'
247
+ localization = '-zh-rHK'
248
+ else
249
+ localization = "-#{path}"
250
+ end
251
+ return "values#{localization}/#{File.basename(zip_file_path)}"
252
+ when 'iOS'
253
+ path = File.dirname(zip_file_path)
254
+ localization = zip_file_path
255
+ case path
256
+ when 'pt-PT.lproj'
257
+ localization = File.join('pt.lproj', File.basename(zip_file_path))
258
+ end
259
+ return localization
260
+ end
229
261
  end
230
- return "values#{localization}/#{File.basename(zip_file_path)}"
262
+
231
263
  end
232
264
 
233
265
  def is_ignored_file_path(file_path)
234
- if platform != 'android'
235
- return false
266
+ case projects
267
+ when Project_AirBrush
268
+ return false unless platform == 'android'
269
+
270
+ path = File.dirname(file_path)
271
+ return path == 'zh-rHant' ? true : false
236
272
  end
237
273
 
238
- path = File.dirname(file_path)
239
- return path == 'zh-rHant' ? true : false
274
+ return false
240
275
  end
241
276
 
242
277
  end
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "1.7.1"
4
+ VERSION = "1.7.3"
5
5
  end
data/pixab.gemspec CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  # Uncomment to register a new dependency of your gem
36
36
  spec.add_dependency "colored2"
37
37
  spec.add_dependency 'rubyzip'
38
+ spec.add_dependency 'nokogiri'
38
39
 
39
40
  # For more information and examples about making a new gem, check out our
40
41
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-06 00:00:00.000000000 Z
11
+ date: 2023-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Write a longer description or delete this line.
42
56
  email:
43
57
  - lzr3@us.meitu.com