fest 1.3.12 → 1.4.12

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
  SHA1:
3
- metadata.gz: 911be5f2274e3d6480715de33a5a22ae7579f420
4
- data.tar.gz: 4ccef82bd14c9b03efd7883e5d7812489102c0d8
3
+ metadata.gz: 971b8a6270186dc0400dd8c2831878d736b6a698
4
+ data.tar.gz: 5000bd30c31c717c364ec41e100bcccae9a3c98e
5
5
  SHA512:
6
- metadata.gz: fff84a8efefeca08043a8ce7b7cde76b9c13f5a92478f14932b6be7067acf49c8a2d03eb354432d43beceafb19cbee9c8f00cf32d425f77c87204dc9beb78719
7
- data.tar.gz: b3dfff72cac33060164af1092b47149b443d04540cf9134058f5e2ed2177cef6ac578f5141ce216a926d73a500359161580333fc274fe959fd403b289288376d
6
+ metadata.gz: 66cc10e14ab3435990869502e7ad6cce79be50163bac163c05708c7739aa9fef1fe1b6fc8f1f99592e6f169ea46b7c26614388bebd5c3017a21ba9dd55e14c11
7
+ data.tar.gz: 8f8233848deaa304ce77f950e276a0449ea421802cfb0849c5e6f75b5cd968b12f80520cb9334595096ef047d9902fde79197cf88c00b617b317a5ec59d5f7db
data/README.md CHANGED
@@ -9,7 +9,7 @@ Ruby wrapper use [Festival](https://wiki.archlinux.org/index.php/Festival_%28%D0
9
9
 
10
10
  ## Requirements
11
11
 
12
- - *nix* or OS X ...
12
+ - *nix* or OS X (pgrep tools) ...
13
13
  - [Festival](https://wiki.archlinux.org/index.php/Festival_%28%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%29) and necessary languages ...
14
14
  - [Pulseaudio](https://wiki.archlinux.org/index.php/PulseAudio_%28%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%29)
15
15
 
@@ -1,3 +1,7 @@
1
+ ** 1.4.12 (Сб 03 окт 2015 13:08:17)
2
+ - manage volumes on inputs ... down ... up ...
3
+ - merge for default params with params ...
4
+ - add conditions ... flash and skype ...
1
5
  ** 1.3.12 (Пт 02 окт 2015 09:37:39)
2
6
  - fix conditions ... delete xbacklight from dependence ...
3
7
  ** 1.3.11 (Чт 01 окт 2015 18:40:50)
@@ -2,7 +2,21 @@
2
2
  light:
3
3
  - "brightness = `cat /sys/class/backlight/intel_backlight/brightness`.to_i"
4
4
  - "exit if @backlight == 'nil' && brightness == 0"
5
+ flash:
6
+ - "displays = `xvinfo`.scan(/screen\\s#(\\d+)/i).flatten"
7
+ - "displays.each do |display|"
8
+ - " display = display.eql?('0') ? '' : '.' + display"
9
+ - " active = `DISPLAY=:0#{display} xprop -root '_NET_ACTIVE_WINDOW'`.scan(/\\w+/).last"
10
+ - " unless `xprop -id '#{active}' | grep '_NET_WM_STATE_FULLSCREEN'`.empty?"
11
+ - " title = `xprop -id '#{active}' | grep 'WM_CLASS(STRING)'`"
12
+ - " ['unknown', 'plugin-containe', 'exe'].each do |name|"
13
+ - " exit if title.scan(name).last == name"
14
+ - " end"
15
+ - " end"
16
+ - "end"
17
+ skype:
18
+ - "exit unless `pactl list sink-inputs | grep 'phone'`.empty?"
5
19
  players:
6
20
  - "%w(xbmc kodi vlc).each do |player|"
7
- - "exit if `ps -el | grep '#{player}' | wc -l`.to_i > 0"
21
+ - " exit if `pgrep -lfc '#{player}'`.to_i > 0"
8
22
  - "end"
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  path:
3
3
  '/tmp'
4
- current_volume:
4
+ common_volume:
5
5
  - "`amixer | grep -o '[0-9]*' | sed '5 ! d' `.to_i"
6
6
  index:
7
7
  - "index = `ls -r #{@path} | grep -o '[0-9]*' | sed '1 ! d'`.to_i"
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  path:
3
3
  '/tmp'
4
- current_volume:
4
+ common_volume:
5
5
  - "`amixer | grep -o '[0-9]*' | sed '5 ! d' `.to_i"
6
6
  index:
7
7
  - "index = `ls -r #{@path} | grep -o '[0-9]*' | sed '1 ! d'`.to_i"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fest'
3
- gem.version = '1.3.12'
3
+ gem.version = '1.4.12'
4
4
  gem.authors = 'Alexsey Ermolaev'
5
5
  gem.email = 'afay.zangetsu@gmail.com'
6
6
  gem.homepage = 'https://github.com/AfsmNGhr/fest'
@@ -14,14 +14,13 @@ class Fest
14
14
  unless string.nil? || string.empty?
15
15
  check_conditions
16
16
  make_wav(string)
17
- expect_if_paplay_now
18
17
  play_wav
18
+ delete_wav
19
19
  end
20
20
  end
21
21
 
22
22
  def initialize(params = {})
23
- params =
24
- YAML.load_file("#{GEM_ROOT}/config/default.yml") if params == {}
23
+ params = YAML.load_file("#{GEM_ROOT}/config/default.yml").merge(params)
25
24
  params.each do |key, value|
26
25
  instance_variable_set(
27
26
  "@#{key}",
@@ -45,20 +44,20 @@ class Fest
45
44
 
46
45
  def expect_if_paplay_now
47
46
  loop do
48
- break if `ps -el | grep paplay | wc -l`.to_i == 0
47
+ break if `pgrep -lfc 'paplay'`.to_i == 0
49
48
  sleep 1
50
49
  end
51
50
  end
52
51
 
53
52
  def play_wav
54
- check_optimal_volume
53
+ expect_if_paplay_now
54
+ current_volumes_on_inputs
55
+ volumes_for_inputs
55
56
  optimize_volume
56
- sink_inputs
57
- change_volume(@current_volume, @volume, @step)
57
+ change_volumes(@current_volumes, @volumes, @step)
58
58
  system("paplay #{@path}/say_#{@index}.wav \
59
59
  --volume='#{@optimize_volume * 655}' > /dev/null 2>&1")
60
- change_volume(@volume, @current_volume, @step)
61
- delete_wav
60
+ change_volumes(@volumes, @current_volumes, @step)
62
61
  end
63
62
 
64
63
  def delete_wav
@@ -1,33 +1,40 @@
1
1
  # coding: utf-8
2
- #
3
2
  module Volume
4
- def check_optimal_volume
5
- @volume = @current_volume - @current_volume / 10 * @step
3
+ def current_volumes_on_inputs
4
+ info = `pactl list sink-inputs`
5
+ inputs = info.scan(/\A#|№(\d+)/).flatten
6
+ volumes = info.scan(/\W+:\s\w+\W+\w+:\s\d+\s\/\s+(\d+)%/).flatten
7
+ @current_volumes = inputs.zip(volumes.map(&:to_i)).to_h
8
+ end
9
+
10
+ def volumes_for_inputs
11
+ @volumes = {}
12
+ @current_volumes.each do |input, volume|
13
+ @volumes.merge!({ input => (volume - volume / 10 * @step) })
14
+ end
15
+ @volumes
6
16
  end
7
17
 
8
18
  def optimize_volume
9
19
  @optimize_volume = (
10
- if @current_volume > @max_volume
20
+ if @common_volume > @max_volume
11
21
  @max_volume
12
- elsif @current_volume < @min_volume
22
+ elsif @common_volume < @min_volume
13
23
  @min_volume
14
24
  else
15
- @current_volume
25
+ @common_volume
16
26
  end
17
27
  )
18
28
  end
19
29
 
20
- def sink_inputs
21
- @inputs = `pactl list sink-inputs | grep '№' | grep -o '[0-9]*'`.split("\n")
22
- end
23
-
24
- def change_volume(volume, break_volume, step)
25
- change = volume > break_volume ? 'down' : 'up'
26
- @inputs.each do |input|
30
+ def change_volumes(volumes, break_volumes, step)
31
+ volumes.each do |input, volume|
32
+ change = volume > break_volumes[input] ? 'down' : 'up'
27
33
  loop do
28
34
  system("pactl set-sink-input-volume #{input} '#{volume * 655}'")
29
35
  change == 'up' ? volume += step : volume -= step
30
- break if change == 'up' ? volume > break_volume : volume < break_volume
36
+ break if change == 'up' ? volume > break_volumes[input] :
37
+ volume < break_volumes[input]
31
38
  end
32
39
  end
33
40
  end
@@ -7,7 +7,7 @@ RSpec.describe Fest do
7
7
  @fest = Fest.new
8
8
  params = YAML.load_file("#{GEM_ROOT}/config/default.yml")
9
9
  @step = params['step']
10
- @current_volume = eval(params['current_volume'].join('; '))
10
+ @common_volume = eval(params['common_volume'].join('; '))
11
11
  @max_volume = params['max_volume']
12
12
  @min_volume = params['min_volume']
13
13
  end
@@ -16,56 +16,65 @@ RSpec.describe Fest do
16
16
  expect(@fest.class.included_modules.include?(Volume)).to be_truthy
17
17
  end
18
18
 
19
- it 'current volume eq volume?' do
19
+ it 'common volume eq volume?' do
20
20
  vol = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
21
- expect(@current_volume).to eq(vol)
21
+ expect(@common_volume).to eq(vol)
22
22
  end
23
23
 
24
- it '#inputs' do
25
- inputs =
26
- `pactl list sink-inputs | grep '№' | grep -o '[0-9]*'`.split("\n")
27
- expect(@fest.sink_inputs).to match_array(inputs)
24
+ it '#current_volumes_on_inputs' do
25
+ info = `pactl list sink-inputs`
26
+ inputs = info.scan(/\A#|№(\d+)/).flatten
27
+ volumes = info.scan(/\W+:\s\w+\W+\w+:\s\d+\s\/\s+(\d+)%/).flatten
28
+ current_volumes = inputs.zip(volumes.map(&:to_i)).to_h
29
+ expect(@fest.current_volumes_on_inputs).to eq(current_volumes)
28
30
  end
29
31
 
30
- it '#check_optimal_volume' do
31
- vol = @current_volume - @current_volume / 10 * @step
32
- expect(@fest.check_optimal_volume).to eq(vol)
32
+ it '#volumes_for_inputs' do
33
+ current_volumes = @fest.current_volumes_on_inputs
34
+ volumes = {}
35
+ current_volumes.each do |input, volume|
36
+ volumes.merge!({ input => (volume - volume / 10 * @step) })
37
+ end
38
+ expect(@fest.volumes_for_inputs).to eq(volumes)
33
39
  end
34
40
 
35
41
  it '#optimize_volume' do
36
- if @current_volume > @max_volume
37
- expect(@fest.optimize_volume).to be < @current_volume
38
- elsif @current_volume < @min_volume
39
- expect(@fest.optimize_volume).to be > @current_volume
42
+ if @common_volume > @max_volume
43
+ expect(@fest.optimize_volume).to be < @common_volume
44
+ elsif @common_volume < @min_volume
45
+ expect(@fest.optimize_volume).to be > @common_volume
40
46
  else
41
- expect(@fest.optimize_volume).to eq(@current_volume)
47
+ expect(@fest.optimize_volume).to eq(@common_volume)
42
48
  end
43
49
  end
44
50
 
45
- it '#change_volume down' do
46
- @fest.sink_inputs
47
- @fest.change_volume(
48
- @current_volume,
49
- @fest.check_optimal_volume,
50
- @step
51
- )
51
+ it '#change_volumes down' do
52
+ @fest.change_volumes(
53
+ @fest.current_volumes_on_inputs, @fest.volumes_for_inputs, @step)
54
+
55
+ info = `pactl list sink-inputs`
56
+ inputs = info.scan(/\A#|№(\d+)/).flatten
57
+ volumes = info.scan(/\W+:\s\w+\W+\w+:\s\d+\s\/\s+(\d+)%/).flatten
58
+ current_volumes = inputs.zip(volumes.map(&:to_i)).to_h
52
59
 
53
- current_volume = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
54
- vol = current_volume - current_volume / 10 * @step
55
- expect(@fest.check_optimal_volume).to eq(vol)
60
+ @fest.volumes_for_inputs.each do |input, volume|
61
+ expect(volume).to eq(current_volumes[input])
62
+ end
56
63
  end
57
64
 
58
- it '#change_volume up' do
59
- @fest.sink_inputs
60
- @fest.change_volume(
61
- @fest.check_optimal_volume,
62
- @current_volume,
63
- @step
64
- )
65
+ it '#change_volumes up' do
66
+ @fest.current_volumes_on_inputs
67
+ @fest.change_volumes(
68
+ @fest.volumes_for_inputs, @fest.current_volumes_on_inputs, @step)
65
69
 
66
- current_volume = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
67
- vol = `amixer | grep -o '[0-9]*' | sed "5 ! d"`.to_i
68
- expect(current_volume).to eq(vol)
70
+ info = `pactl list sink-inputs`
71
+ inputs = info.scan(/\A#|№(\d+)/).flatten
72
+ volumes = info.scan(/\W+:\s\w+\W+\w+:\s\d+\s\/\s+(\d+)%/).flatten
73
+ current_volumes = inputs.zip(volumes.map(&:to_i)).to_h
74
+
75
+ @fest.current_volumes_on_inputs.each do |input, volume|
76
+ expect(volume).to eq(current_volumes[input])
77
+ end
69
78
  end
70
79
  end
71
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.12
4
+ version: 1.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexsey Ermolaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake