gtk2mp3 2.5.191217 → 3.0.210919

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44f275e94c4638c8571bc8f08aff3b3530fb880fdc618ff5db7d3127d74be392
4
- data.tar.gz: ecb239912c273b285001c0ad0794543647703d4d5d7760ecd66dda86eb694f83
3
+ metadata.gz: ba7f8bad4959e91cf3514f05fe5e9e15dd5dd56ecd6bb38e95305955c3c9a8bb
4
+ data.tar.gz: aaebca94d0d198933e6cad51ec87229213ee8287bacc30cd1d49d095b24e2459
5
5
  SHA512:
6
- metadata.gz: f8396b6d71a498084af8a5fd1025974a3cccbb100ff87e4a64de8332b6b5bc33cf84a7039de2dbf356e6c67576a9d1d9209b04df609205e6ec775539d3a05377
7
- data.tar.gz: 1c01f0c6edca39f25258b261b983fc340ae41434c65369273b87872eecefb93dbb536c8fd4ef1cae051e0de29a048c0c6deb6b6bad3e9a9c5c85e8c65e4fa823
6
+ metadata.gz: c15a4927e91c6ee1c38188e4442b8e1ad2694a447cc0d886cdf35c104f53297e2a6e24193d39e6027859d002cf672aa2bc9f83acfe7c9e7defc81f920f492d22
7
+ data.tar.gz: 6ac38d48745513588857c364265eb6970fc51bc95e7a1092f3ea364ad07b2ebab085d20e48196f5a67e16aedf86124ed339139fe7ac9b8ef68e71bb4a87865ba
data/README.md CHANGED
@@ -1,34 +1,58 @@
1
- # Gtk2Mp3 I: Posser
1
+ # Gtk2Mp3
2
2
 
3
+ * [VERSION 3.0.210919](https://github.com/carlosjhr64/gtk2mp3/releases)
3
4
  * [github](https://www.github.com/carlosjhr64/gtk2mp3)
4
5
  * [rubygems](https://rubygems.org/gems/gtk2mp3)
5
- * [MPD/MPC](https://www.musicpd.org/)
6
6
 
7
7
  ## DESCRIPTION:
8
8
 
9
- A "Next!" button gui for MPD/MPC.
9
+ A "Next!" button gui for [MPD/MPC](https://www.musicpd.org/).
10
10
 
11
11
  ## SYNOPSIS
12
-
13
- gtk2mp3
14
-
12
+ ```console
13
+ $ gtk2mp3
14
+ ```
15
15
  ## INSTALL
16
-
17
- $ gem install gtk2mp3
18
-
16
+ ```console
17
+ $ gem install gtk2mp3
18
+ ```
19
19
  ## HELP
20
-
21
- Usage:
22
- gtk2mp3 [:options+]
23
- Options:
24
- -h --help
25
- -v --version
26
- --noinit Don't reset the playlist
27
- -V --verbose
28
- # Notes #
29
- # Signal USR1 will trigger Next! song.
30
- # Signal USR2 will trigger Stop song.
31
- # Signal TERM will quit.
32
- # Requires MPD/MPC.
33
- # See https://www.musicpd.org/clients/mpc/.
34
-
20
+ ```console
21
+ $ gtk2mp3 --help
22
+ Usage:
23
+ gtk2mp3 [:options+]
24
+ Options:
25
+ -h --help
26
+ -v --version
27
+ --minime Real minime
28
+ --notoggle Minime wont toggle decorated and keep above
29
+ --notdecorated Dont decorate window
30
+ --update Updates and sets playlist to the entire collection
31
+ # Note:
32
+ # Requires MPD/MPC.
33
+ # See https://www.musicpd.org/clients/mpc/.
34
+ ```
35
+ ## LICENSE:
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2021 CarlosJHR64
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/gtk2mp3 CHANGED
@@ -1,43 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- require 'help_parser'
3
-
4
- OPTIONS = HelpParser['2.5.191217', <<HELP]
5
- Usage:
6
- gtk2mp3 [:options+]
7
- Options:
8
- -h --help
9
- -v --version
10
- --noinit \tDon't reset the playlist
11
- -V --verbose
12
- # Notes #
13
- # Signal USR1 will trigger Next! song.
14
- # Signal USR2 will trigger Stop song.
15
- # Signal TERM will quit.
16
- # Requires MPD/MPC.
17
- # See https://www.musicpd.org/clients/mpc/.
18
- HELP
19
-
20
- TO_DEV_NULL = OPTIONS.verbose? ? '' : '> /dev/null'
21
- unless OPTIONS.noinit?
22
- # check if mpd is already running
23
- unless system "ps -C mpd #{TO_DEV_NULL}"
24
- unless system "mpd #{TO_DEV_NULL}"
25
- $stderr.puts 'Could not start the mpd daemon.'
26
- exit 69 # EX_UNAVAILABLE
2
+ require 'gtk2mp3'
3
+ class Gtk2Mp3
4
+ begin
5
+ case ARGV
6
+ in [/^(-v)|(--version)$/]
7
+ puts VERSION
8
+ in [/^(-h)|(--help)$/]
9
+ puts HELP
10
+ else
11
+ Gtk2Mp3.init
12
+ Gtk2Mp3.run
27
13
  end
28
14
  end
29
- unless system "mpc --wait update #{TO_DEV_NULL}" and
30
- system "mpc clear #{TO_DEV_NULL}" and
31
- system "mpc ls | mpc add" and
32
- system "mpc consume off #{TO_DEV_NULL}" and
33
- system "mpc repeat off #{TO_DEV_NULL}" and
34
- system "mpc random on #{TO_DEV_NULL}" and
35
- system "mpc single on #{TO_DEV_NULL}"
36
- $stderr.puts 'Could not initialize mpd\'s playlist'
37
- exit 76 # EX_PROTOCOL
38
- end
39
15
  end
40
-
41
- require 'gtk2mp3'
42
- [:USR1,:USR2,:TERM].each{|_|Signal.trap(_){Gtk2Mp3.signal!(_)}}
43
- Gtk3App.main(Gtk2Mp3)
16
+ exit
@@ -1,36 +1,37 @@
1
- module Gtk2Mp3
2
- using Rafini::String
3
- APPDIR = File.dirname File.dirname __dir__
1
+ class Gtk2Mp3
2
+ using Rafini::String # for semantic
3
+ extend Rafini::Empty # for s0,a0,h0
4
+
4
5
  CONFIG = {
5
- PLAYED: 120,
6
- DBM: "#{XDG['CACHE']}/gtk3app/gtk2mp3/dbm.json",
7
- BUTTONS: [:next_button!, :stop_button!],
8
- ITEMS: [:next_item!, :stop_item!],
9
- thing: {
10
- HelpFile: 'https://github.com/carlosjhr64/gtk2mp3',
11
- Logo: "#{XDG['DATA']}/gtk3app/gtk2mp3/logo.png",
12
- window: {
13
- set_title: 'Gtk2Mp3',
14
- set_default_size: [100,60],
15
- set_window_position: :center,
16
- },
17
- NEXT: [label: 'Next!'],
18
- next_button!: [:NEXT, 'clicked'],
19
- next_item!: [:NEXT, 'activate'],
20
- STOP: [label: 'Stop'],
21
- stop_button!: [:STOP, 'clicked'],
22
- stop_item!: [:STOP, 'activate'],
23
- id_label!: [set_selectable: true],
24
- VBOX: [:vertical],
25
- HBOX: [:horizontal],
26
- about_dialog: {
27
- set_program_name: 'Gtk2Mp3',
28
- set_version: VERSION.semantic(0..1),
29
- set_copyright: '(c) 2018 CarlosJHR64',
30
- set_comments: 'A MPD/MPC "Next!" Button',
31
- set_website: 'https://github.com/carlosjhr64/gtk2mp3',
32
- set_website_label: 'See it at GitHub!',
33
- },
34
- }
6
+ TOOLBOX: [:horizontal],
7
+ toolbox: h0,
8
+ toolbox!: [:TOOLBOX,:toolbox],
9
+
10
+ NEXT_BUTTON: [label: 'Next!'],
11
+ next_button: h0,
12
+ next_button!: [:NEXT_BUTTON, :next_button, 'clicked'],
13
+
14
+ STOP_BUTTON: [label: 'Stop'],
15
+ stop_button: h0,
16
+ stop_button!: [:STOP_BUTTON, :stop_button, 'clicked'],
17
+
18
+ ID_LABEL: a0,
19
+ id_label: {set_selectable: true},
20
+ id_label!: [:ID_LABEL, :id_label],
21
+
22
+ HelpFile: 'https://github.com/carlosjhr64/gtk2mp3',
23
+ Logo: "#{File.dirname File.dirname __dir__}/data/logo.png",
24
+ about_dialog: {
25
+ set_program_name: 'Gtk2Mp3',
26
+ set_version: VERSION.semantic(0..1),
27
+ set_copyright: '(c) 2021 CarlosJHR64',
28
+ set_comments: 'A MPD/MPC "Next!" Button',
29
+ set_website: 'https://github.com/carlosjhr64/gtk2mp3',
30
+ set_website_label: 'See it at GitHub!',
31
+ },
32
+
33
+ app_menu: {
34
+ add_menu_item: [:minime!, :about!, :quit!]
35
+ },
35
36
  }
36
37
  end
data/lib/gtk2mp3/gui.rb CHANGED
@@ -1,126 +1,26 @@
1
- module Gtk2Mp3
2
- def Gtk2Mp3.run(program)
3
- GUI.new(program)
1
+ class Gtk2Mp3
2
+ def set_label(text)
3
+ @label.text = text
4
4
  end
5
5
 
6
- class GUI
7
- MUTEX = Mutex.new
8
- ID = lambda{|_|File.basename(_.strip.split(/\n/).first.strip,'.*')}
9
-
10
- def play?(id)
11
- rand(@db[id].to_i+1)==0
12
- end
13
-
14
- def random_song
15
- n = @list.length
16
- loop do
17
- id = @list[rand(n)]
18
- return id if play?(id)
19
- end
20
- end
21
-
22
- def next_song
23
- id = random_song
24
- @label.text = @playing = ID[`mpc -f '%file%' searchplay filename #{id.shellescape}`]
25
- end
26
-
27
- # decrementing count makes the id
28
- # more likely to be played
29
- def down(id)
30
- if count=@db[id]
31
- count -= 1
32
- if count>0
33
- @db[id] = count
34
- else
35
- @db.delete(id)
36
- end
37
- end
38
- end
39
-
40
- # incrementing count makes the id
41
- # less likely to be played
42
- def up(id)
43
- @db[id] = @db[id].to_i+1
44
- end
45
-
46
- def db_update
47
- if @skipped
48
- up(@skipped) if Time.now - @time < CONFIG[:PLAYED]/2
49
- down(@skipped) if Time.now - @time > CONFIG[:PLAYED]
50
- elsif @played
51
- down(@played)
52
- next_song
53
- end
54
- @time,@played,@skipped = Time.now,@playing,nil
55
- end
56
-
57
- def mpc_idle_player
58
- loop do
59
- system "mpc idle player #{TO_DEV_NULL}"
60
- MUTEX.synchronize{db_update}
61
- end
62
- end
63
-
64
- def next_song!
65
- MUTEX.synchronize do
66
- @skipped = @playing
67
- next_song
68
- end
69
- end
70
-
71
- def stop_song!
72
- MUTEX.synchronize do
73
- @skipped = @playing = @played = nil
74
- system "mpc stop #{TO_DEV_NULL}"
75
- end
76
- end
77
-
78
- def initialize(program)
79
- # Build
80
- window,minime,menu = program.window,program.mini_menu,program.app_menu
81
- vbox = Such::Box.new(window, :VBOX)
82
- hbox = Such::Box.new(vbox, :HBOX)
83
- Such::Button.new(hbox, :next_button!){next_song!} if CONFIG[:BUTTONS].include?(:next_button!)
84
- Such::Button.new(hbox, :stop_button!){stop_song!} if CONFIG[:BUTTONS].include?(:stop_button!)
85
- @label = Such::Label.new(vbox, :id_label!)
86
- menu.each{|_|_.destroy if _.key==:fs! or _.key==:help!}
87
- minime.each{|_|_.destroy}
88
- minime.add_menu_item(:stop_item!){stop_song!} if CONFIG[:ITEMS].include?(:stop_item!)
89
- minime.add_menu_item(:next_item!){next_song!} if CONFIG[:ITEMS].include?(:next_item!)
90
-
91
- # Inits
92
- @db = File.exist?(_=CONFIG[:DBM]) ? JSON.parse(File.read(_)) : {}
93
- @list = `mpc listall`.lines.map{|_|ID[_]}.uniq
94
- # A fuzzy delete of possibly gone keys...
95
- @db.keys.each{|id| down(id) unless @list.include?(id)}
96
-
97
- # Run
98
- @skipped=@playing=nil
99
- next_song!
100
- @time,@played = Time.now,@playing
101
- Thread.new do
102
- sleep(1) # mpd needs a little time to settle
103
- mpc_idle_player
104
- end
105
- window.show_all
6
+ def initialize(stage, toolbar, options, &block)
7
+ @toolbox = Such::Box.new toolbar, :toolbox!
8
+ Such::Button.new(@toolbox, :next_button!){block.call :next}
9
+ Such::Button.new(@toolbox, :stop_button!){block.call :stop}
10
+ @label = Such::Label.new(stage, :id_label!)
11
+ build_logo_menu(block)
12
+ end
106
13
 
107
- # Handle Signal.trap
108
- GLib::Timeout.add(500) do
109
- case Gtk2Mp3.signal!
110
- when :USR1
111
- next_song!
112
- when :USR2
113
- stop_song!
114
- when :TERM
115
- Gtk3App.quit!
116
- end
117
- true # repeat
14
+ def build_logo_menu(block)
15
+ Gtk3App.logo_press_event do |button|
16
+ case button
17
+ when 1
18
+ block.call :next
19
+ when 2
20
+ block.call :stop
21
+ when 3
22
+ # Gtk3App's main menu
118
23
  end
119
24
  end
120
-
121
- def finalize
122
- stop_song!
123
- File.write(CONFIG[:DBM], JSON.pretty_generate(@db))
124
- end
125
25
  end
126
26
  end
@@ -0,0 +1,51 @@
1
+ class Gtk2Mp3
2
+ def Gtk2Mp3.system_mpd
3
+ # check if mpd is already running
4
+ unless system 'ps -C mpd'
5
+ unless system 'mpd'
6
+ $stderr.puts 'Could not start the mpd daemon.'
7
+ exit 69 # EX_UNAVAILABLE
8
+ end
9
+ end
10
+ end
11
+
12
+ def Gtk2Mp3.system_mpc
13
+ # initialize playlist
14
+ unless system 'mpc --wait update' and
15
+ system 'mpc clear' and
16
+ system 'mpc ls | mpc add' and
17
+ system 'mpc consume off' and
18
+ system 'mpc repeat off' and
19
+ system 'mpc random on' and
20
+ system 'mpc single off'
21
+ $stderr.puts %q(Could not initialize mpd's playlist)
22
+ exit 76 # EX_PROTOCOL
23
+ end
24
+ end
25
+
26
+ def Gtk2Mp3.mpc_command(command)
27
+ case command
28
+ when :next
29
+ current = `mpc current`.strip
30
+ if current.empty?
31
+ system 'mpc play'
32
+ else
33
+ # On my system, if I don't pause first, the sound fails.
34
+ system 'mpc pause'
35
+ system 'mpc next'
36
+ end
37
+ when :stop
38
+ system 'mpc stop'
39
+ end
40
+ end
41
+
42
+ def Gtk2Mp3.mpc_idleloop(gui)
43
+ Thread.new do
44
+ IO.popen('mpc idleloop', 'r') do |pipe|
45
+ while line = pipe.gets
46
+ gui.set_label File.basename(`mpc current`.strip, '.*')
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/gtk2mp3.rb CHANGED
@@ -1,34 +1,38 @@
1
- require 'json'
2
- require 'shellwords'
1
+ class Gtk2Mp3
2
+ VERSION = '3.0.210919'
3
+ HELP = <<~HELP
4
+ Usage:
5
+ gtk2mp3 [:options+]
6
+ Options:
7
+ -h --help
8
+ -v --version
9
+ --minime \t Real minime
10
+ --notoggle \t Minime wont toggle decorated and keep above
11
+ --notdecorated \t Dont decorate window
12
+ --update \t Updates and sets playlist to the entire collection
13
+ # Note:
14
+ # Requires MPD/MPC.
15
+ # See https://www.musicpd.org/clients/mpc/.
16
+ HELP
3
17
 
4
- # This is a Gtk3App.
5
- require 'gtk3app'
6
- module Gtk3App
7
- # Monkey patching a missing feature
8
- def Gtk3App.quit!
9
- @program.quit!
18
+ def Gtk2Mp3.init
19
+ require_relative 'gtk2mp3/mpd'
20
+ Gtk2Mp3.system_mpd
21
+ Gtk2Mp3.system_mpc if ARGV.include? '--update'
10
22
  end
11
- end
12
-
13
- module Gtk2Mp3
14
- VERSION = '2.5.191217'
15
23
 
16
- @signal = nil
17
- def Gtk2Mp3.signal!(q=nil)
18
- if q
19
- @signal = q
20
- elsif @signal
21
- signal,@signal = @signal,nil
22
- return signal
24
+ def Gtk2Mp3.run
25
+ # This is a Gtk3App.
26
+ require 'gtk3app'
27
+ # This Gem.
28
+ require_relative 'gtk2mp3/config'
29
+ require_relative 'gtk2mp3/gui'
30
+ Gtk3App.run(klass:Gtk2Mp3) do |stage, toolbar, options|
31
+ gui = Gtk2Mp3.new(stage, toolbar, options){Gtk2Mp3.mpc_command _1}
32
+ Gtk2Mp3.mpc_idleloop(gui)
23
33
  end
24
- return nil
25
34
  end
26
-
27
- # This Gem.
28
- require_relative 'gtk2mp3/config.rb'
29
- require_relative 'gtk2mp3/gui.rb'
30
35
  end
31
-
32
36
  # Requires:
33
37
  #`ruby`
34
38
  #`mpd`
metadata CHANGED
@@ -1,56 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk2mp3
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.191217
4
+ version: 3.0.210919
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: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2021-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: help_parser
14
+ name: gtk3app
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 6.5.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '6.5'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
19
+ version: '5.3'
27
20
  - - ">="
28
21
  - !ruby/object:Gem::Version
29
- version: 6.5.0
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '6.5'
33
- - !ruby/object:Gem::Dependency
34
- name: gtk3app
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 3.0.0
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '3.0'
22
+ version: 5.3.210919
43
23
  type: :runtime
44
24
  prerelease: false
45
25
  version_requirements: !ruby/object:Gem::Requirement
46
26
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 3.0.0
50
27
  - - "~>"
51
28
  - !ruby/object:Gem::Version
52
- version: '3.0'
53
- description: 'A "Next!" button gui for MPD/MPC.
29
+ version: '5.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.3.210919
33
+ description: 'A "Next!" button gui for [MPD/MPC](https://www.musicpd.org/).
54
34
 
55
35
  '
56
36
  email: carlosjhr64@gmail.com
@@ -63,16 +43,16 @@ files:
63
43
  - README.md
64
44
  - bin/gtk2mp3
65
45
  - cache/README.txt
66
- - data/VERSION
67
46
  - data/logo.png
68
47
  - lib/gtk2mp3.rb
69
48
  - lib/gtk2mp3/config.rb
70
49
  - lib/gtk2mp3/gui.rb
50
+ - lib/gtk2mp3/mpd.rb
71
51
  homepage: https://github.com/carlosjhr64/gtk2mp3
72
52
  licenses:
73
53
  - MIT
74
54
  metadata: {}
75
- post_install_message:
55
+ post_install_message:
76
56
  rdoc_options: []
77
57
  require_paths:
78
58
  - lib
@@ -87,10 +67,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
67
  - !ruby/object:Gem::Version
88
68
  version: '0'
89
69
  requirements:
90
- - 'ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]'
91
- - 'mpd: Music Player Daemon 0.21.16 (0.21.16)'
92
- rubygems_version: 3.0.3
93
- signing_key:
70
+ - 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
71
+ - 'mpd: Music Player Daemon 0.22.11 (0.22.11)'
72
+ rubygems_version: 3.2.22
73
+ signing_key:
94
74
  specification_version: 4
95
- summary: A "Next!" button gui for MPD/MPC.
75
+ summary: A "Next!" button gui for [MPD/MPC](https://www.musicpd.org/).
96
76
  test_files: []
data/data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.5.191217