filter_rename 1.1.0 → 1.2.0
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 +4 -4
- data/.github/FUNDING.yml +5 -3
- data/.github/workflows/gem-push.yml +46 -0
- data/.github/workflows/main.yml +32 -0
- data/.rubocop.yml +84 -0
- data/Gemfile +15 -1
- data/README.md +83 -39
- data/Rakefile +7 -1
- data/exe/filter_rename +1 -1
- data/filter_rename.gemspec +23 -25
- data/lib/filter_rename/cli.rb +121 -61
- data/lib/filter_rename/config.rb +218 -49
- data/lib/filter_rename/filename.rb +50 -39
- data/lib/filter_rename/filename_factory.rb +22 -17
- data/lib/filter_rename/filetype/audio_filename.rb +86 -0
- data/lib/filter_rename/filetype/image_filename.rb +18 -12
- data/lib/filter_rename/filetype/mp3_filename.rb +18 -18
- data/lib/filter_rename/filetype/pdf_filename.rb +19 -12
- data/lib/filter_rename/filter_base.rb +89 -69
- data/lib/filter_rename/filter_pipe.rb +20 -15
- data/lib/filter_rename/filters.rb +570 -273
- data/lib/filter_rename/utils.rb +288 -117
- data/lib/filter_rename/version.rb +3 -1
- data/lib/filter_rename.rb +95 -32
- data/lib/filter_rename.yaml +20 -10
- metadata +28 -41
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b45ed1cf9b2044a3613d698125dc699c005154bc3c859623be546f748efebdf
|
|
4
|
+
data.tar.gz: 7b2407fbe28d667e3d298f9b90a11b12704bd30a2152c062484ba267f9fcd2a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8054cf53f69b2c0aa28fa41d8b9343c6caee5b2ea14b3c829bd09ea2348b0c86e33022eedc7a788ca5b1dc406692a9590bcf810b183cfcf33ed9fd5cfa464658
|
|
7
|
+
data.tar.gz: 00334ee6bff0e4436e3922340bae92d02df5af45d3b176d2769725ca0063ebc8cfb3ceaae5c35d7707db77e017c9e0e4de6e87e2c026a36331356c2ca94f14e1
|
data/.github/FUNDING.yml
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
---
|
|
1
2
|
# These are supported funding model platforms
|
|
2
3
|
|
|
3
4
|
github: [fabiomux]
|
|
4
5
|
#patreon: # Replace with a single Patreon username
|
|
5
6
|
#open_collective: # Replace with a single Open Collective username
|
|
6
|
-
|
|
7
|
+
ko_fi: freeaptitude
|
|
7
8
|
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
9
|
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
10
|
#liberapay: # Replace with a single Liberapay username
|
|
10
11
|
#issuehunt: # Replace with a single IssueHunt username
|
|
11
12
|
#otechie: # Replace with a single Otechie username
|
|
12
13
|
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
|
13
|
-
custom:
|
|
14
|
-
|
|
14
|
+
custom:
|
|
15
|
+
- 'https://paypal.me/fabiomux'
|
|
16
|
+
- 'https://www.buymeacoffee.com/DCkNYFg'
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: Ruby Gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
tags:
|
|
8
|
+
- 'v*'
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build + Publish
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
packages: write
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v3
|
|
20
|
+
- name: Set up Ruby 2.6
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
22
|
+
with:
|
|
23
|
+
ruby-version: 2.6.10
|
|
24
|
+
|
|
25
|
+
- name: Publish to GPR
|
|
26
|
+
run: |
|
|
27
|
+
mkdir -p $HOME/.gem
|
|
28
|
+
touch $HOME/.gem/credentials
|
|
29
|
+
chmod 0600 $HOME/.gem/credentials
|
|
30
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
31
|
+
gem build *.gemspec
|
|
32
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
|
33
|
+
env:
|
|
34
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
|
35
|
+
OWNER: ${{ github.repository_owner }}
|
|
36
|
+
|
|
37
|
+
# - name: Publish to RubyGems
|
|
38
|
+
# run: |
|
|
39
|
+
# mkdir -p $HOME/.gem
|
|
40
|
+
# touch $HOME/.gem/credentials
|
|
41
|
+
# chmod 0600 $HOME/.gem/credentials
|
|
42
|
+
# printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
43
|
+
# gem build *.gemspec
|
|
44
|
+
# gem push *.gem
|
|
45
|
+
# env:
|
|
46
|
+
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
ruby:
|
|
17
|
+
- '2.7.8'
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v3
|
|
21
|
+
- name: Install exiv2
|
|
22
|
+
run: sudo apt-get install -y libexiv2-dev
|
|
23
|
+
- name: Install taglib
|
|
24
|
+
run: sudo apt-get install -y libtag1-dev
|
|
25
|
+
- name: Set up Ruby
|
|
26
|
+
uses: ruby/setup-ruby@v1
|
|
27
|
+
with:
|
|
28
|
+
ruby-version: ${{ matrix.ruby }}
|
|
29
|
+
bundler-cache: true
|
|
30
|
+
|
|
31
|
+
- name: Run the default task
|
|
32
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Style/ClassVars:
|
|
7
|
+
Enabled: false
|
|
8
|
+
|
|
9
|
+
Style/StringLiterals:
|
|
10
|
+
Enabled: true
|
|
11
|
+
EnforcedStyle: double_quotes
|
|
12
|
+
|
|
13
|
+
Style/StringLiteralsInInterpolation:
|
|
14
|
+
Enabled: true
|
|
15
|
+
EnforcedStyle: double_quotes
|
|
16
|
+
|
|
17
|
+
Layout/LineLength:
|
|
18
|
+
Max: 120
|
|
19
|
+
|
|
20
|
+
Naming/FileName:
|
|
21
|
+
Enabled: false
|
|
22
|
+
|
|
23
|
+
Metrics/MethodLength:
|
|
24
|
+
Enabled: false
|
|
25
|
+
|
|
26
|
+
Metrics/AbcSize:
|
|
27
|
+
Enabled: false
|
|
28
|
+
|
|
29
|
+
Lint/DuplicateBranch:
|
|
30
|
+
Enabled: false
|
|
31
|
+
|
|
32
|
+
Metrics/ClassLength:
|
|
33
|
+
Enabled: true
|
|
34
|
+
Exclude:
|
|
35
|
+
- './lib/**/cli.rb'
|
|
36
|
+
- './lib/**/config.rb'
|
|
37
|
+
- './lib/**/filename.rb'
|
|
38
|
+
- './lib/**/filter_rename.rb'
|
|
39
|
+
- './lib/**/utils.rb'
|
|
40
|
+
|
|
41
|
+
Metrics/BlockLength:
|
|
42
|
+
Enabled: true
|
|
43
|
+
Exclude:
|
|
44
|
+
- '*.gemspec'
|
|
45
|
+
- './lib/**/cli.rb'
|
|
46
|
+
- './spec/**/*'
|
|
47
|
+
|
|
48
|
+
Metrics/PerceivedComplexity:
|
|
49
|
+
Enabled: true
|
|
50
|
+
Exclude:
|
|
51
|
+
- './lib/**/filter_rename.rb'
|
|
52
|
+
- './lib/**/cli.rb'
|
|
53
|
+
- './lib/**/config.rb'
|
|
54
|
+
- './lib/**/filename_factory.rb'
|
|
55
|
+
- './lib/**/filter_base.rb'
|
|
56
|
+
- './lib/**/utils.rb'
|
|
57
|
+
- './lib/**/audio_filename.rb'
|
|
58
|
+
|
|
59
|
+
Metrics/CyclomaticComplexity:
|
|
60
|
+
Enabled: true
|
|
61
|
+
Exclude:
|
|
62
|
+
- './lib/**/filter_rename.rb'
|
|
63
|
+
- './lib/**/cli.rb'
|
|
64
|
+
- './lib/**/config.rb'
|
|
65
|
+
- './lib/**/filename_factory.rb'
|
|
66
|
+
- './lib/**/filter_base.rb'
|
|
67
|
+
- './lib/**/utils.rb'
|
|
68
|
+
- './lib/**/audio_filename.rb'
|
|
69
|
+
|
|
70
|
+
Style/MixinUsage:
|
|
71
|
+
Enabled: true
|
|
72
|
+
Exclude:
|
|
73
|
+
- './spec/**/*'
|
|
74
|
+
|
|
75
|
+
Style/FrozenStringLiteralComment:
|
|
76
|
+
Enabled: true
|
|
77
|
+
Exclude:
|
|
78
|
+
- './bin/*'
|
|
79
|
+
- './exe/*'
|
|
80
|
+
|
|
81
|
+
Style/Documentation:
|
|
82
|
+
Enabled: true
|
|
83
|
+
Exclude:
|
|
84
|
+
- './lib/**/filters.rb'
|
data/Gemfile
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
2
4
|
|
|
3
5
|
# Specify your gem's dependencies in filter_rename.gemspec
|
|
4
6
|
gemspec
|
|
7
|
+
|
|
8
|
+
gem "bundler", "~> 2.0"
|
|
9
|
+
|
|
10
|
+
gem "rake", "~> 13.0"
|
|
11
|
+
|
|
12
|
+
gem "rspec", "~> 3.0"
|
|
13
|
+
|
|
14
|
+
gem "rubocop", "~> 1.21"
|
|
15
|
+
|
|
16
|
+
gem "rubocop-rake", "~> 0.7.0"
|
|
17
|
+
|
|
18
|
+
gem "rubocop-rspec", "~> 3.0"
|
data/README.md
CHANGED
|
@@ -1,82 +1,126 @@
|
|
|
1
1
|
# FilterRename
|
|
2
2
|
|
|
3
|
-
FilterRename is a CLI tool created
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
FilterRename is a CLI tool created for bulk file renaming that work appending a set of micro
|
|
4
|
+
operations here called *filters*, which aim to replace most, if not all, the shell commands
|
|
5
|
+
usually involved in that kind of operations (*sed*, *awk*, *trim*, ...) in a more safe and
|
|
6
|
+
comfortable manner.
|
|
7
|
+
|
|
8
|
+
[][wf_main]
|
|
9
|
+
[][gem_version]
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
### Requirements
|
|
14
|
+
|
|
15
|
+
These two libraries must be installed:
|
|
16
|
+
- **exiv2**
|
|
17
|
+
- **taglib**
|
|
18
|
+
|
|
19
|
+
With *openSUSE*:
|
|
20
|
+
```shell
|
|
21
|
+
$ sudo zypper install libexiv2-devel libtag-devel
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
With *Debian*/*Ubuntu*:
|
|
25
|
+
```shell
|
|
26
|
+
$ sudo apt-get install libexiv2-dev libtag1-dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Rubygem
|
|
30
|
+
|
|
31
|
+
Install it as a regular Ruby gem with:
|
|
32
|
+
```shell
|
|
33
|
+
$ gem install filter_rename
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
7
37
|
|
|
8
38
|
To simplify the whole process through a command line, the full filename is logically organized
|
|
9
|
-
in
|
|
39
|
+
in *targets*:
|
|
10
40
|
|
|
11
41
|
<path>/<folder>/<name><ext>
|
|
12
42
|
|
|
13
|
-
|
|
43
|
+
For example, considering the file `/home/fabio/Documents/Ruby/filter_rename/Gemfile.lock` we have:
|
|
14
44
|
|
|
15
45
|
- path: */home/fabio/Documents/Ruby*
|
|
16
46
|
- folder: *filter_rename*
|
|
17
47
|
- name: *Gemfile*
|
|
18
48
|
- ext: *.lock*
|
|
19
49
|
|
|
20
|
-
The chain of filters will be applied to the current
|
|
21
|
-
option
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
Install it yourself as:
|
|
26
|
-
|
|
27
|
-
$ gem install filter_rename
|
|
50
|
+
The chain of *filters* will be applied to the current *target*, which is *name* by default, but can
|
|
51
|
+
be changed using the *--select* option on the same command line without running the command twice.
|
|
28
52
|
|
|
29
|
-
|
|
53
|
+
For example, to capitalize the *ext* and upper case the *name* at the same time we can use:
|
|
54
|
+
```shell
|
|
55
|
+
filter_rename Gemfile.lock --uppercase --select ext --capitalize
|
|
56
|
+
```
|
|
30
57
|
|
|
31
|
-
|
|
32
|
-
executed one by one as they appear in the argument's list.
|
|
58
|
+
So the file *Gemfile.lock* becomes *GEMFILE.Lock*.
|
|
33
59
|
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* _dry-run_: executes a simulation warning when a conflict is raised;
|
|
37
|
-
* _apply_: confirm the changes and rename the files unless the destination file exists.
|
|
60
|
+
To make things easier we can use a special class of *filters* that target a string as a list of *words*
|
|
61
|
+
or *numbers* with their position used as index.
|
|
38
62
|
|
|
39
|
-
|
|
63
|
+
For example, having the files:
|
|
40
64
|
|
|
41
65
|
home
|
|
42
66
|
fabio
|
|
43
67
|
Documents
|
|
44
68
|
Photos
|
|
45
69
|
Vacations
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
image_from_portofino_0.jpg
|
|
71
|
+
image_from_portofino_1.jpg
|
|
72
|
+
image_from_portofino_2.jpg
|
|
49
73
|
...
|
|
50
74
|
|
|
51
|
-
|
|
75
|
+
We want:
|
|
76
|
+
- space-separated words in place of the underscore;
|
|
77
|
+
- the first and third word capitalized;
|
|
78
|
+
- the final number must start from 1;
|
|
79
|
+
- the final number must be 2 digits wide.
|
|
52
80
|
|
|
53
|
-
|
|
81
|
+
Using:
|
|
82
|
+
```shell
|
|
83
|
+
$ filter_rename /home/fabio/Documents/Photos/Vacations/*.jpg \
|
|
84
|
+
--spacify '_' \
|
|
85
|
+
--capitalize-word 1:3 \
|
|
86
|
+
--add-number 1,1 \
|
|
87
|
+
--format-number 1,2
|
|
88
|
+
```
|
|
54
89
|
|
|
55
|
-
|
|
90
|
+
The result is:
|
|
56
91
|
|
|
57
92
|
home
|
|
58
93
|
fabio
|
|
59
94
|
Documents
|
|
60
95
|
Photos
|
|
61
96
|
Vacations
|
|
62
|
-
Image Portofino
|
|
63
|
-
Image Portofino
|
|
64
|
-
Image Portofino
|
|
97
|
+
Image from Portofino 01.jpg
|
|
98
|
+
Image from Portofino 02.jpg
|
|
99
|
+
Image from Portofino 03.jpg
|
|
65
100
|
...
|
|
66
101
|
|
|
102
|
+
If you are wondering why all the commands above didn't affected the files physically on the disk,
|
|
103
|
+
then must be aware of the three main operations contemplated:
|
|
104
|
+
- *diff*: shows the results verbosly without making any change (default);
|
|
105
|
+
- *dry-run*: executes a simulation warning also for renaming conflicts;
|
|
106
|
+
- *apply*: confirm the changes and rename the files unless the destination file exists.
|
|
107
|
+
|
|
108
|
+
Last but not least filter_rename also supports *macros* and *regular expressions*, and the ability to
|
|
109
|
+
setup configurations params on the fly (*config* and *global*).
|
|
67
110
|
|
|
68
111
|
## Get help
|
|
69
112
|
|
|
70
113
|
Where to start
|
|
114
|
+
```shell
|
|
115
|
+
$ filter_rename --help
|
|
116
|
+
```
|
|
71
117
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
More help
|
|
75
|
-
|
|
76
|
-
- The wiki page: https://github.com/fabiomux/filter_rename/wiki
|
|
77
|
-
|
|
118
|
+
## More help
|
|
78
119
|
|
|
79
|
-
|
|
120
|
+
More info is available at:
|
|
121
|
+
- the [FilterRename GitHub wiki][filter_rename_wiki].
|
|
80
122
|
|
|
81
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/fabio_mux/filter_rename. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
82
123
|
|
|
124
|
+
[filter_rename_wiki]: https://github.com/fabiomux/filter_rename/wiki "FilterRename wiki page on GitHub"
|
|
125
|
+
[wf_main]: https://github.com/fabiomux/filter_rename/actions/workflows/main.yml
|
|
126
|
+
[gem_version]: https://badge.fury.io/rb/filter_rename
|
data/Rakefile
CHANGED
data/exe/filter_rename
CHANGED
data/filter_rename.gemspec
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require 'filter_rename/version'
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/filter_rename/version"
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
6
|
spec.name = "filter_rename"
|
|
@@ -9,36 +8,35 @@ Gem::Specification.new do |spec|
|
|
|
9
8
|
spec.authors = ["Fabio Mucciante"]
|
|
10
9
|
spec.email = ["fabio.mucciante@gmail.com"]
|
|
11
10
|
|
|
12
|
-
spec.summary =
|
|
13
|
-
spec.description =
|
|
11
|
+
spec.summary = "File renaming tool which make use of a chain of actions called filters."
|
|
12
|
+
spec.description = "FilterRename is a bulk renaming tool, based on the concept of filters as small operations " \
|
|
13
|
+
"to perform over sections of the full filename logically represented in targets."
|
|
14
14
|
spec.homepage = "https://github.com/fabiomux/filter_rename"
|
|
15
15
|
spec.license = "GPL-3.0"
|
|
16
|
+
spec.required_ruby_version = ">= 2.5.0"
|
|
16
17
|
|
|
17
|
-
spec.metadata
|
|
18
|
-
"bug_tracker_uri"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"wiki_uri" => "https://github.com/fabiomux/filter_rename/wiki"
|
|
18
|
+
spec.metadata = {
|
|
19
|
+
"bug_tracker_uri" => "https://github.com/fabiomux/filter_rename/issues",
|
|
20
|
+
"homepage_uri" => "https://freeaptitude.altervista.org/projects/filter-rename.html",
|
|
21
|
+
"source_code_uri" => "https://github.com/fabiomux/filter_rename",
|
|
22
|
+
"changelog_uri" => "https://freeaptitude.altervista.org/projects/filter-rename.html#changelog",
|
|
23
|
+
"wiki_uri" => "https://github.com/fabiomux/filter_rename/wiki",
|
|
24
|
+
"rubygems_mfa_required" => "true"
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
spec.files
|
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
28
28
|
f.match(%r{^(test|spec|features)/})
|
|
29
29
|
end
|
|
30
30
|
spec.bindir = "exe"
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
32
32
|
spec.require_paths = ["lib"]
|
|
33
33
|
|
|
34
|
-
spec.
|
|
35
|
-
spec.
|
|
36
|
-
spec.
|
|
37
|
-
|
|
38
|
-
spec.
|
|
39
|
-
spec.
|
|
40
|
-
spec.
|
|
41
|
-
spec.
|
|
42
|
-
spec.add_runtime_dependency "fastimage"
|
|
43
|
-
spec.add_runtime_dependency "pdf-reader"
|
|
34
|
+
spec.add_dependency "differ"
|
|
35
|
+
spec.add_dependency "exiv2"
|
|
36
|
+
spec.add_dependency "fastimage"
|
|
37
|
+
spec.add_dependency "keisan"
|
|
38
|
+
spec.add_dependency "mimemagic"
|
|
39
|
+
spec.add_dependency "mp3info"
|
|
40
|
+
spec.add_dependency "pdf-reader"
|
|
41
|
+
spec.add_dependency "taglib-ruby" #, "~> 1.0"
|
|
44
42
|
end
|