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.
- checksums.yaml +4 -4
- data/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress.rb +2 -2
- data/lib/ehbrs_ruby_utils/bga/parsers/table/options.rb +3 -3
- data/lib/ehbrs_ruby_utils/bga/session/skip_trophies.rb +1 -1
- data/lib/ehbrs_ruby_utils/bga/session/user.rb +1 -3
- data/lib/ehbrs_ruby_utils/bga/table/whatsapp_formatters/base.rb +1 -1
- data/lib/ehbrs_ruby_utils/circular_list_spreader/base_level.rb +1 -1
- data/lib/ehbrs_ruby_utils/circular_list_spreader/group_level.rb +1 -1
- data/lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb +1 -1
- data/lib/ehbrs_ruby_utils/fs/selected/build.rb +1 -1
- data/lib/ehbrs_ruby_utils/fs/to_file_format.rb +83 -0
- data/lib/ehbrs_ruby_utils/fs/to_utf8_unix.rb +60 -0
- data/lib/ehbrs_ruby_utils/fs/to_windows_pt_br.rb +59 -0
- data/lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb +1 -1
- data/lib/ehbrs_ruby_utils/patches/object/template.rb +2 -2
- data/lib/ehbrs_ruby_utils/patches/object.rb +1 -1
- data/lib/ehbrs_ruby_utils/patches.rb +1 -1
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/lib/ehbrs_ruby_utils/vg/wii/wit/image_format.rb +2 -2
- data/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump.rb +3 -3
- data/lib/ehbrs_ruby_utils/videos/container.rb +1 -1
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/subtitles_provider.rb +51 -0
- data/lib/ehbrs_ruby_utils/videos/opensubtitles/processors/title.rb +5 -0
- data/lib/ehbrs_ruby_utils/videos/quality.rb +1 -3
- data/lib/ehbrs_ruby_utils/videos/resolution.rb +2 -2
- data/lib/ehbrs_ruby_utils/videos/series/rename/file/basename_parser.rb +2 -2
- data/lib/ehbrs_ruby_utils/videos/series/rename/file.rb +2 -2
- data/lib/ehbrs_ruby_utils/videos/series/rename/line_result.rb +2 -2
- data/lib/ehbrs_ruby_utils/videos/series/rename/line_result_group.rb +1 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/season_group.rb +1 -0
- data/lib/ehbrs_ruby_utils/videos/stream.rb +1 -1
- data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize/content_sanitizer.rb +87 -0
- data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize/with_pattern_matcher.rb +20 -0
- data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize/with_term_matcher.rb +20 -0
- data/lib/ehbrs_ruby_utils/videos/subtitles/sanitize.rb +42 -0
- data/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +1 -1
- metadata +42 -160
- data/.rspec +0 -1
- data/.rubocop.yml +0 -45
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec.rb +0 -7
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.source.html +0 -8657
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-12.target.yaml +0 -41
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.source.html +0 -8650
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_84920871_2023-06-19.target.yaml +0 -41
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.source.html +0 -8657
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93167144_2023-06-12.target.yaml +0 -5
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.source.html +0 -8657
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93205235_2023-06-12.target.yaml +0 -13
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.source.html +0 -8657
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93212034_2023-06-12.target.yaml +0 -29
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.source.html +0 -8657
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93223573_2023-06-12.target.yaml +0 -7
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93248308_2023-06-12.source.html +0 -8657
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_in_progress_spec_files/player_93248308_2023-06-12.target.yaml +0 -1
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec.rb +0 -7
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.source.html +0 -1082
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/1.target.yaml +0 -151
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.source.html +0 -1083
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/game_stats_spec_files/2.target.yaml +0 -1127
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec.rb +0 -7
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.source.html +0 -1491
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_302873643.target.yaml +0 -40
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.source.html +0 -1965
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_308782287.target.yaml +0 -46
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.source.html +0 -1497
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_356513708.target.yaml +0 -56
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.source.html +0 -1500
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_357408039.target.yaml +0 -66
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.source.html +0 -1497
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_368448439.target.yaml +0 -58
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.source.html +0 -1441
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373602409.target.yaml +0 -30
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.source.html +0 -1521
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_373747455.target.yaml +0 -59
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_383405743.source.html +0 -1480
- data/spec/lib/ehbrs_ruby_utils/bga/parsers/table_spec_files/table_383405743.target.yaml +0 -32
- data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec.rb +0 -68
- data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.source.yaml +0 -124
- data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/ehbrs_music1.target.yaml +0 -70
- data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.source.yaml +0 -7
- data/spec/lib/ehbrs_ruby_utils/circular_list_spreader_spec_files/minimum.target.yaml +0 -5
- data/spec/lib/ehbrs_ruby_utils/cooking_book/recipe/measure_spec.rb +0 -21
- data/spec/lib/ehbrs_ruby_utils/vg/wii/game_file_spec.rb +0 -21
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec.rb +0 -11
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_R92P01_wia.source.witdump +0 -27
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_R92P01_wia.target.yaml +0 -22
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_pal_iso.source.witdump +0 -28
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/pikmin2_pal_iso.target.yaml +0 -21
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/resident_evil_code_veronica_disc2_iso.source.witdump +0 -16
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/resident_evil_code_veronica_disc2_iso.target.yaml +0 -19
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/super_mario_galaxy_wbfs.source.witdump +0 -28
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/parsers/dump_spec_files/super_mario_galaxy_wbfs.target.yaml +0 -23
- data/spec/lib/ehbrs_ruby_utils/vg/wii/wit/path_spec.rb +0 -33
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec.rb +0 -7
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.source.html +0 -993
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/counterpart_s01e01.target.yaml +0 -5
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.source.html +0 -478
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/episode_spec_files/wire-season-1-page-1.target.yaml +0 -43
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec.rb +0 -7
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.source.html +0 -763
- data/spec/lib/ehbrs_ruby_utils/videos/opensubtitles/parsers/title_spec_files/countepart.target.yaml +0 -22
- data/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +0 -18
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec.rb +0 -13
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.source.yaml +0 -28
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_attachment.target.yaml +0 -8
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.source.yaml +0 -49
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_audio.target.yaml +0 -8
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.source.yaml +0 -43
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_subtitle.target.yaml +0 -8
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.source.yaml +0 -59
- data/spec/lib/ehbrs_ruby_utils/videos/stream_spec_files/menina_ovo_video.target.yaml +0 -8
- data/spec/rubocop_check_spec.rb +0 -3
- data/spec/spec_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a51803bc2fc98c7439c7e0e8808e00866d7130f898e1f9738c1c9f1483b326aa
|
4
|
+
data.tar.gz: a4146dc9718ed5356187a725e1537895c679301ca63d67619f9f3edaa8374223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -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
|
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 =
|
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
|
@@ -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
|
-
|
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(',').
|
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
|
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
|
-
.
|
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
|
@@ -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])
|
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])
|
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 =
|
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)
|
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
|
-
|
20
|
+
"#{' ' * level.to_i}* "
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -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
|