summaryrefslogtreecommitdiff
path: root/geturl.rb
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2024-10-08 21:28:46 +0900
committerhaturatu <taro@eyes4you.org>2024-10-08 21:28:46 +0900
commite6d71fbf65df8a54e92649544c9acc71c58e182e (patch)
tree99a61557b537181725391247a917a9fb3db55824 /geturl.rb
parent6f9466f1e2fd70eb56446de53cfa2816ac0a0dbc (diff)
fix spe char & add error hundlling
Diffstat (limited to 'geturl.rb')
-rwxr-xr-xgeturl.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/geturl.rb b/geturl.rb
index 166956a..9a2ae88 100755
--- a/geturl.rb
+++ b/geturl.rb
@@ -17,7 +17,7 @@ def is_garbled?(text)
end
def clean_title(title)
- title = title.chars.reject { |ch| UnicodeUtils.general_category(ch).start_with?('C') }.join
+ title = title.chars.reject { |ch| UnicodeUtils.general_category(ch).start_with?('C') && !['(', ')', '[', ']', '{', '}', '【', '】', '「', '」', '(' ,')' ].include?(ch) }.join
title = UnicodeUtils.nfkc(title)
title = title.chars.select(&:valid_encoding?).join
title.strip
@@ -76,12 +76,28 @@ def process_url(url)
end
def process_urls(file_path)
+ unless File.exist?(file_path)
+ puts "エラー: 指定されたファイル '#{file_path}' が見つかりません。"
+ exit(1)
+ end
+
urls = File.readlines(file_path).map(&:strip).reject(&:empty?)
+ if urls.empty?
+ puts "警告: ファイル '#{file_path}' にURLが含まれていません。"
+ exit(0)
+ end
+
Parallel.each(urls, in_threads: CONCURRENCY) do |url|
process_url(url)
sleep(rand(1.0..3.0))
end
end
-process_urls(FILE_PATH)
+begin
+ process_urls(FILE_PATH)
+rescue => e
+ puts "エラーが発生しました: #{e.message}"
+ puts e.backtrace
+ exit(1)
+end