comiv 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ee66a34bb8803b146b502d42fa69de8a07cb070f1946b1406c5208ad544e8b0
4
+ data.tar.gz: caa2057f8955908d97a9e503dde9c6d217205d087e201f11fbc4ba5664d357bc
5
+ SHA512:
6
+ metadata.gz: 60eb71226a3561c19686eedbce07c9d727749ea1ab837ae2c7eb093947fd2360b17a18f847c593254cb22b88fcb0e1d120868f183c6d6117d9ae6f91cd171e46
7
+ data.tar.gz: 3fc5550c2dce262d473f4c099d447fad0502a8dfa8a9a978432293bfcea3914bbc54b4749715f64a151c87d47de0f20868e666644e9dbc7c669fed7a505632d3
@@ -0,0 +1,15 @@
1
+ # Ruby
2
+ /.bundle/
3
+ /Gemfile.lock
4
+ /vendor/
5
+ /*.gem
6
+
7
+ # RSpec
8
+ /.rspec_status
9
+
10
+ # Comiv
11
+ /.comiv/
12
+ /stored/
13
+
14
+ # ffmpeg
15
+ ffmpeg2pass*
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at exrecord160@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in compv.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 yuitoku
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.
@@ -0,0 +1,45 @@
1
+ # ComIV
2
+ Compress image and video.
3
+ Use FFmpeg and Tinify API.
4
+
5
+ ## Extension
6
+ Following are supported extensions.
7
+
8
+ ### Photo
9
+ - jpg
10
+
11
+ ### Video
12
+ - mp4
13
+
14
+ ## Requirement
15
+ - FFmpeg
16
+ - Tinify API key
17
+
18
+ ## Install
19
+ ```
20
+ gem install comiv
21
+ ```
22
+
23
+ ## Usage
24
+ Add key and store photo or video to stored directory. When ran, compressed file is created in stored/compress directory.
25
+ ```
26
+ Usage:
27
+ comiv init
28
+ comiv run
29
+ comiv config (--add-key KEY | --delete-key | --show-count)
30
+ comiv -h | --help
31
+ comiv -v | --version
32
+
33
+ Options:
34
+ init Create .comiv and stored directory.
35
+ run Compress image and video files in stored directory.
36
+ config Set comiv configuration.
37
+ --add-key KEY Add tinify api key.
38
+ --delete-key Delete tinify api key.
39
+ --show-count Show compresstion count this month. however, it needs to be executed once.
40
+ -h --help Show help.
41
+ -v --version Show version.
42
+ ```
43
+
44
+ ## Licence
45
+ [MIT License](https://github.com/yuitoku/compv/blob/master/LICENSE.txt) @ Yuitoku
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "compv"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "comiv/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "comiv"
8
+ spec.version = Comiv::VERSION
9
+ spec.authors = ["yuitoku"]
10
+ spec.email = ["exrecord160@gmail.com"]
11
+
12
+ spec.summary = %q{Compress photo and video.}
13
+ spec.description = %q{Compress photo and video. Use ffmpeg and tinify API for compress.}
14
+ spec.homepage = "https://github.com/yuitoku/comiv"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables << "comiv"
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_runtime_dependency "tinify", "~> 1.5"
30
+ spec.add_runtime_dependency "docopt", "~> 0.6"
31
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "comiv"
3
+
4
+ Comiv.check_argument
@@ -0,0 +1,143 @@
1
+ require "yaml"
2
+
3
+ require "comiv/version"
4
+ require "comiv/config"
5
+ require "comiv/docopt"
6
+ require "comiv/ffmpeg"
7
+ require "comiv/tinify"
8
+
9
+ module Comiv
10
+ class << self
11
+ def check_argument
12
+ args = Comiv::Docopt.docopt
13
+ if args.is_a?(Hash)
14
+ check_command(args)
15
+ else
16
+ puts args
17
+ exit(0)
18
+ end
19
+ end
20
+
21
+ def check_command(args)
22
+ command = args.find{ |key, value| value }.first
23
+ command == "config" ? Comiv.send(command, args) : Comiv.send(command)
24
+ end
25
+
26
+ def init
27
+ create_directory
28
+ create_config
29
+ end
30
+
31
+ def run
32
+ config_exist?
33
+ compress_exist?
34
+ find_image(load_config)
35
+ find_video
36
+ end
37
+
38
+ def config(options)
39
+ options.each do |key, value|
40
+ case key
41
+ when "--add-key" then add_key(value) if value
42
+ when "--delete-key" then delete_key if value
43
+ when "--show-count" then show_count if value
44
+ end
45
+ end
46
+ end
47
+
48
+ def create_directory
49
+ DIRECTORIES.each do |dir|
50
+ if File.exist?(dir)
51
+ puts "Already #{dir}"
52
+ else
53
+ Dir.mkdir(dir)
54
+ puts "Create #{dir}"
55
+ end
56
+ end
57
+ end
58
+
59
+ def create_config
60
+ if File.exist?(CONFIG_FILE)
61
+ puts "Already #{CONFIG_FILE}"
62
+ else
63
+ File.write(CONFIG_FILE, CONFIG)
64
+ puts "Create #{CONFIG_FILE}"
65
+ end
66
+ end
67
+
68
+ def add_key(value)
69
+ config_exist?
70
+ write_config(KEY, value)
71
+ reset_count
72
+ puts "Add tinify api key."
73
+ end
74
+
75
+ def delete_key
76
+ config_exist?
77
+ write_config(KEY)
78
+ reset_count
79
+ puts "Delete tinify api key."
80
+ end
81
+
82
+ def show_count
83
+ config_exist?
84
+ compression_count = load_config.fetch(COMPRESSION_COUNT)
85
+ puts "Compression count is #{compression_count}"
86
+ end
87
+
88
+ def config_exist?
89
+ unless File.exist?(CONFIG_FILE)
90
+ puts "Nothing #{CONFIG_FILE}. please `comiv init` command."
91
+ exit(0)
92
+ end
93
+ end
94
+
95
+ def compress_exist?
96
+ unless File.exist?("#{STORED_DIRECTORY}/#{COMPRESS_DIRECTORY}")
97
+ puts "Nothing #{STORED_DIRECTORY}/#{COMPRESS_DIRECTORY}. please `comiv init` command."
98
+ exit(0)
99
+ end
100
+ end
101
+
102
+ def write_config(key, replacement = "nil")
103
+ File.write(CONFIG_FILE, File.read(CONFIG_FILE).gsub(/#{key}:.*/, "#{key}: #{replacement}"))
104
+ end
105
+
106
+ def reset_count
107
+ File.write(CONFIG_FILE, File.read(CONFIG_FILE).gsub(/#{COMPRESSION_COUNT}:.*/, "#{COMPRESSION_COUNT}: 0"))
108
+ end
109
+
110
+ def load_config
111
+ YAML.load_file(CONFIG_FILE)
112
+ end
113
+
114
+ def find_image(config)
115
+ puts "Checking image..."
116
+ images = Dir.glob("#{STORED_DIRECTORY}/*.#{IMAGE_EXTENSION}")
117
+ images.each.with_index(1) do |image, index|
118
+ puts "Nothing image." if image.nil?
119
+ puts "#{index}: #{image}"
120
+ index == images.size ?
121
+ write_config(COMPRESSION_COUNT, Comiv::Tinify.compress_image(image, config["key"])) :
122
+ Comiv::Tinify.compress_image(image, config["key"])
123
+ end
124
+
125
+ show_count
126
+ puts "Completed."
127
+ end
128
+
129
+ def find_video
130
+ puts "Checking video..."
131
+ videos = Dir.glob("#{STORED_DIRECTORY}/*.#{VIDEO_EXTENSION}")
132
+ videos.each.with_index(1) do |video, index|
133
+ puts "Nothind video." if video.nil?
134
+ puts "#{index}: #{video}"
135
+ Comiv::FFmpeg.compress_video(video)
136
+ end
137
+
138
+ File.delete("ffmpeg2pass-0.log")
139
+ File.delete("ffmpeg2pass-0.log.mbtree")
140
+ puts "Complted."
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,15 @@
1
+ module Comiv
2
+ CONFIG_DIRECTORY = ".comiv"
3
+ STORED_DIRECTORY = "stored"
4
+ COMPRESS_DIRECTORY = "compress"
5
+ DIRECTORIES = [CONFIG_DIRECTORY, STORED_DIRECTORY, "#{STORED_DIRECTORY}/#{COMPRESS_DIRECTORY}"]
6
+ CONFIG_FILE = ".comiv/config.yml"
7
+ IMAGE_EXTENSION = "jpg"
8
+ VIDEO_EXTENSION = "mp4"
9
+ KEY = "key"
10
+ COMPRESSION_COUNT = "compression_count"
11
+ CONFIG = <<"CONTENT"
12
+ key: nil
13
+ compression_count: 0
14
+ CONTENT
15
+ end
@@ -0,0 +1,29 @@
1
+ require "docopt"
2
+
3
+ module Comiv::Docopt
4
+ def self.docopt
5
+ doc = <<DOCOPT
6
+ Usage:
7
+ comiv init
8
+ comiv run
9
+ comiv config (--add-key KEY | --delete-key | --show-count)
10
+ comiv -h | --help
11
+ comiv -v | --version
12
+
13
+ Options:
14
+ init Create .comiv and stored directory.
15
+ run Compress image and video files in stored directory.
16
+ config Set comiv configuration.
17
+ --add-key KEY Add tinify api key.
18
+ --delete-key Delete tinify api key.
19
+ --show-count Show compresstion count this month. however, it needs to be executed once.
20
+ -h --help Show help.
21
+ -v --version Show version.
22
+ DOCOPT
23
+ begin
24
+ Docopt::docopt(doc)
25
+ rescue Docopt::Exit => e
26
+ e.message
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "config"
2
+
3
+ module Comiv::FFmpeg
4
+ VCODEC = "libx264"
5
+ ACODEC = "aac"
6
+ BITRATE = "2500k"
7
+ NULL = "/dev/null"
8
+
9
+ def self.compress_video(video)
10
+ directory = File.dirname(video)
11
+ file = File.basename(video)
12
+ `ffmpeg -i #{video} -c:v #{VCODEC} -an -pass 1 -f mp4 -loglevel error -y #{NULL}`
13
+ `ffmpeg -i #{video} -c:v #{VCODEC} -c:a #{ACODEC} -pass 2 -loglevel error -b:v #{BITRATE} -y #{directory}/#{Comiv::COMPRESS_DIRECTORY}/#{file}`
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require "tinify"
2
+ require_relative "config"
3
+
4
+ module Comiv::Tinify
5
+ Tinify.key = nil
6
+
7
+ class << self
8
+ def set_key(key)
9
+ Tinify.key = key
10
+ end
11
+
12
+ def compress_image(image, key)
13
+ set_key(key)
14
+ directory = File.dirname(image)
15
+ file = File.basename(image)
16
+ source = Tinify.from_file("#{image}")
17
+ source.to_file("#{directory}/#{Comiv::COMPRESS_DIRECTORY}/#{file}")
18
+ Tinify.compression_count
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Comiv
2
+ VERSION = "1.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comiv
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yuitoku
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-04 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tinify
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: docopt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ description: Compress photo and video. Use ffmpeg and tinify API for compress.
84
+ email:
85
+ - exrecord160@gmail.com
86
+ executables:
87
+ - comiv
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - comiv.gemspec
100
+ - exe/comiv
101
+ - lib/comiv.rb
102
+ - lib/comiv/config.rb
103
+ - lib/comiv/docopt.rb
104
+ - lib/comiv/ffmpeg.rb
105
+ - lib/comiv/tinify.rb
106
+ - lib/comiv/version.rb
107
+ homepage: https://github.com/yuitoku/comiv
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.3
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Compress photo and video.
131
+ test_files: []