movie_cleaner 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8afaab2b0a4c2766d05f21bad71843345ad89c1186a1a314b6b78fe44ac8273
4
+ data.tar.gz: 6ae2c2c68b9a73066bd627ddb44d3ffe8506af260a619e4a133eda4210244293
5
+ SHA512:
6
+ metadata.gz: ae0130289bfd63e7569761ad663ea3c4ac6ee7b27e4042e798f3af7ecdbdc64a0bcabdcd15b0f75ad1a99522ee120f9729f7ac389a49cffcc741a85170324aa0
7
+ data.tar.gz: 1adf7d34074d20c4ff2ea5a17a4c6052ef96109553de1829a1252671a317efab17d975390837637a9d3b740acae5be5f73c49e8385b1351432f347e523d5161a
data/.editorconfig ADDED
@@ -0,0 +1,8 @@
1
+ [*]
2
+ trim_trailing_whitespace = true
3
+ max_line_length = 120
4
+ insert_final_newline = true
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ require: rubocop-rspec
2
+
3
+ Metrics/LineLength:
4
+ Max: 120
5
+
6
+ Layout/EndOfLine:
7
+ Enabled: False
8
+
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - 'spec/*.rb'
12
+ - 'spec/**/*.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.5
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in movie_cleaner.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ movie_cleaner (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ jaro_winkler (1.5.3)
13
+ method_source (0.9.2)
14
+ parallel (1.17.0)
15
+ parser (2.6.3.0)
16
+ ast (~> 2.4.0)
17
+ pry (0.12.2)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ rainbow (3.0.0)
21
+ rake (10.5.0)
22
+ rspec (3.8.0)
23
+ rspec-core (~> 3.8.0)
24
+ rspec-expectations (~> 3.8.0)
25
+ rspec-mocks (~> 3.8.0)
26
+ rspec-core (3.8.2)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-expectations (3.8.4)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-mocks (3.8.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-support (3.8.2)
35
+ rubocop (0.74.0)
36
+ jaro_winkler (~> 1.5.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.6)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 1.7)
42
+ rubocop-rspec (1.35.0)
43
+ rubocop (>= 0.60.0)
44
+ ruby-progressbar (1.10.1)
45
+ unicode-display_width (1.6.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+ x64-mingw32
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 2.0)
53
+ movie_cleaner!
54
+ pry (~> 0.12)
55
+ rake (~> 10.0)
56
+ rspec (~> 3.0)
57
+ rubocop (~> 0.74.0)
58
+ rubocop-rspec (~> 1.35.0)
59
+
60
+ BUNDLED WITH
61
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Niels Saurer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # MovieCleaner
2
+ Removes media files where there already is a higher resolution
3
+
4
+ ## Prerequisites
5
+
6
+ * ruby
7
+ * A movie library with sub-folders per movie containing different quality files of the movie
8
+ * Movie files must have the resolution in the filename (e.g. `It (2017) - 1080p.mkv`)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'movie_cleaner'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install movie_cleaner
25
+
26
+ ## Usage
27
+
28
+ `movie_cleaner [options]`
29
+
30
+ | option | description | example |
31
+ |-|-| - |
32
+ |`-v`| verbose - omitting this results in a completely `\| bash`-able output of `rm` commands. | |
33
+ |`-d,--directory DIRECTORY`| Directory which contains all other movie folders | `-d /home/user/media/movies` |
34
+ |`-r,--resolutions res1,res2`| Comma-separated list of resolutions in order of priority | `-r 1080p,720p` |
35
+
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`.
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/skius/movie_cleaner.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'movie_cleaner'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
data/bin/movie_cleaner ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+
6
+ require 'optparse'
7
+ require 'ostruct'
8
+
9
+ require 'movie_cleaner'
10
+
11
+ options = OpenStruct.new
12
+ OptionParser.new do |opt|
13
+ opt.on('-v') { |o| options.verbose = o }
14
+ opt.on('-d', '--directory DIRECTORY',
15
+ 'The base path for all movie files') { |o| options.base_path = o }
16
+ opt.on('-r', '--resolutions 1080p,720p', Array,
17
+ 'The wanted resolutions in order (Default: 1080p,720p') { |o| options.resolutions = o }
18
+ end.parse!
19
+
20
+ movie_cleaner = MovieCleaner::Cleaner.new(options.base_path, options.verbose, options.resolutions)
21
+ puts movie_cleaner.sub_par_files
22
+ movie_cleaner.print_rm_commands
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MovieCleaner
4
+ # Cleaner prints commands to remove all unwanted movie files in a directory
5
+ class Cleaner
6
+ def initialize(base_path, verbose = false, possible_resolutions = nil)
7
+ @base_path = base_path
8
+ @verbose = verbose
9
+ @possible_resolutions = possible_resolutions || %w[1080p 720p]
10
+ end
11
+
12
+ def sub_par_files
13
+ sub_par_files_per_movie.flat_map do |movie, files|
14
+ next if files.empty?
15
+
16
+ files.map { |file| full_path(movie, file) }
17
+ end.compact
18
+ end
19
+
20
+ def print_rm_commands
21
+ sub_par_files_per_movie.each do |movie, files|
22
+ vputs "Found sub-par files for movie '#{movie}':"
23
+ print_rm_commands_for_files(movie, files)
24
+ vputs ''
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def print_rm_commands_for_files(movie, files)
31
+ files.each do |f|
32
+ puts "rm '#{full_path(movie, f)}'"
33
+ end
34
+ end
35
+
36
+ def sub_par_files_per_movie
37
+ movie_files.map do |movie, files|
38
+ current_sub_par_files = []
39
+ @possible_resolutions.each do |resolution|
40
+ next if files.none? { |f| f.include?(resolution) }
41
+
42
+ current_sub_par_files = files.reject { |f| f.include?(resolution) }
43
+ break
44
+ end
45
+ next if current_sub_par_files.empty?
46
+
47
+ [movie, current_sub_par_files]
48
+ end.compact.to_h
49
+ end
50
+
51
+ def movie_files
52
+ @movie_files ||= Dir["#{@base_path}/*"].map do |dir|
53
+ [
54
+ File.basename(dir),
55
+ Dir["#{dir}/*.{mkv,mov,mp4}"].map { |f| File.basename(f) }
56
+ ]
57
+ end.to_h
58
+ end
59
+
60
+ def full_path(movie, file)
61
+ "#{@base_path}/#{movie}/#{file}"
62
+ end
63
+
64
+ def vputs(*args)
65
+ puts args if @verbose
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MovieCleaner
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'movie_cleaner/version'
4
+ require 'movie_cleaner/cleaner'
5
+
6
+ module MovieCleaner
7
+ class Error < StandardError; end
8
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'movie_cleaner/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'movie_cleaner'
9
+ spec.version = MovieCleaner::VERSION
10
+ spec.authors = ['Niels Saurer']
11
+ spec.email = ['me@nielssaurer.com']
12
+
13
+ spec.summary = 'Removes media files where there already is a higher resolution'
14
+ spec.homepage = 'https://github.com/skius/movie-cleaner'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/skius/movie-cleaner'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'bin'
28
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'pry', '~> 0.12'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ spec.add_development_dependency 'rubocop', '~> 0.74.0'
36
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.35.0'
37
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: movie_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Niels Saurer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.74.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.74.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.35.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.35.0
97
+ description:
98
+ email:
99
+ - me@nielssaurer.com
100
+ executables:
101
+ - console
102
+ - movie_cleaner
103
+ - setup
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".editorconfig"
108
+ - ".gitignore"
109
+ - ".rspec"
110
+ - ".rubocop.yml"
111
+ - ".ruby-version"
112
+ - ".travis.yml"
113
+ - Gemfile
114
+ - Gemfile.lock
115
+ - LICENSE.txt
116
+ - README.md
117
+ - Rakefile
118
+ - bin/console
119
+ - bin/movie_cleaner
120
+ - bin/setup
121
+ - lib/movie_cleaner.rb
122
+ - lib/movie_cleaner/cleaner.rb
123
+ - lib/movie_cleaner/version.rb
124
+ - movie_cleaner.gemspec
125
+ homepage: https://github.com/skius/movie-cleaner
126
+ licenses:
127
+ - MIT
128
+ metadata:
129
+ allowed_push_host: https://rubygems.org
130
+ homepage_uri: https://github.com/skius/movie-cleaner
131
+ source_code_uri: https://github.com/skius/movie-cleaner
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.0.3
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Removes media files where there already is a higher resolution
151
+ test_files: []