helpema 2.1.200129 → 3.2.210924

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d18fa86fd912cfcc45ebb9efbdae0f9ae2a207399660fca0b3f0e3ce3b2bad64
4
- data.tar.gz: c18e1447a10e90e878644d982e1578965309264eae84c7badc3676c31e1c018b
3
+ metadata.gz: 958027b0a2546243bae724c0a543197d7632385c0f9049d8e59ed53349b18f4d
4
+ data.tar.gz: d57d402890e736b580fc052c66308df90a6e29202d467cd4e26714ad11b64331
5
5
  SHA512:
6
- metadata.gz: e7b98dfb0588da2070870131947cff69d9777d586fe72a7d513e3156c3f78b405e9d513d195ae18a952d099894965c44d0ba06fddd605825c6f06fe86297f604
7
- data.tar.gz: f9cedadc0afe83aa718c637fe017555f50931023343ebc24519742b8cc17f89fe87367f4de4eafbfdcf30305b66ce4e0d23c8355ad344e62efa89e3827d42239
6
+ metadata.gz: dd576603c81835d9610eac6d15487d25d82491eec8de717fcfbe6a16c51c865968d8ac259dddc45e02f2148f7653c6fa5b9ed5be55eb05c878b184df3bc5cdec
7
+ data.tar.gz: 65f36c77c56ded75225ecd35fe6f6f4bb3581aeff1c3ce1de855f423e65de78e3e69d1131a63e7b18760b1224f27eda14a33c0a41e40e55bef67d8c0cb89b488
data/README.md CHANGED
@@ -1,90 +1,176 @@
1
- # helpema
1
+ # Helpema
2
2
 
3
- * [VERSION 2.1.200129](https://github.com/carlosjhr64/helpema/releases)
4
- * [github](https://github/carlosjhr64/helpema)
5
- * [rubygems](https://rubygems/gems/helpema)
3
+ * [VERSION 3.2.210924](https://github.com/carlosjhr64/helpema/releases)
4
+ * [github](https://github.com/carlosjhr64/helpema)
5
+ * [rubygems](https://rubygems.org/gems/helpema)
6
6
 
7
7
  ## DESCRIPTION:
8
8
 
9
9
  Meant to be an eclectic collection of useful single functions and wrappers.
10
10
 
11
- Wrappers:
12
-
13
- * ssss-split
14
- * ssss-combine
15
- * zbarcam
16
- * youtube-dl -j
17
-
18
- Functions:
19
-
20
- * requires("gemname version",...)
21
- * params(arg,...){|h Hash[Class,Obj]|...}
22
-
23
- More later.
24
-
25
- ## SYNOPSIS:
26
-
27
- require 'helpema'
28
- include HELPEMA
29
-
30
- Helpema.requires <<-GEMS
31
- awesome_print ~>1.8
32
- base_convert ~>4.0
33
- entropia ~>0.1
34
- GEMS
35
- #=> ["awesome_print", "base_convert", "entropia"]
36
- # Returns the list of loaded gems.
37
- # For those quick little scripts one writes in one's bin
38
- # that annoyingly keep falling out of maintainance... right?
39
-
40
- s0 = s1 = i = f0 = f1 = r = nil
41
- Helpema.params(1, 2.0, 3, "Five", /Six/, "Seven", /Eight/) do |params|
42
- s0 = params[String][0]
43
- s1 = params[String][1]
44
- i = params[Integer][0]
45
- f0 = params[Float][0]
46
- f1 = params[Float][1]
47
- r = params[Regexp][0]
48
- end
49
- s0 #=> "Five"
50
- s1 #=> "Seven"
51
- i #=> 1
52
- f0 #=> 2.0
53
- f1 #=> nil
54
- r #=> /Six/
55
-
56
- SSSS.split("Top Secret!", threshold: 2, shares: 3)
57
- #~> ^\["1-\h+", "2-\h+", "3-\h+"\]$
58
- # Note that the split has random outputs on the same inputs.
59
-
60
- SSSS.combine("3-055562917c41e68c6ab2c8", "1-27bf3cbfe8d2c25c7e8928")
61
- #=> Top Secret!
62
- # Pregenerated splits combine to reproduce the secret.
63
-
64
- list = []
65
- url = 'https://www.youtube.com/watch?v=u4oK3ZSccZI'
66
- YouTubeDL.json(url){|json| list.push json}
67
- # The url was for just one video
68
- list.length #=> 1
69
- json = list[0]
70
- json['title'] #=> "Fortnite Easy Last Ten"
71
-
72
- ZBar.cam( timeout=3 ) # Reads qrcodes on camera.
73
- ZBar.screen # Reads qrcodes on screen.
11
+ Featured method: `requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
74
12
 
75
13
  ## INSTALL:
76
14
 
77
- $ sudo gem install helpema
15
+ ```console
16
+ $ gem install helpema
17
+ ```
78
18
 
79
- ## FEATURES:
19
+ ## SYNOPSIS:
80
20
 
81
- * Autoloaded: no need to pick and choose which library component to require.
21
+ ### requires
22
+ ```ruby
23
+ require 'helpema'
24
+ include Helpema
25
+ using Helpema
26
+
27
+ ### requires ###
28
+ # Ensure ruby's and helpema's version.
29
+ # Returns the list of loaded gems.
30
+ # For those quick little scripts one writes in one's bin
31
+ # that annoyingly keep falling out of maintainance... right?
32
+ requires'
33
+ ruby ~>3.0
34
+ helpema ~>3.1
35
+ base_convert ~>4.0
36
+ entropia ~>0.1'
37
+ #=> ["base_convert", "entropia"]
38
+ ```
39
+ ### String#satisfies?
40
+ ```ruby
41
+ ### String#satisfies? ###
42
+ # Uses Gem::Requirement and Gem::Version to check version strings.
43
+ '1.2.3'.satisfies? '~>1.1' #=> true
44
+ '1.2.3'.satisfies? '~>1.3' #=> false
45
+ ```
46
+ ### run_command
47
+ ```ruby
48
+ ### run_command ###
49
+ # Automates pipe creation to a system command.
50
+ # See the code for all available features.
51
+ run_command('date',{d: 'Dec 31, 2020'}) #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
52
+ ```
53
+ ### define_command
54
+ ```ruby
55
+ ### define_command ###
56
+ # Creates a method out of a system command.
57
+ # See the code for all available features.
58
+ define_command(:date, cmd: 'date', usage: {d: nil}, synonyms: {string: :d})
59
+ date(string: 'Dec 31, 2020') #=> "Thu Dec 31 12:00:00 AM PST 2020\n"
60
+ ```
61
+ ### to_arg
62
+ ```ruby
63
+ ### to_arg ###
64
+ # A helper function to do system command calls.
65
+ to_arg :q, true #=> "-q"
66
+ to_arg :quiet, true #=> "--quiet"
67
+ to_arg :verbose, false #=> nil
68
+ to_arg :f, '/path-to/file' #=> ["-f", "/path-to/file"]
69
+ to_arg :geo=, '10x20' #=> "--geo=10x20"
70
+ to_arg :arg0, 'Hello World' #=> "Hello World"
71
+ ```
72
+ ### Hash#to_args
73
+ ```ruby
74
+ ### Hash#to_args ###
75
+ { q: true,
76
+ quiet: true,
77
+ verbose: false,
78
+ f: '/path-to/file',
79
+ :geo= => '10x20',
80
+ arg0: 'Hello World' }.to_args
81
+ #=> ["-q", "--quiet", "-f", "/path-to/file", "--geo=10x20", "Hello World"]
82
+ ```
83
+ ### Array#classify
84
+ ```ruby
85
+ ### Array#classify ###
86
+ # Groups items in Array by class.
87
+ [1, 2.0, :Three, 'Four', /Five/, :Six, 'Seven'].classify
88
+ #=> {Integer=>[1], Float=>[2.0], Symbol=>[:Three, :Six], String=>["Four", "Seven"], Regexp=>[/Five/]}
89
+ ```
90
+ ### SSSS.split
91
+ ```ruby
92
+ ### SSSS.split ####
93
+ SSSS.split(secret: "Top Secret!", threshold: 2, shares: 3)
94
+ #~> ^\["1-\h+", "2-\h+", "3-\h+"\]$
95
+ # Note that the split has random outputs on the same inputs.
96
+ ```
97
+ ### SSS.combine
98
+ ```ruby
99
+ #### SSSS.combine ###
100
+ # Pregenerated splits combine to reproduce the secret.
101
+ SSSS.combine(secrets: ["3-055562917c41e68c6ab2c8", "1-27bf3cbfe8d2c25c7e8928"],
102
+ threshold: 2)
103
+ #=> "Top Secret!"
104
+ ```
105
+ ### YouTubeDL.json
106
+ ```ruby
107
+ ### YouTubeDL.json ###
108
+ list = []
109
+ url = 'https://www.youtube.com/watch?v=u4oK3ZSccZI'
110
+ YouTubeDL.json(url){|json| list.push json}
111
+ # The url was for just one video
112
+ list.length #=> 1
113
+ json = list[0]
114
+ json['title'] #=> "Fortnite Easy Last Ten"
115
+ ```
116
+ ### YouTubeDL.mp3(url, output: '%(id)s.%(ext)s')
117
+ ### FFMPEG.hash(filename, digest: 'sha160')
118
+ ### ZBar.screen
119
+ ```ruby
120
+ ### ZBar.screen ###
121
+ # Reads qrcodes on screen.
122
+ string_or_nil = ZBar.screen
123
+ ```
124
+ ### ZBar.cam
125
+ ```ruby
126
+ ### ZBar.cam ###
127
+ # Reads qrcodes from camera.
128
+ # You may want to wrap this one in a Timeout block.
129
+ # string = ZBar.cam
130
+ ```
131
+ ### GPG.encrypt and GPG.decrypt
132
+ ```ruby
133
+ ### GPG Symmetric ###
134
+ ## String to String
135
+ encrypted = GPG.encrypt(passphrase: '<Secret>', string: '<Plain Text>')
136
+ decrypted = GPG.decrypt(passphrase: '<Secret>', string: encrypted)
137
+ #=> "<Plain Text>"
138
+ ## File to File
139
+ # Got a text file...
140
+ `md5sum tmp/text.txt` #~> ^d27b3111fdeb72f2862909c216214bc1
141
+ # gpg wont overwrite, so need to remove existing...
142
+ File.exist?(_='tmp/text.enc') and File.unlink(_)
143
+ File.exist?(_='tmp/text.dec') and File.unlink(_)
144
+ # Encrypt text file...
145
+ GPG.encrypt(passphrase: '<Secret>', input: 'tmp/text.txt', output: 'tmp/text.enc') #=> ""
146
+ # Decrypt encrypted file...
147
+ GPG.decrypt(passphrase: '<Secret>', input: 'tmp/text.enc', output: 'tmp/text.dec') #=> ""
148
+ # Decrypted file should match...
149
+ `md5sum tmp/text.dec` #~> ^d27b3111fdeb72f2862909c216214bc1
150
+ ## IO to IO
151
+ require 'stringio'
152
+ pio = StringIO.new '<Plain>'
153
+ eio = StringIO.new ''
154
+ dio = StringIO.new ''
155
+ GPG.encrypt(passphrase: '<Secret>', ioin: pio, ioout: eio)
156
+ eio.rewind
157
+ GPG.decrypt(passphrase: '<Secret>', ioin: eio, ioout: dio)
158
+ dio.string #=> "<Plain>"
159
+ ```
160
+
161
+ ## TROUBLESHOOTING:
162
+
163
+ Command version mismatch
164
+ : set `Helpema::WRAPPER.version = "your.version"` or just nil it.
165
+
166
+ More documentation
167
+ : see [sig/helpema.rb](sig/helpema.rbs) for the expected method signatures.
82
168
 
83
169
  ## LICENSE:
84
170
 
85
171
  (The MIT License)
86
172
 
87
- Copyright (c) 2020 carlosjhr64
173
+ Copyright (c) 2021 CarlosJHR64
88
174
 
89
175
  Permission is hereby granted, free of charge, to any person obtaining
90
176
  a copy of this software and associated documentation files (the
@@ -0,0 +1,23 @@
1
+ module Helpema
2
+ module FFMPEG
3
+ extend Helpema
4
+
5
+ FFMPEG.define_command(:_hash,
6
+ cmd: 'ffmpeg',
7
+ usage: {arg0: '-i',
8
+ arg1: nil,
9
+ arg2: '-f',
10
+ arg3: 'hash',
11
+ arg4: '-hash',
12
+ arg5: nil,
13
+ arg6: '-'},
14
+ synonyms: {filename: :arg1, digest: :arg5},
15
+ exception: 'ffmpeg failed',
16
+ err: '/dev/null')
17
+ def hash(filename, digest:'sha160')
18
+ FFMPEG._hash(filename:filename, digest:digest).strip.split('=').last
19
+ end
20
+
21
+ extend self
22
+ end
23
+ end
@@ -0,0 +1,86 @@
1
+ module Helpema
2
+ module GPG
3
+ extend Helpema
4
+ class << self; attr_accessor :version; end
5
+ GPG.version = '^gpg \\(GnuPG\\) 2\.[234]\.' # version as of this writing is 2.2.27
6
+
7
+ GPG.define_command(:cryptor,
8
+ cmd: 'gpg', version: GPG.version,
9
+ usage: {
10
+ quiet: true,
11
+ batch: true,
12
+ 'passphrase-fd': 0,
13
+ output: nil,
14
+ symmetric: nil,
15
+ decrypt: nil,
16
+ arg0: nil,
17
+ },
18
+ synonyms: {
19
+ input: :arg0,
20
+ },
21
+ mode: 'w+',
22
+ exception: 'gpg failed'
23
+ ) do |pipe, options, blk|
24
+ passphrase, string, ioin, ioout =
25
+ options.fetch_values(:passphrase, :string, :ioin, :ioout)
26
+ pipe.puts passphrase
27
+ Thread.new do
28
+ if string
29
+ pipe.write string
30
+ elsif ioin
31
+ while c = ioin.getbyte
32
+ pipe.putc c
33
+ end
34
+ end
35
+ pipe.close_write
36
+ end
37
+ if ioout
38
+ while c = pipe.getbyte
39
+ ioout.putc c
40
+ end
41
+ else
42
+ pipe.read
43
+ end
44
+ end
45
+
46
+ def encrypt(passphrase:,
47
+ string:nil,
48
+ output:nil,
49
+ input:nil,
50
+ ioin:nil,
51
+ ioout:nil)
52
+ unless [string,input,ioin].count{_1} == 1
53
+ raise "Need only one of string, input, or ioin"
54
+ end
55
+ raise "Can't have both output and ioout" if output and ioout
56
+ GPG.cryptor(symmetric: true,
57
+ passphrase: passphrase,
58
+ string: string,
59
+ input: input,
60
+ output: output,
61
+ ioin: ioin,
62
+ ioout: ioout)
63
+ end
64
+
65
+ def decrypt(passphrase:,
66
+ string:nil,
67
+ output:nil,
68
+ input:nil,
69
+ ioin:nil,
70
+ ioout:nil)
71
+ unless [string,input,ioin].count{_1} == 1
72
+ raise "Need only one of string, input, or ioin"
73
+ end
74
+ raise "Can't have both output and ioout" if output and ioout
75
+ GPG.cryptor(decrypt: true,
76
+ passphrase: passphrase,
77
+ string: string,
78
+ input: input,
79
+ output: output,
80
+ ioin: ioin,
81
+ ioout: ioout)
82
+ end
83
+
84
+ extend self
85
+ end
86
+ end
@@ -1,21 +1,118 @@
1
- module HELPEMA
2
1
  module Helpema
2
+ refine ::String do
3
+ def satisfies?(*reqs)
4
+ Gem::Requirement.new(*reqs).satisfied_by? Gem::Version.new(self)
5
+ end
6
+ end
7
+ refine ::Hash do
8
+ def to_args(usage:nil, synonyms:nil)
9
+ # create separate args from self with the translated synonyms
10
+ args = self.transform_keys(synonyms.to_h)
11
+ # pad usage's defaults to args
12
+ usage&.each{|key,default| args[key]=default unless args.has_key? key}
13
+ # order might be important so enforce usage
14
+ args = usage&.map{|k,v|[k,args[k]]} || args.to_a
15
+ # convert key,value tuples to final list of args
16
+ args.map!(&:to_arg)
17
+ # get rid of nil
18
+ args.compact!
19
+ # ...and finally flatten!
20
+ args.flatten!
21
+ return args
22
+ end
23
+ end
24
+ refine ::Array do
25
+ def classify(hash: Hash.new{|h,k|h[k]=[]})
26
+ self.each{|v| hash[v.class] << v}
27
+ return hash
28
+ end
29
+ def to_arg
30
+ Helpema.to_arg(*self)
31
+ end
32
+ end
33
+ refine ::Symbol do
34
+ def to_flag
35
+ return nil if self[-1].match?(/\d/) # like :arg0
36
+ (self.length > 1)? "--#{self}": "-#{self}" # like --verbose or -V
37
+ end
38
+ end
39
+ using Helpema
40
+
41
+ def to_arg(key,value)
42
+ # keep only keys with value(no false or nil)
43
+ return nil unless value
44
+ # assume nil0/--long/-short
45
+ key = key.to_flag
46
+ if key
47
+ return key if value==true # a flag
48
+ return "#{key}#{value}" if key[-1]=='=' # joined key=value
49
+ return [key,value.to_s]
50
+ end
51
+ # It's a Nth arg, like arg0...
52
+ return value.to_s
53
+ end
54
+
55
+ def run_command(cmd, options={},
56
+ usage:nil, synonyms:nil, mode:'r',
57
+ exception:nil, forward_pass:nil, **popt, &blk)
58
+ args,ret = options.to_args(usage:usage,synonyms:synonyms),nil
59
+ $stderr.puts "#{cmd} #{args.join(' ')}" if $DEBUG
60
+ IO.popen([cmd, *args], mode, **popt) do |pipe|
61
+ ret = forward_pass ? forward_pass.call(pipe, options, blk) :
62
+ blk ? blk.call(pipe) :
63
+ pipe.read
64
+ end
65
+ (exception.nil? or $?.exitstatus==0)? ret : raise(exception)
66
+ end
67
+
68
+ def define_command(name,
69
+ cmd: name.to_s, version: nil, v: nil,
70
+ usage: nil, synonyms: nil,
71
+ mode: 'r',exception: nil,
72
+ **popt, &forward_pass)
73
+
74
+ # which version? --version or -v
75
+ if version and not `#{cmd} --version`.strip.match?(version)
76
+ raise "`#{cmd} --version` !~ #{version}"
77
+ end
78
+ if v and not `#{cmd} -v`.strip.match?(v)
79
+ raise "`#{cmd} -v` !~ #{v}"
80
+ end
81
+
82
+ define_method(name) do |**options, &blk|
83
+ run_command(cmd, options,
84
+ usage:usage, synonyms:synonyms, mode:mode,
85
+ exception:exception, forward_pass:forward_pass, **popt, &blk)
86
+ end
87
+ end
88
+
3
89
  def requires(*list)
4
90
  loaded = []
5
91
  list.each do |gems|
6
- gems.lines.each do |gemname_version|
7
- gemname, *version = gemname_version.split
8
- gem gemname, *version unless version.empty?
92
+ gems.lines.each do |gemname_reqs|
93
+ gemname, *reqs = gemname_reqs.split
94
+ next unless gemname
95
+ unless reqs.empty?
96
+ case gemname
97
+ when 'helpema'
98
+ unless VERSION.satisfies?(*reqs)
99
+ raise "helpema #{VERSION} not #{reqs.join(', ')}"
100
+ end
101
+ next
102
+ when 'ruby'
103
+ unless RUBY_VERSION.satisfies?(*reqs)
104
+ raise "ruby #{RUBY_VERSION} not #{reqs.join(', ')}"
105
+ end
106
+ next
107
+ else
108
+ gem gemname, *reqs
109
+ end
110
+ end
9
111
  require gemname and loaded.push gemname
10
112
  end
11
113
  end
12
- loaded
13
- end
14
-
15
- def params(*args)
16
- yield args.inject(Hash.new{|h,k|h[k]=[]}){|h,v|h[v.class].push(v) && h}
114
+ return loaded
17
115
  end
18
116
 
19
117
  extend self
20
118
  end
21
- end
data/lib/helpema/ssss.rb CHANGED
@@ -1,34 +1,46 @@
1
- require 'open3'
1
+ module Helpema
2
+ module SSSS
3
+ extend Helpema
4
+ class << self; attr_accessor :version; end
5
+ SSSS.version = 'Version: 0\.[567]\b' # version as of this writing is 0.5
2
6
 
3
- module HELPEMA
4
- module SSSS
5
- # Note how the function mirrors the command line options.
6
- def self.split(secret, t0=2, n0=3,
7
- t: t0, n: n0,
8
- threshold: t, shares: n,
9
- w: nil, s: nil, x: false,
10
- token: w, level: s, hexmode: x)
11
- pwds = nil
12
- command = "ssss-split -Q -t #{threshold} -n #{shares}"
13
- command << " -w #{token}" if token
14
- command << " -s #{level}" if level
15
- command << " -x" if hexmode
16
- Open3.popen3(command) do |stdin, stdout, stderr|
17
- stdin.puts secret
18
- stdin.close
19
- pwds = stdout.read.split("\n")
7
+ SSSS.define_command(:_split,
8
+ cmd: 'ssss-split', v: SSSS.version,
9
+ usage: {Q:true,t:2,n:3,w:nil,s:nil,x:false},
10
+ synonyms: {threshold: :t, shares: :n, token: :w, level: :s, hexmode: :x},
11
+ mode: 'w+', exception: 'ssss-split failed.',
12
+ err: [:child, :out]
13
+ ) do |pipe, options, blk|
14
+ pipe.puts options.fetch(:secret)
15
+ pipe.read.split.last(options[:shares])
20
16
  end
21
- return pwds
22
- end
23
-
24
- def self.combine(*pwds)
25
- pwd = ''
26
- Open3.popen3("ssss-combine -q -t #{pwds.length}") do |stdin, stdout, stderr|
27
- pwds.each{|p| stdin.puts p}
28
- stdin.close
29
- pwd = stderr.read.split("\n").last
17
+ def split(
18
+ secret:, threshold:,
19
+ shares:, token:nil,
20
+ level:nil,
21
+ hexmode:false
22
+ ) = SSSS._split(
23
+ secret:secret,
24
+ threshold:threshold,
25
+ shares:shares,
26
+ token:token,
27
+ level:level,
28
+ hexmode:hexmode)
29
+ SSSS.define_command(:_combine,
30
+ cmd: 'ssss-combine', v: SSSS.version,
31
+ usage: {Q:true,t:2,x:false}, synonyms: {threshold: :t, hexmode: :x},
32
+ mode: 'w+', exception: 'ssss-combine failed.',
33
+ err: [:child, :out]
34
+ ) do |pipe, options, blk|
35
+ secrets,n = options.fetch_values(:secrets,:threshold)
36
+ secrets.first(n).each{pipe.puts _1}
37
+ pipe.read.lines.last.chomp
38
+ end
39
+ def combine(secrets:, threshold:, hexmode:false)
40
+ raise 'Need threshold number of secrets.' unless secrets.size >= threshold
41
+ SSSS._combine(secrets:secrets, threshold:threshold, hexmode:hexmode)
30
42
  end
31
- return pwd
43
+
44
+ extend self
32
45
  end
33
46
  end
34
- end
@@ -1,20 +1,37 @@
1
1
  require 'json'
2
- require 'open3'
3
2
 
4
- module HELPEMA
5
- module YouTubeDL
6
- def self.json(url, pwd=nil)
7
- Open3.popen2e("youtube-dl -j '#{url}'") do |i, o|
8
- i.puts pwd if pwd
9
- i.close
10
- o.each do |line|
3
+ module Helpema
4
+ module YouTubeDL
5
+ extend Helpema
6
+ class << self; attr_accessor :version; end
7
+ YouTubeDL.version = '^202\d\.[01]\d\.[0123]\d$'
8
+
9
+ YouTubeDL.define_command(:_json,
10
+ cmd: 'youtube-dl', version: YouTubeDL.version,
11
+ usage: {j:true, arg0:nil}, synonyms: {url: :arg0},
12
+ err: '/dev/null'
13
+ ) do |pipe, options, blk|
14
+ pipe.each do |data|
11
15
  begin
12
- yield JSON.parse line
13
- rescue JSON::ParserError
14
- yield line
16
+ data = JSON.parse data
17
+ ensure
18
+ blk.call data
15
19
  end
16
20
  end
17
21
  end
22
+ def json(url, &blk) = YouTubeDL._json(url:url, &blk)
23
+
24
+ YouTubeDL.define_command(:_mp3,
25
+ cmd: 'youtube-dl', version: YouTubeDL.version,
26
+ usage: { output: nil,
27
+ 'extract-audio': true,
28
+ 'audio-format': true,
29
+ arg0: 'mp3',
30
+ arg1: nil },
31
+ synonyms: {url: :arg1},
32
+ err: '/dev/null')
33
+ def mp3(url, output:'%(id)s.%(ext)s') = YouTubeDL._mp3(url:url, output:output)
34
+
35
+ extend self
18
36
  end
19
37
  end
20
- end
data/lib/helpema/zbar.rb CHANGED
@@ -1,38 +1,46 @@
1
- require 'timeout'
2
1
  require 'tmpdir'
3
2
 
4
- module HELPEMA
5
- module ZBar
6
- def self.cam(timeout=3)
7
- raw = ''
8
- IO.popen('zbarcam --nodisplay --raw --prescale=800x800', 'r') do |io|
3
+ module Helpema
4
+ module ZBar
5
+ extend Helpema
6
+ class << self; attr_accessor :version, :screenshot; end
7
+ ZBar.version = '^0\.2[345]\b' # version as of this writing is 0.23
8
+ ZBar.screenshot = ['gnome-screenshot', '-f']
9
+
10
+ def snapshot(filename)
11
+ system(*ZBar.screenshot, filename)
12
+ end
13
+
14
+ ZBar.define_command(:_cam,
15
+ cmd: 'zbarcam',
16
+ version: ZBar.version,
17
+ usage: {raw:true,quiet:true,nodisplay:true, :prescale= => '800x800'},
18
+ synonyms: {prescale: :prescale=}
19
+ ) do |pipe, kw, blk|
9
20
  begin
10
- Timeout.timeout(timeout) do
11
- raw << io.gets
12
- while q = io.gets
13
- break if q=="\n"
14
- raw << q
15
- end
16
- raw.strip!
17
- end
18
- rescue Timeout::Error
19
- raw = nil
20
- $stderr.puts $!
21
+ pipe.gets.chomp # This is the return value!
21
22
  ensure
22
- Process.kill('INT', io.pid)
23
+ Process.kill('TERM', pipe.pid)
23
24
  end
24
25
  end
25
- raw
26
- end
26
+ def cam() = ZBar._cam()
27
27
 
28
- def self.screen
29
- raw = nil
30
- Dir.mktmpdir do |tmpdir|
31
- screenshot = File.join(tmpdir, "#{$$}.#{Time.now.to_f}.png")
32
- system "gnome-screenshot -f #{screenshot}"
33
- raw = `zbarimg -q --raw #{screenshot}`.strip
28
+ ZBar.define_command(:_img,
29
+ cmd: 'zbarimg',
30
+ version: ZBar.version,
31
+ usage: {q:true,raw:true,arg0:nil},
32
+ synonyms: {filename: :arg0})
33
+ def img(filename) = ZBar._img(filename:filename)
34
+
35
+ def screen
36
+ raw = nil
37
+ Dir.mktmpdir do |tmpdir|
38
+ _ = File.join(tmpdir, "#{$$}.#{Time.now.to_f}.png")
39
+ raw = _ if ZBar.snapshot(_) and not (_=ZBar.img(_).chomp).empty?
40
+ end
41
+ raw
34
42
  end
35
- raw
43
+
44
+ extend self
36
45
  end
37
46
  end
38
- end
data/lib/helpema.rb CHANGED
@@ -1,14 +1,21 @@
1
- module HELPEMA
2
- VERSION = '2.1.200129'
1
+ module Helpema
2
+ VERSION = '3.2.210924'
3
+
4
+ require_relative 'helpema/helpema'
3
5
 
4
- autoload :Helpema, 'helpema/helpema.rb'
5
6
  autoload :SSSS, 'helpema/ssss.rb'
6
7
  autoload :YouTubeDL, 'helpema/youtubedl.rb'
7
8
  autoload :ZBar, 'helpema/zbar.rb'
9
+ autoload :GPG, 'helpema/gpg.rb'
10
+ autoload :FFMPEG, 'helpema/ffmpeg.rb'
8
11
  end
12
+
9
13
  # Requires:
10
14
  #`ruby`
15
+ #`youtube-dl`
11
16
  #`ssss-split`
12
17
  #`ssss-combine`
13
18
  #`zbarcam`
19
+ #`zbarimg`
14
20
  #`gnome-screenshot`
21
+ #`gpg`
metadata CHANGED
@@ -1,21 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helpema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.200129
4
+ version: 3.2.210924
5
5
  platform: ruby
6
6
  authors:
7
- - carlosjhr64
8
- autorequire:
7
+ - CarlosJHR64
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-29 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Meant to be an eclectic collection of useful single functions and wrappers.
15
- Wrappers: ssss-split, ssss-combine, zbarcam, youtube-dl -j.
16
- Funtions: requires("gemname version",...).
17
15
 
18
- More later.
16
+ Featured method: `requires "good ~>3.0", "bad ~>2.7", "ugly ~>1.8"`
19
17
  email: carlosjhr64@gmail.com
20
18
  executables: []
21
19
  extensions: []
@@ -23,6 +21,8 @@ extra_rdoc_files: []
23
21
  files:
24
22
  - README.md
25
23
  - lib/helpema.rb
24
+ - lib/helpema/ffmpeg.rb
25
+ - lib/helpema/gpg.rb
26
26
  - lib/helpema/helpema.rb
27
27
  - lib/helpema/ssss.rb
28
28
  - lib/helpema/youtubedl.rb
@@ -31,7 +31,7 @@ homepage: https://github.com/carlosjhr64/helpema
31
31
  licenses:
32
32
  - MIT
33
33
  metadata: {}
34
- post_install_message:
34
+ post_install_message:
35
35
  rdoc_options: []
36
36
  require_paths:
37
37
  - lib
@@ -46,15 +46,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements:
49
- - 'ruby: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]'
49
+ - 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
50
+ - 'youtube-dl: 2021.06.06'
50
51
  - 'ssss-split: 0.5'
51
52
  - 'ssss-combine: 0.5'
52
53
  - 'zbarcam: 0.23'
53
- - 'gnome-screenshot: gnome-screenshot 3.34.0'
54
- rubygems_version: 3.1.2
55
- signing_key:
54
+ - 'zbarimg: 0.23'
55
+ - 'gnome-screenshot: gnome-screenshot 40.0'
56
+ - 'gpg: gpg (GnuPG) 2.2.27'
57
+ rubygems_version: 3.2.22
58
+ signing_key:
56
59
  specification_version: 4
57
- summary: 'Meant to be an eclectic collection of useful single functions and wrappers.
58
- Wrappers: ssss-split, ssss-combine, zbarcam, youtube-dl -j. Funtions: requires("gemname
59
- version",...).'
60
+ summary: Meant to be an eclectic collection of useful single functions and wrappers.
60
61
  test_files: []