listlace 0.2.1 → 0.2.2

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: 81dd49a642dc3679a690ddc7b4107d614d2356c6
4
- data.tar.gz: 49cfdc7c09b8e1835346c3d334796e2a25a81287
3
+ metadata.gz: 73a561a8f588866994d8cbe4718ebdfecc177e0c
4
+ data.tar.gz: b6e132d833d80fa70db4bd45797a14f215a886ed
5
5
  SHA512:
6
- metadata.gz: 1894c03f8bcc99d20c212bbc8c2b80ae37cf4ebe67bd44e6053cd64eb22a19223a7f2fbbf44fd22a40bebdf2a82cbe51e985d629c2811401dd277ad1fabbc2a9
7
- data.tar.gz: fe454c5393bdedf4acbc145393ea94c83726670eeaf7b243e6b7df7f62fdf856ccec7a377427082117bc22d15eebde2de6f80559df5900b8924ad1d0964fbd68
6
+ metadata.gz: 71fbeea2dffa8205f5ad4ffa0320b5c53ad8e8f8cbf8d3c22f83b3a396330bd9aba86b70ccb9f224aabe66607a15bc7068ba2fa6ac85cd0d2167aa74b2d27bd1
7
+ data.tar.gz: 453a19318a387a0016cebbd839a1bdf22caa2f350ae108e06b4f25d75f9e229b3611fc3561ba3a4e502fc2dd9ac705d500f60ea1bcf3ff53ebdcaf83e97a8f9b
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
  gemspec
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- listlace (0.2.0)
5
- bundler
6
- pry
7
- ruby-mpd
4
+ listlace (0.2.2)
5
+ bundler (~> 1.5)
6
+ pry (~> 0.9)
7
+ ruby-mpd (~> 0.3, >= 0.3.1)
8
8
 
9
9
  GEM
10
- remote: http://rubygems.org/
10
+ remote: https://rubygems.org/
11
11
  specs:
12
12
  coderay (1.1.0)
13
13
  method_source (0.8.2)
@@ -15,7 +15,6 @@ GEM
15
15
  coderay (~> 1.0)
16
16
  method_source (~> 0.8)
17
17
  slop (~> 3.4)
18
- rake (0.9.2.2)
19
18
  ruby-mpd (0.3.1)
20
19
  slop (3.5.0)
21
20
 
@@ -24,4 +23,3 @@ PLATFORMS
24
23
 
25
24
  DEPENDENCIES
26
25
  listlace!
27
- rake
data/README.md CHANGED
@@ -96,14 +96,14 @@ It's basically a numeric selector, but you can pass a String containing a format
96
96
 
97
97
  ### Special selectors
98
98
 
99
- ### all
99
+ #### all
100
100
 
101
101
  `all` returns all the songs in your library.
102
102
 
103
103
  ♫> all
104
104
  => [3560 songs]
105
105
 
106
- ### none
106
+ #### none
107
107
 
108
108
  `none` returns an empty playlist.
109
109
 
@@ -134,6 +134,54 @@ It's basically a numeric selector, but you can pass a String containing a format
134
134
 
135
135
  ♫> stop
136
136
 
137
+ ### skip
138
+
139
+ `skip` goes to the next song. If you give it a number, it will go that many songs ahead.
140
+
141
+ ♫> skip
142
+ ♫> skip 3
143
+
144
+ ### back
145
+
146
+ `back` goes back a song. If you give it a number, it will go that many songs back.
147
+
148
+ ♫> back
149
+ ♫> back 3
150
+
151
+ ### restart
152
+
153
+ `restart` goes back to the beginning of the current song.
154
+
155
+ ♫> restart
156
+
157
+ ### pause
158
+
159
+ `pause` pauses the current song.
160
+
161
+ ♫> pause
162
+
163
+ ### resume
164
+
165
+ `resume` resumes the current song after being paused.
166
+
167
+ ♫> resume
168
+
169
+ ### seek
170
+
171
+ `seek` seeks forward or backward the specified number of seconds. You can also pass a String containing a formatted time, like "1:23", to skip ahead that many minutes and seconds, or "-1:23" to skip backward.
172
+
173
+ ♫> seek 10
174
+ ♫> seek -10
175
+ ♫> seek "1:23"
176
+ ♫> seek "-0:10"
177
+
178
+ ### seek_to
179
+
180
+ `seek_to` seeks to an exact position of the current playing song. You can give it a number of seconds, or a formatted string containing a time.
181
+
182
+ ♫> seek_to 0
183
+ ♫> seek_to "5:00"
184
+
137
185
  ### list
138
186
 
139
187
  `list` with no arguments lists all the songs in your music library. If you pass it a playlist, it will list all the songs in that playlist.
@@ -9,7 +9,9 @@ require "listlace/core_ext/array"
9
9
  class Listlace
10
10
  attr_reader :mpd
11
11
 
12
- include Commands
12
+ include Commands::InfoCommands
13
+ include Commands::PlaybackCommands
14
+ include Commands::QueueCommands
13
15
  include Selectors
14
16
 
15
17
  def initialize(host, port)
@@ -1,81 +1,9 @@
1
+ require "listlace/commands/info_commands"
2
+ require "listlace/commands/playback_commands"
3
+ require "listlace/commands/queue_commands"
4
+
1
5
  class Listlace
2
6
  module Commands
3
- def p(*playlist)
4
- if playlist.empty?
5
- case mpd.status[:state]
6
- when :play
7
- mpd.pause = true
8
- when :pause
9
- mpd.pause = false
10
- when :stop
11
- mpd.play
12
- end
13
- else
14
- mpd.clear
15
- playlist.flatten.each do |song|
16
- mpd.add song.file
17
- end
18
- mpd.play
19
- end
20
- nil
21
- end
22
-
23
- def stop
24
- mpd.stop
25
- nil
26
- end
27
-
28
- def q(*playlist)
29
- if playlist.empty?
30
- mpd.queue
31
- else
32
- mpd.clear
33
- playlist.flatten.each do |song|
34
- mpd.add song.file
35
- end
36
- nil
37
- end
38
- end
39
-
40
- def list(playlist = nil)
41
- (playlist || all).each do |song|
42
- time = TimeHelpers.format_time(song.time)
43
- puts "#{song.artist} - #{song.album} - #{song.title} (#{time})"
44
- end
45
- nil
46
- end
47
-
48
- def artists(playlist = nil)
49
- (playlist || all).group_by(&:artist).each do |artist, songs|
50
- plural = (songs.length == 1) ? "" : "s"
51
- puts "#{artist} (#{songs.length} song#{plural})"
52
- end
53
- nil
54
- end
55
-
56
- def albums(playlist = nil)
57
- (playlist || all).group_by(&:album).each do |album, songs|
58
- plural = (songs.length == 1) ? "" : "s"
59
- puts "#{songs.first.artist} - #{album} (#{songs.length} song#{plural})"
60
- end
61
- nil
62
- end
63
-
64
- def genres(playlist = nil)
65
- (playlist || all).group_by(&:genre).each do |genre, songs|
66
- plural = (songs.length == 1) ? "" : "s"
67
- puts "#{genre} (#{songs.length} song#{plural})"
68
- end
69
- nil
70
- end
71
-
72
- def years(playlist = nil)
73
- (playlist || all).group_by(&:date).each do |year, songs|
74
- plural = (songs.length == 1) ? "" : "s"
75
- puts "#{year} (#{songs.length} song#{plural})"
76
- end
77
- nil
78
- end
79
7
  end
80
8
  end
81
9
 
@@ -0,0 +1,46 @@
1
+ class Listlace
2
+ module Commands
3
+ module InfoCommands
4
+ def list(playlist = nil)
5
+ (playlist || all).each do |song|
6
+ time = TimeHelpers.format_time(song.time)
7
+ puts "#{song.artist} - #{song.album} - #{song.title} (#{time})"
8
+ end
9
+ nil
10
+ end
11
+
12
+ def artists(playlist = nil)
13
+ (playlist || all).group_by(&:artist).each do |artist, songs|
14
+ plural = (songs.length == 1) ? "" : "s"
15
+ puts "#{artist} (#{songs.length} song#{plural})"
16
+ end
17
+ nil
18
+ end
19
+
20
+ def albums(playlist = nil)
21
+ (playlist || all).group_by(&:album).each do |album, songs|
22
+ plural = (songs.length == 1) ? "" : "s"
23
+ puts "#{songs.first.artist} - #{album} (#{songs.length} song#{plural})"
24
+ end
25
+ nil
26
+ end
27
+
28
+ def genres(playlist = nil)
29
+ (playlist || all).group_by(&:genre).each do |genre, songs|
30
+ plural = (songs.length == 1) ? "" : "s"
31
+ puts "#{genre} (#{songs.length} song#{plural})"
32
+ end
33
+ nil
34
+ end
35
+
36
+ def years(playlist = nil)
37
+ (playlist || all).group_by(&:date).each do |year, songs|
38
+ plural = (songs.length == 1) ? "" : "s"
39
+ puts "#{year} (#{songs.length} song#{plural})"
40
+ end
41
+ nil
42
+ end
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,73 @@
1
+ class Listlace
2
+ module Commands
3
+ module PlaybackCommands
4
+ def p(*playlist)
5
+ if playlist.empty?
6
+ case mpd.status[:state]
7
+ when :play
8
+ mpd.pause = true
9
+ when :pause
10
+ mpd.pause = false
11
+ when :stop
12
+ mpd.play
13
+ end
14
+ else
15
+ mpd.clear
16
+ playlist.flatten.each do |song|
17
+ mpd.add song.file
18
+ end
19
+ mpd.play
20
+ end
21
+ nil
22
+ end
23
+
24
+ def stop
25
+ mpd.stop
26
+ nil
27
+ end
28
+
29
+ def skip(n = 1)
30
+ n.times { mpd.next }
31
+ nil
32
+ end
33
+
34
+ def back(n = 1)
35
+ n.times { mpd.previous }
36
+ nil
37
+ end
38
+
39
+ def restart
40
+ seek_to 0
41
+ nil
42
+ end
43
+
44
+ def pause
45
+ mpd.pause = true
46
+ nil
47
+ end
48
+
49
+ def resume
50
+ mpd.pause = false
51
+ nil
52
+ end
53
+
54
+ def seek(time)
55
+ if time.is_a? String
56
+ time = TimeHelpers.parse_time(time)
57
+ end
58
+ stat = mpd.status
59
+ mpd.seek(stat[:time].first + time, pos: stat[:song])
60
+ nil
61
+ end
62
+
63
+ def seek_to(time)
64
+ if time.is_a? String
65
+ time = TimeHelpers.parse_time(time)
66
+ end
67
+ mpd.seek(time, pos: mpd.status[:song])
68
+ nil
69
+ end
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,18 @@
1
+ class Listlace
2
+ module Commands
3
+ module QueueCommands
4
+ def q(*playlist)
5
+ if playlist.empty?
6
+ mpd.queue
7
+ else
8
+ mpd.clear
9
+ playlist.flatten.each do |song|
10
+ mpd.add song.file
11
+ end
12
+ nil
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -4,22 +4,33 @@ class Listlace
4
4
 
5
5
  # Helper method to format a number of seconds as a string like "1:03:56".
6
6
  def format_time(seconds, options = {})
7
- raise ArgumentError, "can't format negative time" if seconds < 0
7
+ negative = false
8
+ if seconds < 0
9
+ negative = true
10
+ seconds = -seconds
11
+ end
8
12
 
9
13
  hours = seconds / 3600
10
14
  minutes = (seconds / 60) % 60
11
15
  seconds = seconds % 60
16
+ sign = negative ? "-" : ""
12
17
 
13
18
  if hours > 0
14
- "%d:%02d:%02d" % [hours, minutes, seconds]
19
+ "%s%d:%02d:%02d" % [sign, hours, minutes, seconds]
15
20
  else
16
- "%d:%02d" % [minutes, seconds]
21
+ "%s%d:%02d" % [sign, minutes, seconds]
17
22
  end
18
23
  end
19
24
 
20
25
  # Helper method to parse a string like "1:03:56" and return the number of
21
26
  # seconds that time length represents.
22
27
  def parse_time(string)
28
+ negative = false
29
+ if string[0] == "-"
30
+ negative = true
31
+ string = string[1..-1]
32
+ end
33
+
23
34
  parts = string.split(":", -1).map(&:to_i)
24
35
 
25
36
  raise ArgumentError, "too many parts" if parts.length > 3
@@ -27,7 +38,9 @@ class Listlace
27
38
 
28
39
  parts.unshift(0) until parts.length == 3
29
40
  hours, minutes, seconds = parts
30
- hours * 3600 + minutes * 60 + seconds
41
+ total_seconds = hours * 3600 + minutes * 60 + seconds
42
+
43
+ total_seconds * (negative ? -1 : 1)
31
44
  end
32
45
  end
33
46
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "listlace"
3
- s.version = "0.2.1"
4
- s.date = "2014-03-24"
3
+ s.version = "0.2.2"
4
+ s.date = "2014-03-25"
5
5
  s.summary = "An mpd (music player daemon) client with a Ruby shell as the interface."
6
6
  s.description = "Listlace is an mpd (music player daemon) client with a Ruby shell as the interface."
7
7
  s.author = "Jeremy Ruten"
@@ -15,12 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.files += ["bin/listlace"]
16
16
  s.files += Dir["lib/**/*.rb"]
17
17
 
18
- %w(bundler pry ruby-mpd).each do |gem_name|
19
- s.add_runtime_dependency gem_name
20
- end
21
-
22
- %w(rake).each do |gem_name|
23
- s.add_development_dependency gem_name
24
- end
18
+ s.add_runtime_dependency "bundler", "~> 1.5"
19
+ s.add_runtime_dependency "pry", "~> 0.9"
20
+ s.add_runtime_dependency "ruby-mpd", "~> 0.3", ">= 0.3.1"
25
21
  end
26
22
 
metadata CHANGED
@@ -1,71 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listlace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ruten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-mpd
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
45
48
  - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: '0'
50
+ version: 0.3.1
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
55
+ - - "~>"
60
56
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
57
+ version: '0.3'
66
58
  - - ">="
67
59
  - !ruby/object:Gem::Version
68
- version: '0'
60
+ version: 0.3.1
69
61
  description: Listlace is an mpd (music player daemon) client with a Ruby shell as
70
62
  the interface.
71
63
  email: jeremy.ruten@gmail.com
@@ -81,6 +73,9 @@ files:
81
73
  - bin/listlace
82
74
  - lib/listlace.rb
83
75
  - lib/listlace/commands.rb
76
+ - lib/listlace/commands/info_commands.rb
77
+ - lib/listlace/commands/playback_commands.rb
78
+ - lib/listlace/commands/queue_commands.rb
84
79
  - lib/listlace/core_ext/array.rb
85
80
  - lib/listlace/selectors.rb
86
81
  - lib/listlace/time_helpers.rb