gtk2mp3 1.4.0 → 3.0.210920

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: cd88c6f72aaf00b59a83973e5957600222b57e9ae0263908e2671dcc16b48f06
4
- data.tar.gz: 436134b8e2ca7a20bfbd0184e6611a359c26fce1551e23723ae8b7466018c9e5
3
+ metadata.gz: 180114c8a9dc0eb5d6338b18adcf5285f3e689ad2e4c07f20f808bd87bc90c1c
4
+ data.tar.gz: 1bccb9897a607bdcf6220c6430c602a42b5670cc97d66cc2852ef8073e50f389
5
5
  SHA512:
6
- metadata.gz: 877da13c590ab089e8c4fa107839b8fb72537aff36decbc2a5bccac33a3c8c922c7a3998a926a22b748f395cd05d32ae52fd0683cd8f43d191c9702c781cf989
7
- data.tar.gz: e4ac9b49fc5cfe11fb2e8a04ca5f878faec7a194f9f8f7ec85b0f40c6eabc67929fe14481340ba415baa8e60d874ab5d9f187558bdd3b6c9bbca4c9b8a7fc6c9
6
+ metadata.gz: 64fe65004af2cbc43a1267c9ec0058a00affcba1bf8c4d47a3cfb64987463dc4d5809e54022194db41742bda3f410ab021e5ff256dbd2253e0b8ad91674818e8
7
+ data.tar.gz: 8ad3748d951f1153ba05c4eab525da74cd59357eb69bb1c8f62d32aa2d1cabd8a1437c63909789550cd836bbc91e3b6109a91a8f03cd4f63b5af2f12359631fa
data/README.md CHANGED
@@ -1,30 +1,58 @@
1
- # Gtk2Mp3 I: Posser
1
+ # Gtk2Mp3
2
2
 
3
+ * [VERSION 3.0.210920](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
- $ sudo 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
- # Notes #
28
- # Requires MPD/MPC.
29
- # See https://www.musicpd.org/clients/mpc/.
30
-
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,38 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- require 'help_parser'
3
2
  require 'gtk2mp3'
4
-
5
- OPTIONS = HelpParser[Gtk2Mp3::VERSION, <<HELP]
6
- Usage:
7
- gtk2mp3 [:options+]
8
- Options:
9
- -h --help
10
- -v --version
11
- --noinit \tDon't reset the playlist
12
- # Notes #
13
- # Requires MPD/MPC.
14
- # See https://www.musicpd.org/clients/mpc/.
15
- HELP
16
-
17
- unless OPTIONS.noinit?
18
- unless system 'ps -C mpd'
19
- unless system 'mpd'
20
- $stderr.puts 'Could not start the mpd daemon.'
21
- exit 69 # EX_UNAVAILABLE
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
22
13
  end
23
14
  end
24
- unless system "mpc --wait update" and
25
- system "mpc clear" and
26
- system "mpc ls | mpc add" and
27
- system "mpc consume off" and
28
- system "mpc repeat off" and
29
- system "mpc random on" and
30
- system "mpc single on"
31
- $stderr.puts 'Could not initialize mpd\'s playlist'
32
- exit 76 # EX_PROTOCOL
33
- end
34
15
  end
35
-
36
- Gtk2Mp3.requires
37
- Gtk3App.main(Gtk2Mp3)
38
-
16
+ exit
@@ -1,35 +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
- VBOX: [:vertical],
24
- HBOX: [:horizontal],
25
- about_dialog: {
26
- set_program_name: 'Gtk2Mp3',
27
- set_version: VERSION.semantic(0..1),
28
- set_copyright: '(c) 2018 CarlosJHR64',
29
- set_comments: 'A MPD/MPC "Next!" Button',
30
- set_website: 'https://github.com/carlosjhr64/gtk2mp3',
31
- set_website_label: 'See it at GitHub!',
32
- },
33
- }
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: "#{UserSpace::XDG['data']}/gtk3app/gtk2mp3/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
+ },
34
36
  }
35
37
  end
data/lib/gtk2mp3/gui.rb CHANGED
@@ -1,108 +1,26 @@
1
- module Gtk2Mp3
2
- def self.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
- @label.text = @playing = ID[`mpc -f '%file%' searchplay filename #{random_song.shellescape}`]
24
- end
25
-
26
- def down(id)
27
- if count=@db[id]
28
- count -= 1
29
- if count>0
30
- @db[id] = count
31
- else
32
- @db.delete(id)
33
- end
34
- end
35
- end
36
-
37
- def up(id)
38
- @db[id] = @db[id].to_i+1
39
- end
40
-
41
- def db_update
42
- if @skipped
43
- up(@skipped) if Time.now - @time < CONFIG[:PLAYED]/2
44
- down(@skipped) if Time.now - @time > CONFIG[:PLAYED]
45
- elsif @played
46
- down(@played)
47
- next_song
48
- end
49
- @time,@played,@skipped = Time.now,@playing,nil
50
- end
51
-
52
- def mpc_idle_player
53
- loop do
54
- system 'mpc idle player'
55
- MUTEX.synchronize{db_update}
56
- end
57
- end
58
-
59
- def next_song!
60
- MUTEX.synchronize do
61
- @skipped = @playing
62
- next_song
63
- end
64
- end
65
-
66
- def stop_song!
67
- MUTEX.synchronize do
68
- @skipped = @playing = @played = nil
69
- system 'mpc stop'
70
- end
71
- end
72
-
73
- def initialize(program)
74
- # Build
75
- window,minime,menu = program.window,program.mini_menu,program.app_menu
76
- vbox = Such::Box.new(window, :VBOX)
77
- hbox = Such::Box.new(vbox, :HBOX)
78
- Such::Button.new(hbox, :next_button!){next_song!} if CONFIG[:BUTTONS].include?(:next_button!)
79
- Such::Button.new(hbox, :stop_button!){stop_song!} if CONFIG[:BUTTONS].include?(:stop_button!)
80
- @label = Such::Label.new(vbox)
81
- menu.each{|_|_.destroy if _.key==:fs! or _.key==:help!}
82
- minime.each{|_|_.destroy}
83
- minime.add_menu_item(:stop_item!){stop_song!} if CONFIG[:ITEMS].include?(:stop_item!)
84
- minime.add_menu_item(:next_item!){next_song!} if CONFIG[:ITEMS].include?(:next_item!)
85
-
86
- # Inits
87
- @db = File.exist?(_=CONFIG[:DBM]) ? JSON.parse(File.read(_)) : {}
88
- @list = `mpc listall`.lines.map{|_|ID[_]}.uniq
89
- # A fuzzy delete of possibly gone keys...
90
- @db.keys.each{|id| down(id) unless @list.include?(id)}
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
91
13
 
92
- # Run
93
- @skipped=@playing=nil
94
- next_song!
95
- @time,@played = Time.now,@playing
96
- Thread.new do
97
- sleep(1) # mpd needs a little time to settle
98
- mpc_idle_player
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
99
23
  end
100
- window.show_all
101
- end
102
-
103
- def finalize
104
- stop_song!
105
- File.write(CONFIG[:DBM], JSON.pretty_generate(@db))
106
24
  end
107
25
  end
108
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,20 +1,38 @@
1
- module Gtk2Mp3
2
- VERSION = '1.4.0'
1
+ class Gtk2Mp3
2
+ VERSION = '3.0.210920'
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
- def self.requires
18
+ def Gtk2Mp3.init
19
+ require_relative 'gtk2mp3/mpd'
20
+ Gtk2Mp3.system_mpd
21
+ Gtk2Mp3.system_mpc if ARGV.include? '--update'
22
+ end
23
+
24
+ def Gtk2Mp3.run
5
25
  # This is a Gtk3App.
6
26
  require 'gtk3app'
7
-
8
- # Standard Libraries
9
- require 'json'
10
- require 'shellwords'
11
-
12
27
  # This Gem.
13
- require_relative 'gtk2mp3/config.rb'
14
- require_relative 'gtk2mp3/gui.rb'
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)
33
+ end
15
34
  end
16
35
  end
17
-
18
36
  # Requires:
19
37
  #`ruby`
20
38
  #`mpd`
metadata CHANGED
@@ -1,58 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk2mp3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 3.0.210920
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: 2018-10-04 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: help_parser
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '6.4'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 6.4.2
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '6.4'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 6.4.2
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: gtk3app
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - "~>"
38
18
  - !ruby/object:Gem::Version
39
- version: '3.0'
19
+ version: '5.3'
40
20
  - - ">="
41
21
  - !ruby/object:Gem::Version
42
- version: 3.0.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
27
  - - "~>"
48
28
  - !ruby/object:Gem::Version
49
- version: '3.0'
29
+ version: '5.3'
50
30
  - - ">="
51
31
  - !ruby/object:Gem::Version
52
- version: 3.0.0
53
- description: 'A "Next!" button gui for MPD/MPC.
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
57
37
  executables:
58
38
  - gtk2mp3
@@ -62,17 +42,16 @@ files:
62
42
  - LICENSE
63
43
  - README.md
64
44
  - bin/gtk2mp3
65
- - cache/README.txt
66
- - data/VERSION
67
45
  - data/logo.png
68
46
  - lib/gtk2mp3.rb
69
47
  - lib/gtk2mp3/config.rb
70
48
  - lib/gtk2mp3/gui.rb
49
+ - lib/gtk2mp3/mpd.rb
71
50
  homepage: https://github.com/carlosjhr64/gtk2mp3
72
51
  licenses:
73
52
  - MIT
74
53
  metadata: {}
75
- post_install_message:
54
+ post_install_message:
76
55
  rdoc_options: []
77
56
  require_paths:
78
57
  - lib
@@ -87,11 +66,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
66
  - !ruby/object:Gem::Version
88
67
  version: '0'
89
68
  requirements:
90
- - 'ruby: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]'
91
- - 'mpd: Music Player Daemon 0.20.16'
92
- rubyforge_project:
93
- rubygems_version: 2.7.7
94
- signing_key:
69
+ - 'ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]'
70
+ - 'mpd: Music Player Daemon 0.22.11 (0.22.11)'
71
+ rubygems_version: 3.2.22
72
+ signing_key:
95
73
  specification_version: 4
96
- summary: A "Next!" button gui for MPD/MPC.
74
+ summary: A "Next!" button gui for [MPD/MPC](https://www.musicpd.org/).
97
75
  test_files: []
data/cache/README.txt DELETED
@@ -1 +0,0 @@
1
- The dbm.json file will be in this cache directory.
data/data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.4.0