ehbrs_ruby_utils 0.33.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb +2 -2
  3. data/lib/ehbrs_ruby_utils/bga/parsers/table/options.rb +3 -3
  4. data/lib/ehbrs_ruby_utils/bga/session/skip_trophies.rb +1 -1
  5. data/lib/ehbrs_ruby_utils/bga/session/user.rb +1 -3
  6. data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base.rb +1 -1
  7. data/lib/ehbrs_ruby_utils/circular_list_spreader/base_level.rb +1 -1
  8. data/lib/ehbrs_ruby_utils/circular_list_spreader/group_level.rb +1 -1
  9. data/lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb +1 -1
  10. data/lib/ehbrs_ruby_utils/fs/selected/build.rb +1 -1
  11. data/lib/ehbrs_ruby_utils/fs/to_file_format.rb +83 -0
  12. data/lib/ehbrs_ruby_utils/fs/to_utf8_unix.rb +60 -0
  13. data/lib/ehbrs_ruby_utils/fs/to_windows_pt_br.rb +59 -0
  14. data/lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb +1 -1
  15. data/lib/ehbrs_ruby_utils/patches/object/template.rb +2 -2
  16. data/lib/ehbrs_ruby_utils/patches/object.rb +1 -1
  17. data/lib/ehbrs_ruby_utils/patches.rb +1 -1
  18. data/lib/ehbrs_ruby_utils/version.rb +1 -1
  19. data/lib/ehbrs_ruby_utils/vg/wii/wit/image_format.rb +2 -2
  20. data/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump.rb +3 -3
  21. data/lib/ehbrs_ruby_utils/videos/container.rb +1 -1
  22. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/subtitles_provider.rb +51 -0
  23. data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/title.rb +5 -0
  24. data/lib/ehbrs_ruby_utils/videos/quality.rb +1 -3
  25. data/lib/ehbrs_ruby_utils/videos/resolution.rb +2 -2
  26. data/lib/ehbrs_ruby_utils/videos/series/rename/file/basename_parser.rb +2 -2
  27. data/lib/ehbrs_ruby_utils/videos/series/rename/file.rb +2 -2
  28. data/lib/ehbrs_ruby_utils/videos/series/rename/line_result.rb +2 -2
  29. data/lib/ehbrs_ruby_utils/videos/series/rename/line_result_group.rb +1 -0
  30. data/lib/ehbrs_ruby_utils/videos/series/rename/season_group.rb +1 -0
  31. data/lib/ehbrs_ruby_utils/videos/stream.rb +1 -1
  32. data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize/content_sanitizer.rb +87 -0
  33. data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize/with_pattern_matcher.rb +20 -0
  34. data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize/with_term_matcher.rb +20 -0
  35. data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize.rb +42 -0
  36. data/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +1 -1
  37. metadata +42 -160
  38. data/.rspec +0 -1
  39. data/.rubocop.yml +0 -45
  40. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec.rb +0 -7
  41. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.source.html +0 -8657
  42. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.target.yaml +0 -41
  43. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.source.html +0 -8650
  44. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.target.yaml +0 -41
  45. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.source.html +0 -8657
  46. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.target.yaml +0 -5
  47. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.source.html +0 -8657
  48. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.target.yaml +0 -13
  49. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.source.html +0 -8657
  50. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.target.yaml +0 -29
  51. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.source.html +0 -8657
  52. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.target.yaml +0 -7
  53. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93248308_2023-06-12.source.html +0 -8657
  54. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93248308_2023-06-12.target.yaml +0 -1
  55. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec.rb +0 -7
  56. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.source.html +0 -1082
  57. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.target.yaml +0 -151
  58. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.source.html +0 -1083
  59. data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.target.yaml +0 -1127
  60. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec.rb +0 -7
  61. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.source.html +0 -1491
  62. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.target.yaml +0 -40
  63. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.source.html +0 -1965
  64. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.target.yaml +0 -46
  65. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.source.html +0 -1497
  66. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.target.yaml +0 -56
  67. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.source.html +0 -1500
  68. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.target.yaml +0 -66
  69. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.source.html +0 -1497
  70. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml +0 -58
  71. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.source.html +0 -1441
  72. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml +0 -30
  73. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.source.html +0 -1521
  74. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml +0 -59
  75. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_383405743.source.html +0 -1480
  76. data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_383405743.target.yaml +0 -32
  77. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec.rb +0 -68
  78. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.source.yaml +0 -124
  79. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.target.yaml +0 -70
  80. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.source.yaml +0 -7
  81. data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.target.yaml +0 -5
  82. data/spec/lib/ehbrs_ruby_utils/cooking_book/recipe/measure_spec.rb +0 -21
  83. data/spec/lib/ehbrs_ruby_utils/vg/wii/game_file_spec.rb +0 -21
  84. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec.rb +0 -11
  85. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_R92P01_wia.source.witdump +0 -27
  86. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_R92P01_wia.target.yaml +0 -22
  87. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_pal_iso.source.witdump +0 -28
  88. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_pal_iso.target.yaml +0 -21
  89. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/resident_evil_code_veronica_disc2_iso.source.witdump +0 -16
  90. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/resident_evil_code_veronica_disc2_iso.target.yaml +0 -19
  91. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/super_mario_galaxy_wbfs.source.witdump +0 -28
  92. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/super_mario_galaxy_wbfs.target.yaml +0 -23
  93. data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/path_spec.rb +0 -33
  94. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb +0 -7
  95. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html +0 -993
  96. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml +0 -5
  97. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html +0 -478
  98. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml +0 -43
  99. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb +0 -7
  100. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html +0 -763
  101. data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml +0 -22
  102. data/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +0 -18
  103. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec.rb +0 -13
  104. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.source.yaml +0 -28
  105. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.target.yaml +0 -8
  106. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.source.yaml +0 -49
  107. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.target.yaml +0 -8
  108. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.source.yaml +0 -43
  109. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.target.yaml +0 -8
  110. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.source.yaml +0 -59
  111. data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.target.yaml +0 -8
  112. data/spec/rubocop_check_spec.rb +0 -3
  113. data/spec/spec_helper.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05a500e93163dbff946466f1e0500eb191734c6dab6f7ee221df9c6f7b1d652a
4
- data.tar.gz: 551a4cd6c774196401f2c87a7b176c7e8b3ca3c94ae9b030ab16dc73a14f3555
3
+ metadata.gz: a51803bc2fc98c7439c7e0e8808e00866d7130f898e1f9738c1c9f1483b326aa
4
+ data.tar.gz: a4146dc9718ed5356187a725e1537895c679301ca63d67619f9f3edaa8374223
5
5
  SHA512:
6
- metadata.gz: 652775ab4e50bdfc1066d11cab55e66fa9a5f98c670ec12cf0e7f2652b9668d5ce2c98a8a2e58faf20d433a8342a824296da1e05a34e99a516f787227ae2431b
7
- data.tar.gz: 4be18d9b6f3641869a415e957a7ead726bec9d846c36d1ec893047b1be04a24217603388fda5c900910eb3aeba7ff86e6cd40ecae4547a01ad3ce481e286208d
6
+ metadata.gz: 91760450578b621f60892d253f686ee1c5f8662c70a0177bace04b9f3cead3b4148999f0c8b7492f0de473be71e15e52e79d58957fd7fbcc04f59c939105e7ae
7
+ data.tar.gz: 2b9b4af1d0b6a47e99930adc678487721da804b6978d23700d5c33f2cdb04bf5757401c598c4ddc06212309c2bb3ac68bded943aaf4365a618bc169e4217ddac
@@ -8,7 +8,7 @@ module EhbrsRubyUtils
8
8
  module Parsers
9
9
  class GameInProgress < ::Aranha::Parsers::Html::ItemList
10
10
  ITEMS_XPATH = '//*[@id = "gametables_inprogress_all"]' \
11
- '//*[starts-with(@id, "gametableblock_")]'
11
+ '//*[starts-with(@id, "gametableblock_")]'
12
12
  STATUS_CLASS_PATTERN = /\Agametable_status_(.+)\z/.freeze
13
13
  STATUS_CLASS_PARSER = STATUS_CLASS_PATTERN.to_parser { |m| m[1] }
14
14
 
@@ -29,7 +29,7 @@ module EhbrsRubyUtils
29
29
  private
30
30
 
31
31
  def process_status(status)
32
- status.split(' ').lazy.map { |s| STATUS_CLASS_PARSER.parse(s.strip) }.find(&:present?) ||
32
+ status.split.lazy.map { |s| STATUS_CLASS_PARSER.parse(s.strip) }.find(&:present?) ||
33
33
  raise("No status class found in \"#{status}\"")
34
34
  end
35
35
  end
@@ -9,12 +9,12 @@ module EhbrsRubyUtils
9
9
  module Parsers
10
10
  class Table < ::Aranha::Parsers::Html::Item
11
11
  class Options < ::Aranha::Parsers::Html::ItemList
12
- ITEMS_XPATH = '//div[starts-with(@id, "gameoption_")' \
13
- ' and not(contains(@style, "none"))]'
12
+ ITEMS_XPATH = '//div[starts-with(@id, "gameoption_") ' \
13
+ 'and not(contains(@style, "none"))]'
14
14
 
15
15
  field :label, :string, './div[@class = "row-label"]/text()'
16
16
  field :value, :string, './div[@class = "row-value"]' \
17
- "//*[#{xpath_ends_with('@id', "'_displayed_value'")}]/text()"
17
+ "//*[#{xpath_ends_with('@id', "'_displayed_value'")}]/text()"
18
18
  field :description, :string, './div[@class = "gameoption_description"]/text()'
19
19
 
20
20
  def items_xpath
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
7
7
  class Session < ::SimpleDelegator
8
8
  module SkipTrophies
9
9
  TROPHY_SKIP_BUTTON_XPATH = '//*[@id = "splashedNotifications_overlay"]' \
10
- '//*[starts-with(@id, "continue_btn_")]'
10
+ '//*[starts-with(@id, "continue_btn_")]'
11
11
  TROPHY_SKIP_TIMEOUT = 5
12
12
 
13
13
  # @param &block [Proc]
@@ -18,9 +18,7 @@ module EhbrsRubyUtils
18
18
  end
19
19
 
20
20
  def on_logged(&block)
21
- unless logged?
22
- raise "Login failed for BoardGameUser user \"#{username}\"" unless login
23
- end
21
+ raise "Login failed for BoardGameUser user \"#{username}\"" if !logged? && !login
24
22
 
25
23
  block.call
26
24
  end
@@ -49,7 +49,7 @@ module EhbrsRubyUtils
49
49
  end
50
50
 
51
51
  def title_to_s(title)
52
- '*' + [title_icon, title, title_icon].join(' ') + "*\n\n"
52
+ "*#{[title_icon, title, title_icon].join(' ')}*\n\n"
53
53
  end
54
54
 
55
55
  def players
@@ -26,7 +26,7 @@ module EhbrsRubyUtils
26
26
  end
27
27
 
28
28
  def remaining_fs
29
- ((remaining_f * 1000).round / 10.0).to_s + '%'
29
+ "#{(remaining_f * 1000).round / 10.0}%"
30
30
  end
31
31
 
32
32
  def debugs
@@ -28,7 +28,7 @@ module EhbrsRubyUtils
28
28
 
29
29
  def pop_all
30
30
  r = []
31
- while remaining?; r << pop; end
31
+ r << pop while remaining?
32
32
  r
33
33
  end
34
34
 
@@ -11,7 +11,7 @@ module EhbrsRubyUtils
11
11
  FLOAT_PATTERN = /\d+(?:\.\d+)?/.freeze
12
12
  FRACTION_PATTERN = %r{(#{FLOAT_PATTERN})(?:\s*/\s*(#{FLOAT_PATTERN}))?}.freeze
13
13
  QUANTITY_UNIT_PATTERN = /\A#{FRACTION_PATTERN}(?:\s*(\S+))?\z/.freeze
14
- VARIABLE_PATTERN = /\A\~\z/.freeze
14
+ VARIABLE_PATTERN = /\A~\z/.freeze
15
15
  VARIABLE_TEXT = 'a gosto'
16
16
 
17
17
  class << self
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
7
7
  module Fs
8
8
  class Selected
9
9
  class Build
10
- DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |path| path.basename.to_path }
10
+ DEFAULT_TARGET_BASENAME_PROC = proc { |path| path.basename.to_path }
11
11
 
12
12
  attr_reader :selected, :target_dir, :target_basename_proc
13
13
 
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/patches'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module Fs
8
+ class ToFileFormat
9
+ enable_abstract_methods
10
+ enable_simple_cache
11
+ abstract_methods :convert, :convert?, :target_encoding
12
+
13
+ common_constructor(:file) do
14
+ self.file = file.to_pathname
15
+ end
16
+
17
+ class << self
18
+ def convert_self(file)
19
+ new(file).run
20
+ end
21
+
22
+ def convert_to_file(source, target)
23
+ ::FileUtils.cp(source, target)
24
+ convert_self(target)
25
+ end
26
+
27
+ def convert_to_string(source)
28
+ ::EacRubyUtils::Fs::Temp.on_file do |target|
29
+ convert_to_file(source, target)
30
+ target.open('rb', &:read)
31
+ end
32
+ end
33
+ end
34
+
35
+ def run
36
+ return false unless convert?
37
+
38
+ convert
39
+ true
40
+ end
41
+
42
+ protected
43
+
44
+ def convert_to_target_encoding
45
+ ::EacRubyUtils::Fs::Temp.on_file do |temp|
46
+ ::EacRubyUtils::Envs.local.command(
47
+ 'iconv', '-c', '-f', source_encoding, '-t', target_encoding, '-o', temp, file
48
+ ).execute!
49
+ ::FileUtils.mv(temp, file)
50
+ end
51
+ reset_cache
52
+ end
53
+
54
+ def crlf?
55
+ file_type?('CRLF')
56
+ end
57
+
58
+ def file_info_uncached
59
+ ::EacFs::FileInfo.new(file)
60
+ end
61
+
62
+ def file_type?(*include)
63
+ return false unless ::File.file?(file)
64
+
65
+ include.any? { |i| file_type.include?(i) }
66
+ end
67
+
68
+ def file_type_uncached
69
+ ::EacRubyUtils::Envs.local.command('file', '-b', file).execute!.strip
70
+ end
71
+
72
+ def source_encoding
73
+ r = file.info.charset
74
+ r = 'iso-8859-15' if r == 'unknown-8bit'
75
+ r
76
+ end
77
+
78
+ def text?
79
+ file.info.content_type.type == 'text'
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/fs/to_file_format'
4
+
5
+ module EhbrsRubyUtils
6
+ module Fs
7
+ class ToUtf8Unix < ::EhbrsRubyUtils::Fs::ToFileFormat
8
+ UTF8_ENCODINGS = %w[us-ascii utf-8].freeze
9
+ ISO885915_ENCODINGS = %w[iso-8859-1].freeze
10
+
11
+ protected
12
+
13
+ def convert
14
+ check_utf8
15
+ check_crlf
16
+ end
17
+
18
+ def check_utf8
19
+ return if utf8?
20
+
21
+ convert_to_target_encoding
22
+ reset_cache
23
+ end
24
+
25
+ def file_attr(option)
26
+ ::EacRubyUtils::Envs.local.command('file', '--brief', option, file).execute!
27
+ end
28
+
29
+ def mime_encoding_uncached
30
+ file_attr('--mime-encoding')
31
+ end
32
+
33
+ def check_crlf
34
+ return unless crlf?
35
+
36
+ convert_crlf
37
+ end
38
+
39
+ def convert_crlf
40
+ ::EacRubyUtils::Envs.local.command('dos2unix', file).execute!
41
+ end
42
+
43
+ def convert?
44
+ text? && (!utf8? || crlf?)
45
+ end
46
+
47
+ def utf8?
48
+ UTF8_ENCODINGS.include?(mime_encoding)
49
+ end
50
+
51
+ def iso885915?
52
+ ISO885915_ENCODINGS.include?(mime_encoding)
53
+ end
54
+
55
+ def target_encoding
56
+ 'utf-8'
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/fs/to_file_format'
5
+
6
+ module EhbrsRubyUtils
7
+ module Fs
8
+ class ToWindowsPtBr < ::EhbrsRubyUtils::Fs::ToFileFormat
9
+ TARGET_CHARSETS = %w[ISO-8859].freeze
10
+ ICONV_TO = 'ISO-8859-1'
11
+
12
+ protected
13
+
14
+ def convert
15
+ check_bom
16
+ check_target_charset
17
+ check_crlf
18
+ end
19
+
20
+ private
21
+
22
+ def check_bom
23
+ ::EacRubyUtils::Envs.local.command(
24
+ 'sed', '-i', '1s/^\\xEF\\xBB\\xBF//', file
25
+ ).system!
26
+ reset_cache
27
+ end
28
+
29
+ def check_target_charset
30
+ return if target_charset?
31
+
32
+ convert_to_target_encoding
33
+ end
34
+
35
+ def check_crlf
36
+ return if crlf?
37
+
38
+ convert_crlf
39
+ end
40
+
41
+ def convert_crlf
42
+ ::EacRubyUtils::Envs.local.command('unix2dos', file).execute!
43
+ reset_cache
44
+ end
45
+
46
+ def convert?
47
+ text? && (!target_charset? || !crlf?)
48
+ end
49
+
50
+ def target_charset?
51
+ file_type?(*TARGET_CHARSETS)
52
+ end
53
+
54
+ def target_encoding
55
+ ICONV_TO
56
+ end
57
+ end
58
+ end
59
+ end
@@ -31,7 +31,7 @@ module EhbrsRubyUtils
31
31
  end
32
32
 
33
33
  def link_to_header
34
- "<a href=\"\##{header_id}\" id=\"#{index_id}\">#{header_title}</a>"
34
+ "<a href=\"##{header_id}\" id=\"#{index_id}\">#{header_title}</a>"
35
35
  end
36
36
 
37
37
  def index_id
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'eac_templates/patches/object/template'
4
4
 
5
- ::EacTemplates::Searcher.default.included_paths <<
6
- ::File.expand_path('../../../../template', __dir__)
5
+ EacTemplates::Searcher.default.included_paths <<
6
+ File.expand_path('../../../../template', __dir__)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub __FILE__
4
+ EacRubyUtils.require_sub __FILE__
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/require_sub'
4
- ::EacRubyUtils.require_sub __FILE__
4
+ EacRubyUtils.require_sub __FILE__
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.33.0'
4
+ VERSION = '0.36.0'
5
5
  end
@@ -16,8 +16,8 @@ module EhbrsRubyUtils
16
16
 
17
17
  def by_name(name)
18
18
  all.find { |i| i.name.downcase == name.to_s.downcase } ||
19
- raise(::ArgumentError, "Image not found with name \"#{name.to_s.downcase}\"" \
20
- " (Available: #{all.map(&:name).join(', ')})")
19
+ raise(::ArgumentError, "Image not found with name \"#{name.to_s.downcase}\" " \
20
+ "(Available: #{all.map(&:name).join(', ')})")
21
21
  end
22
22
 
23
23
  private
@@ -54,10 +54,10 @@ module EhbrsRubyUtils
54
54
  end
55
55
 
56
56
  def parse_disc_part_ids(value)
57
- value.split(',').map(&:strip).map do |v|
58
- r = v.split('=')
57
+ value.split(',').to_h do |v|
58
+ r = v.strip.split('=')
59
59
  [r[0].strip, r[1].strip]
60
- end.to_h
60
+ end
61
61
  end
62
62
  end
63
63
  end
@@ -43,7 +43,7 @@ module EhbrsRubyUtils
43
43
  def song_metadata_uncached
44
44
  ::UltimateLyrics::SongMetadata.new(
45
45
  ::UltimateLyrics::SongMetadata::Field.lists.sources.values
46
- .map { |source| [source, tag.send(source)] }.to_h
46
+ .index_with { |source| tag.send(source) }
47
47
  )
48
48
  end
49
49
 
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/default_processor'
4
+ require 'ehbrs_ruby_utils/videos/opensubtitles/processors/episode'
5
+ require 'ehbrs_ruby_utils/videos/opensubtitles/processors/title'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module EhbrsRubyUtils
9
+ module Videos
10
+ module Opensubtitles
11
+ module Processors
12
+ class SubtitlesProvider < ::Aranha::DefaultProcessor
13
+ enable_simple_cache
14
+
15
+ delegate :perform, :subtitles, to: :sub_processor
16
+
17
+ # @return [Boolean]
18
+ def episode?
19
+ title_parser.data[:episodes].if_present(true, &:empty?)
20
+ end
21
+
22
+ private
23
+
24
+ # @return [Class]
25
+ def sub_processor_class
26
+ if episode?
27
+ ::EhbrsRubyUtils::Videos::Opensubtitles::Processors::Episode
28
+ else
29
+ ::EhbrsRubyUtils::Videos::Opensubtitles::Processors::Title
30
+ end
31
+ end
32
+
33
+ # @return [EhbrsRubyUtils::Videos::Opensubtitles::Parsers::Episode]
34
+ def episode_parser
35
+ ::EhbrsRubyUtils::Videos::Opensubtitles::Parsers::Episode.new(source_uri)
36
+ end
37
+
38
+ # @return [EhbrsRubyUtils::Videos::Opensubtitles::Parsers::Title]
39
+ def title_parser
40
+ ::EhbrsRubyUtils::Videos::Opensubtitles::Parsers::Title.new(source_uri)
41
+ end
42
+
43
+ # @return [Aranha::DefaultProcessor]
44
+ def sub_processor_uncached
45
+ sub_processor_class.new(source_uri, extra_data)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -18,6 +18,11 @@ module EhbrsRubyUtils
18
18
  episodes.each(&:perform)
19
19
  end
20
20
 
21
+ # @return [Array<EhbrsRubyUtils::Videos::Opensubtitles::Processors::Subtitle>]
22
+ def subtitles
23
+ episodes.flat_map(&:subtitles)
24
+ end
25
+
21
26
  private
22
27
 
23
28
  def episode_uri(episode_data)
@@ -36,9 +36,7 @@ module EhbrsRubyUtils
36
36
  height <=> other.height
37
37
  end
38
38
 
39
- def to_s
40
- height.to_s
41
- end
39
+ delegate :to_s, to: :height
42
40
 
43
41
  def to_xs
44
42
  "#{height} (Min: #{min_height}, Max: #{max_height})"
@@ -29,11 +29,11 @@ module EhbrsRubyUtils
29
29
  end
30
30
 
31
31
  def higher
32
- width > height ? width : height
32
+ [width, height].max
33
33
  end
34
34
 
35
35
  def lower
36
- width < height ? width : height
36
+ [width, height].min
37
37
  end
38
38
 
39
39
  def pixels
@@ -10,10 +10,10 @@ module EhbrsRubyUtils
10
10
  module BasenameParser
11
11
  FORMATS = [{
12
12
  format: /(\d+)(\d{2})(\d{2})/i,
13
- build: ->(m) { { s: padding(m[1]), e: padding(m[2]) + '-' + padding(m[3]) } }
13
+ build: ->(m) { { s: padding(m[1]), e: "#{padding(m[2])}-#{padding(m[3])}" } }
14
14
  }, {
15
15
  format: /s(\d+)e(\d+)-(\d+)/i,
16
- build: ->(m) { { s: padding(m[1]), e: padding(m[2]) + '-' + padding(m[3]) } }
16
+ build: ->(m) { { s: padding(m[1]), e: "#{padding(m[2])}-#{padding(m[3])}" } }
17
17
  }, {
18
18
  format: /(\d{1,2})\s*[^\d]\s*(\d{2})/i,
19
19
  build: ->(m) { { s: padding(m[1]), e: padding(m[2]) } }
@@ -13,7 +13,7 @@ module EhbrsRubyUtils
13
13
 
14
14
  common_constructor :file, :options do
15
15
  self.file = file.to_pathname.expand_path
16
- self.options = ::OpenStruct.new(options) if options.is_a?(::Hash)
16
+ self.options = options.to_struct if options.is_a?(::Hash)
17
17
  end
18
18
 
19
19
  # @return [String]
@@ -70,7 +70,7 @@ module EhbrsRubyUtils
70
70
 
71
71
  def kernel_from_directory_name
72
72
  dir = dirname.basename.to_path.sub(/\([0-9]+\)/, '')
73
- dir.split(/\W+/).select { |w| /\A[a-z0-9]/.match(w) }.map { |p| p[0].downcase }.join('')
73
+ dir.split(/\W+/).select { |w| /\A[a-z0-9]/.match(w) }.map { |p| p[0].downcase }.join
74
74
  end
75
75
 
76
76
  def extension
@@ -11,13 +11,13 @@ module EhbrsRubyUtils
11
11
  enable_speaker
12
12
 
13
13
  def show(level)
14
- out(padding_level(level) + line_out + "\n")
14
+ out("#{padding_level(level)}#{line_out}\n")
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def padding_level(level)
20
- (' ' * level.to_i) + '* '
20
+ "#{' ' * level.to_i}* "
21
21
  end
22
22
  end
23
23
  end
@@ -10,6 +10,7 @@ module EhbrsRubyUtils
10
10
  attr_reader :name, :children
11
11
 
12
12
  def initialize(name, files)
13
+ super
13
14
  @name = name
14
15
  @children = build_children(files)
15
16
  end
@@ -10,6 +10,7 @@ module EhbrsRubyUtils
10
10
  attr_reader :season, :files
11
11
 
12
12
  def initialize(season, files)
13
+ super
13
14
  @season = season
14
15
  @files = files.sort_by { |f| [f.episode] }
15
16
  end
@@ -54,7 +54,7 @@ module EhbrsRubyUtils
54
54
  end
55
55
 
56
56
  def language_with_title
57
- [language, title].reject(&:blank?).if_present { |v| v.join('_').variableize }
57
+ [language, title].compact_blank.if_present { |v| v.join('_').variableize }
58
58
  end
59
59
 
60
60
  def title
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/fs/to_file_format'
5
+ require 'ehbrs_ruby_utils/videos/subtitles/sanitize/with_pattern_matcher'
6
+ require 'ehbrs_ruby_utils/videos/subtitles/sanitize/with_term_matcher'
7
+ require 'srt'
8
+
9
+ module EhbrsRubyUtils
10
+ module Videos
11
+ module Subtitles
12
+ class Sanitize < ::EhbrsRubyUtils::Fs::ToFileFormat
13
+ class ContentSanitizer
14
+ class << self
15
+ def build_pattern(slim, elim)
16
+ /#{::Regexp.quote(slim)}[^#{::Regexp.quote(elim)}]*#{::Regexp.quote(elim)}/
17
+ end
18
+ end
19
+
20
+ REMOVE_PATTERNS = [%w[< >], %w[( )], ['[', ']']].map do |args|
21
+ build_pattern(*args)
22
+ end.freeze
23
+ REMOVE_TERMS = %w[subtitle osdb legenda @ united4ever unitedteam pt-subs capejuna maniacs
24
+ |]
25
+ .map(&:downcase)
26
+
27
+ common_constructor :input
28
+
29
+ def line_processors
30
+ REMOVE_PATTERNS.map do |pattern|
31
+ ::EhbrsRubyUtils::Videos::Subtitles::Sanitize::WithPatternMatcher.new(pattern)
32
+ end
33
+ end
34
+
35
+ def output
36
+ output_lines.join("\n")
37
+ end
38
+
39
+ def output_lines
40
+ r = []
41
+ last_output_line = nil
42
+ ::SRT::File.parse_string(input).lines.each do |input_line|
43
+ output_line(input_line, last_output_line).if_present do |v|
44
+ r << v
45
+ last_output_line = v
46
+ end
47
+ end
48
+ r
49
+ end
50
+
51
+ def output_line(input_line, last_output_line)
52
+ text = output_line_text(input_line.text)
53
+ return nil if text.blank?
54
+
55
+ r = input_line.dup
56
+ r.sequence = last_output_line.if_present(1) { |v| v.sequence + 1 }
57
+ r.text = text
58
+ r
59
+ end
60
+
61
+ def output_line_text(text)
62
+ text_processors.each do |term|
63
+ text = term.process(text)
64
+ return nil if text.blank?
65
+ end
66
+
67
+ text.map { |line| process_line(line) }.compact_blank
68
+ end
69
+
70
+ def process_line(line)
71
+ remove_tags(line)
72
+ end
73
+
74
+ def remove_tags(line)
75
+ line_processors.inject(line) { |a, e| e.process(a) }.strip
76
+ end
77
+
78
+ def text_processors
79
+ REMOVE_TERMS.map do |term|
80
+ ::EhbrsRubyUtils::Videos::Subtitles::Sanitize::WithTermMatcher.new(term)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end