ehbrs_ruby_utils 0.16.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -8
- data/lib/ehbrs_ruby_utils/music/lyrics_book/song.rb +1 -1
- data/lib/ehbrs_ruby_utils/spreader_t1/base_level.rb +1 -1
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/lib/ehbrs_ruby_utils/videos/series/rename/directory_group.rb +28 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/file/basename_parser.rb +44 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/file/options.rb +20 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/file/renamer.rb +51 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/file.rb +102 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/line_result.rb +26 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/line_result_group.rb +39 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/results_builder.rb +32 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename/season_group.rb +39 -0
- data/lib/ehbrs_ruby_utils/videos/series/rename.rb +13 -0
- data/lib/ehbrs_ruby_utils/videos/series.rb +11 -0
- metadata +17 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18bf8f507c46f76400bf63a57e2309db8930cdde653e2967b63802455ea375b
|
4
|
+
data.tar.gz: 60ca9d39a6e5ff6ec008925a218d7636b0c0045032b8a65a3921995c63936bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20f0a8bd00ba051fabe2e3e0747c0a1e3f3844dc5ff7019c7051203cdaa86c3b0774d6e8869b0dc3a31d0dd1bee6fe69dbab6d409967be8a477b2a22cf251402
|
7
|
+
data.tar.gz: 41c38422cc3aab6bc0af6d4bb09f5160d1f269cdd4d6acbe142b78eeb7d47432aff81ff0e22023d522b3d65f95309a725809d930ca74fcbdc9f7f525ef1849fc
|
data/.rubocop.yml
CHANGED
@@ -3,21 +3,38 @@ require:
|
|
3
3
|
- rubocop-rspec
|
4
4
|
|
5
5
|
AllCops:
|
6
|
-
|
7
|
-
|
8
|
-
Layout/LineLength:
|
9
|
-
Max: 100
|
6
|
+
TargetRailsVersion: 5.2
|
7
|
+
TargetRubyVersion: 2.7
|
10
8
|
|
11
9
|
Metrics/BlockLength:
|
12
10
|
Exclude:
|
11
|
+
- '**/*.gemspec'
|
13
12
|
- 'spec/**/*_spec.rb'
|
14
13
|
|
15
|
-
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 100
|
16
|
+
|
17
|
+
Layout/MultilineMethodCallIndentation:
|
18
|
+
EnforcedStyle: indented_relative_to_receiver
|
19
|
+
|
20
|
+
Rails/DynamicFindBy:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Rails/Output:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Rails/SkipsModelValidations:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Rails/TimeZone:
|
16
30
|
Enabled: false
|
17
31
|
|
18
32
|
Style/AsciiComments:
|
19
33
|
Enabled: false
|
20
34
|
|
35
|
+
Style/Documentation:
|
36
|
+
Enabled: false
|
37
|
+
|
21
38
|
Style/HashEachMethods:
|
22
39
|
Enabled: true
|
23
40
|
|
@@ -26,6 +43,3 @@ Style/HashTransformKeys:
|
|
26
43
|
|
27
44
|
Style/HashTransformValues:
|
28
45
|
Enabled: true
|
29
|
-
|
30
|
-
Layout/MultilineMethodCallIndentation:
|
31
|
-
EnforcedStyle: indented_relative_to_receiver
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/videos/series/rename/line_result_group'
|
4
|
+
require 'ehbrs_ruby_utils/videos/series/rename/season_group'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Videos
|
8
|
+
module Series
|
9
|
+
module Rename
|
10
|
+
class DirectoryGroup < LineResultGroup
|
11
|
+
def line_out
|
12
|
+
name.to_s.colorize(:light_yellow)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def child_key
|
18
|
+
:season
|
19
|
+
end
|
20
|
+
|
21
|
+
def child_class
|
22
|
+
::EhbrsRubyUtils::Videos::Series::Rename::SeasonGroup
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/videos/series/rename/line_result'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class File < ::EhbrsRubyUtils::Videos::Series::Rename::LineResult
|
10
|
+
module BasenameParser
|
11
|
+
FORMATS = [{
|
12
|
+
format: /(\d+)(\d{2})(\d{2})/i,
|
13
|
+
build: ->(m) { { s: padding(m[1]), e: padding(m[2]) + '-' + padding(m[3]) } }
|
14
|
+
}, {
|
15
|
+
format: /s(\d+)e(\d+)-(\d+)/i,
|
16
|
+
build: ->(m) { { s: padding(m[1]), e: padding(m[2]) + '-' + padding(m[3]) } }
|
17
|
+
}, {
|
18
|
+
format: /(\d{1,2})\s*[^\d]\s*(\d{2})/i,
|
19
|
+
build: ->(m) { { s: padding(m[1]), e: padding(m[2]) } }
|
20
|
+
}, {
|
21
|
+
format: /(\d+)(\d{2})/i,
|
22
|
+
build: ->(m) { { s: padding(m[1]), e: padding(m[2]) } }
|
23
|
+
}, {
|
24
|
+
format: /(\d{2})/i,
|
25
|
+
build: ->(m) { { s: padding(1), e: padding(m[1]) } }
|
26
|
+
}].freeze
|
27
|
+
|
28
|
+
def self.padding(string)
|
29
|
+
string.to_s.rjust(2, '0')
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_uncached
|
33
|
+
FORMATS.each do |format|
|
34
|
+
m = format.fetch(:format).match(current_name)
|
35
|
+
return format.fetch(:build).call(m) if m
|
36
|
+
end
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EhbrsRubyUtils
|
4
|
+
module Videos
|
5
|
+
module Series
|
6
|
+
module Rename
|
7
|
+
class File
|
8
|
+
class Options
|
9
|
+
common_constructor :options
|
10
|
+
delegate :kernel, :confirm, :recursive, :extension, to: :options
|
11
|
+
|
12
|
+
def episode_increment
|
13
|
+
options.episode_increment.if_present(0, &:to_i)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class File
|
10
|
+
class Renamer
|
11
|
+
enable_speaker
|
12
|
+
common_constructor :owner
|
13
|
+
delegate :current_name, :dirname, :file, :new_name, to: :owner
|
14
|
+
|
15
|
+
def perform
|
16
|
+
return unless rename?
|
17
|
+
|
18
|
+
version_number = 0
|
19
|
+
loop do
|
20
|
+
target_path = dirname.join(build_target_name(version_number))
|
21
|
+
break perform_rename(target_path) unless target_path.exist?
|
22
|
+
|
23
|
+
version_number += 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_target_name(version_number)
|
30
|
+
return new_name unless version_number.positive?
|
31
|
+
|
32
|
+
extname = ::File.extname(new_name)
|
33
|
+
"#{::File.basename(new_name, extname)}.v#{version_number}#{extname}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def perform_rename(target_path)
|
37
|
+
infov 'Renaming', file.to_path
|
38
|
+
::FileUtils.mv(file.to_path, target_path.to_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def rename?
|
42
|
+
return false unless new_name
|
43
|
+
|
44
|
+
current_name != new_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/fs/extname'
|
4
|
+
require 'ehbrs_ruby_utils/videos/series/rename/line_result'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
module EhbrsRubyUtils
|
8
|
+
module Videos
|
9
|
+
module Series
|
10
|
+
module Rename
|
11
|
+
class File < ::EhbrsRubyUtils::Videos::Series::Rename::LineResult
|
12
|
+
require_sub __FILE__, include_modules: true
|
13
|
+
|
14
|
+
common_constructor :file, :options do
|
15
|
+
self.file = file.to_pathname.expand_path
|
16
|
+
self.options = ::OpenStruct.new(options) if options.is_a?(::Hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
def current_name
|
21
|
+
file.basename.to_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def rename
|
25
|
+
EhbrsRubyUtils::Videos::Series::Rename::File::Renamer.new(self).perform
|
26
|
+
end
|
27
|
+
|
28
|
+
def season
|
29
|
+
return '??' if parse.blank?
|
30
|
+
|
31
|
+
parse.fetch(:s)
|
32
|
+
end
|
33
|
+
|
34
|
+
def episode
|
35
|
+
return '??' if parse.blank?
|
36
|
+
|
37
|
+
parse.fetch(:e)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Pathname]
|
41
|
+
def dirname
|
42
|
+
d = file
|
43
|
+
until d.root?
|
44
|
+
d = d.dirname
|
45
|
+
return d unless d.basename.to_path.starts_with?('_')
|
46
|
+
end
|
47
|
+
raise "series_dirname not found for #{file.to_path}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def line_out
|
51
|
+
"#{episode.green}: " + if new_name == current_name
|
52
|
+
current_name.light_black
|
53
|
+
else
|
54
|
+
"#{new_name} <= #{current_name}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def new_name
|
59
|
+
return "#{kernel}-s#{parse[:s]}e#{new_name_episodes}#{extension}" if parse.present?
|
60
|
+
|
61
|
+
current_name
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def kernel
|
67
|
+
options.kernel || kernel_from_directory_name ||
|
68
|
+
raise("Kernel undefined (File: #{file.to_path})")
|
69
|
+
end
|
70
|
+
|
71
|
+
def kernel_from_directory_name
|
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('')
|
74
|
+
end
|
75
|
+
|
76
|
+
def extension
|
77
|
+
return options.extension if options.extension
|
78
|
+
|
79
|
+
extension_by_directory || ::EacRubyUtils::Fs.extname2(current_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def extension_by_directory
|
83
|
+
r = ::File.dirname(current_name)
|
84
|
+
return nil if r == '.'
|
85
|
+
|
86
|
+
r.gsub(/\A_/, '.')
|
87
|
+
end
|
88
|
+
|
89
|
+
def source_episodes
|
90
|
+
parse[:e].split('-').map(&:to_i)
|
91
|
+
end
|
92
|
+
|
93
|
+
def new_name_episodes
|
94
|
+
source_episodes.map do |i|
|
95
|
+
(i + options.episode_increment).to_s.rjust(2, '0')
|
96
|
+
end.join('-')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class LineResult
|
10
|
+
enable_simple_cache
|
11
|
+
enable_speaker
|
12
|
+
|
13
|
+
def show(level)
|
14
|
+
out(padding_level(level) + line_out + "\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def padding_level(level)
|
20
|
+
(' ' * level.to_i) + '* '
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'line_result'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class LineResultGroup < ::EhbrsRubyUtils::Videos::Series::Rename::LineResult
|
10
|
+
attr_reader :name, :children
|
11
|
+
|
12
|
+
def initialize(name, files)
|
13
|
+
@name = name
|
14
|
+
@children = build_children(files)
|
15
|
+
end
|
16
|
+
|
17
|
+
def show(level)
|
18
|
+
super(level)
|
19
|
+
children.each do |child|
|
20
|
+
child.show(level + 1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_children(files)
|
27
|
+
r = {}
|
28
|
+
files.each do |file|
|
29
|
+
key = file.send(child_key)
|
30
|
+
r[key] ||= []
|
31
|
+
r[key] << file
|
32
|
+
end
|
33
|
+
r.sort.map { |v| child_class.new(v[0], v[1]) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/videos/series/rename/directory_group'
|
4
|
+
require 'ehbrs_ruby_utils/videos/series/rename/line_result_group'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Videos
|
8
|
+
module Series
|
9
|
+
module Rename
|
10
|
+
class ResultsBuilder < LineResultGroup
|
11
|
+
def initialize(files)
|
12
|
+
super '', files
|
13
|
+
end
|
14
|
+
|
15
|
+
def line_out
|
16
|
+
'Groups: '.cyan + children.count.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def child_key
|
22
|
+
:dirname
|
23
|
+
end
|
24
|
+
|
25
|
+
def child_class
|
26
|
+
::EhbrsRubyUtils::Videos::Series::Rename::DirectoryGroup
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'line_result'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Videos
|
7
|
+
module Series
|
8
|
+
module Rename
|
9
|
+
class SeasonGroup < ::EhbrsRubyUtils::Videos::Series::Rename::LineResult
|
10
|
+
attr_reader :season, :files
|
11
|
+
|
12
|
+
def initialize(season, files)
|
13
|
+
@season = season
|
14
|
+
@files = files.sort_by { |f| [f.episode] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def line_out
|
18
|
+
'Season: '.cyan + "#{season} (#{first_episode} - #{last_episode})"
|
19
|
+
end
|
20
|
+
|
21
|
+
def show(level)
|
22
|
+
super
|
23
|
+
files.each { |file| file.show(level + 1) }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def first_episode
|
29
|
+
files.first.episode
|
30
|
+
end
|
31
|
+
|
32
|
+
def last_episode
|
33
|
+
files.last.episode
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha-parsers
|
@@ -56,14 +56,14 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '0.
|
59
|
+
version: '0.10'
|
60
60
|
type: :runtime
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '0.
|
66
|
+
version: '0.10'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: eac_ruby_utils
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,14 +146,14 @@ dependencies:
|
|
146
146
|
requirements:
|
147
147
|
- - "~>"
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
149
|
+
version: 0.5.1
|
150
150
|
type: :development
|
151
151
|
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
154
|
- - "~>"
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
156
|
+
version: 0.5.1
|
157
157
|
description:
|
158
158
|
email:
|
159
159
|
executables: []
|
@@ -193,6 +193,17 @@ files:
|
|
193
193
|
- lib/ehbrs_ruby_utils/videos/convert_job.rb
|
194
194
|
- lib/ehbrs_ruby_utils/videos/quality.rb
|
195
195
|
- lib/ehbrs_ruby_utils/videos/resolution.rb
|
196
|
+
- lib/ehbrs_ruby_utils/videos/series.rb
|
197
|
+
- lib/ehbrs_ruby_utils/videos/series/rename.rb
|
198
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/directory_group.rb
|
199
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/file.rb
|
200
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/file/basename_parser.rb
|
201
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/file/options.rb
|
202
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/file/renamer.rb
|
203
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/line_result.rb
|
204
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/line_result_group.rb
|
205
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/results_builder.rb
|
206
|
+
- lib/ehbrs_ruby_utils/videos/series/rename/season_group.rb
|
196
207
|
- lib/ehbrs_ruby_utils/videos/stream.rb
|
197
208
|
- lib/ehbrs_ruby_utils/web_utils.rb
|
198
209
|
- lib/ehbrs_ruby_utils/web_utils/instance.rb
|