mikeplayer 1.0.3 → 1.0.4

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: 129df9ce63171d9efbe8bd1e581fdbfdf33fdadf127936089db72149ebd76a54
4
- data.tar.gz: 25f8be729ae785873137a34e291c63983fcb9a5ff71ccb035e6160bbb3448007
3
+ metadata.gz: 6447a8b4d80be57938640f4beaa73d51e158b71a5616e4fd7867f87a1a25a792
4
+ data.tar.gz: 30b3252b18975ab2e62f8bd07d2a6021902b86c8819e7789f959cb196ddb9ae5
5
5
  SHA512:
6
- metadata.gz: b1ec4ae4f8a765ffeed9fb96d7097f97392a27db66211a4bfc4bb14f7a1636b876ec40ecd84458a8ce8a53050cc160d36769a18088fa99533ce927e8ac5185c8
7
- data.tar.gz: eebd1b3afce640dd29ba8e639122f56b64c7b7e0878a1b50e0f7e72cc78a4b258708e50ef8cde1e5fc1f43916b39b42444339b339ad488cdada53a387692ac6e
6
+ metadata.gz: a93ea2bef948f0bc1fec7ae071b3549448366c5333b22182de34dd01b52b3bee5073bf06fdd0f6f5b6df709d2aaaae8b9b39d0b0730eb886748a6dd75774e6fb
7
+ data.tar.gz: 0a72819b5c7a56dd3658ed2e6b0c9872c2afb2c4885ec4f2b06f5b84c40dcddf47b22878aac7820c232592dce3a95a64fe67db698f1487c764a6fab4df4aef52
data/bin/MikePlayer.rb CHANGED
@@ -21,6 +21,7 @@ OptionParser.new do |opt|
21
21
  opt.on('-l', '--list', 'List songs in playlist.') { |o| options[:list] = true; }
22
22
  opt.on('-d', '--directory name', 'Directory to find mp3s.') { |o| options[:directory] = o }
23
23
  opt.on('-t', '--time minutes', 'Limit time to number of minutes.') { |o| options[:minutes] = o }
24
+ opt.on('-x', '--debug', 'Turn on debug.') { |o| options[:debug] = true }
24
25
  end.parse!
25
26
 
26
27
  MikePlayer::Player.new(options, ARGV).play
@@ -5,12 +5,11 @@ module MikePlayer
5
5
  def initialize(filename)
6
6
  @filename = filename
7
7
  @songs = []
8
- @song_i = 0
9
8
  @length = 0
10
9
 
11
10
  load_songs
12
11
 
13
- @loaded_song_count = @songs.size
12
+ @loaded_song_count = self.size
14
13
  end
15
14
 
16
15
  def <<(song)
@@ -44,22 +43,8 @@ module MikePlayer
44
43
  return self
45
44
  end
46
45
 
47
- def current
48
- return @songs[@song_i]
49
- end
50
-
51
- def next
52
- @song_i += 1
53
-
54
- return self.current
55
- end
56
-
57
- def previous
58
- @song_i -= 1
59
-
60
- @song_i = 0 if @song_i < 0
61
-
62
- return self.current
46
+ def get(i)
47
+ return @songs[i]
63
48
  end
64
49
 
65
50
  def shuffle!
@@ -79,17 +64,17 @@ module MikePlayer
79
64
  end
80
65
 
81
66
  def info
82
- return "#{self.name} loaded #{@loaded_song_count} songs with length #{Song.as_duration_str(@length)}, added #{@songs.size - @loaded_song_count}"
67
+ return "#{self.name} loaded #{@loaded_song_count} songs with length #{Song.as_duration_str(@length)}, added #{self.size - @loaded_song_count}"
83
68
  end
84
69
 
85
- def current_song_info
86
- song_i_str = "#{@song_i + 1}".rjust(@songs.size.to_s.size)
70
+ def song_info(i)
71
+ song_i_str = "#{i + 1}".rjust(self.size.to_s.size)
87
72
 
88
- return "Playing (#{song_i_str}/#{@songs.size}): #{current.info}".freeze
73
+ return "Playing (#{song_i_str}/#{self.size}): #{get(i).info}".freeze
89
74
  end
90
75
 
91
- def finished?
92
- return @song_i >= @songs.size
76
+ def size
77
+ return @songs.size
93
78
  end
94
79
 
95
80
  private
@@ -16,6 +16,7 @@ module MikePlayer
16
16
  @music_dir = options[:directory] || File.join(@home, DEFAULT_DIRECTORY)
17
17
  @settings_dir = options[:settings] || File.join(@home, SETTINGS_DIRECTORY)
18
18
  @minutes = options[:minutes].to_i
19
+ @debug = options[:debug]
19
20
  @random = options[:random].to_i
20
21
 
21
22
  if (false == Dir.exist?(@settings_dir))
@@ -35,6 +36,10 @@ module MikePlayer
35
36
  return 0 < @random
36
37
  end
37
38
 
39
+ def debug?
40
+ return (true == @debug)
41
+ end
42
+
38
43
  def overwrite?
39
44
  return true == @overwrite
40
45
  end
@@ -23,7 +23,7 @@ module MikePlayer
23
23
  end
24
24
 
25
25
  def length
26
- return @mp3info.length
26
+ return @mp3info.length || 0
27
27
  end
28
28
 
29
29
  def length_str(elapsed_time)
@@ -1,3 +1,3 @@
1
1
  module MikePlayer
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.4'.freeze
3
3
  end
data/lib/mikeplayer.rb CHANGED
@@ -10,7 +10,8 @@ require 'mikeplayer/song'
10
10
 
11
11
  module MikePlayer
12
12
  class Player
13
- PAUSE_INDICATOR = " ||".freeze
13
+ PAUSE_INDICATOR = "||".freeze
14
+ INDICATOR_SIZE = 4
14
15
  SLEEP_SETTING = 0.5
15
16
  STOPPED = :stopped
16
17
  PLAYING = :playing
@@ -50,19 +51,21 @@ module MikePlayer
50
51
  puts "Mike Player v#{MikePlayer::VERSION}"
51
52
  puts "Playlist #{@playlist.info}\n"
52
53
 
53
- if @playlist.finished?
54
+ if (0 == @playlist.size)
54
55
  puts "No songs in playlist."
55
56
 
56
57
  exit 1
57
58
  end
58
59
 
59
60
  @thread = Thread.new do
61
+ @song_i = 0
60
62
  display_width = 0
61
63
 
62
- while (false == @playlist.finished?)
63
- song = @playlist.current
64
+ while (@song_i < @playlist.size)
65
+ song = @playlist.get(@song_i)
64
66
  @song_start = Time.now
65
- info_prefix = "\r#{@playlist.current_song_info}".freeze
67
+ @pause_time = nil
68
+ info_prefix = "\r#{@playlist.song_info(@song_i)}".freeze
66
69
 
67
70
  stdin, stdother, thread_info = Open3.popen2e('play', '--no-show-progress', '--volume', @settings.volume, song.filename)
68
71
 
@@ -75,10 +78,10 @@ module MikePlayer
75
78
  pause_if_over_time_limit
76
79
 
77
80
  if (true == playing?)
78
- indicator = "#{'>' * (playing_time % 4)}".ljust(4)
81
+ indicator = "#{'>' * (playing_time % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE)
79
82
  info_changed = true
80
83
  elsif (true == paused?) && (PAUSE_INDICATOR != indicator)
81
- indicator = PAUSE_INDICATOR
84
+ indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE)
82
85
  info_changed = true
83
86
  end
84
87
 
@@ -109,8 +112,8 @@ module MikePlayer
109
112
 
110
113
  @pid = nil
111
114
 
112
- if (true == playing?)
113
- next_song unless @pid.nil?
115
+ if (true == playing?) && (playing_time >= (song.length - 1))
116
+ next_song
114
117
  end
115
118
  end
116
119
 
@@ -198,10 +201,6 @@ module MikePlayer
198
201
  end
199
202
 
200
203
  def stop_song
201
- if (true == paused?)
202
- kill("CONT")
203
- end
204
-
205
204
  kill("INT")
206
205
 
207
206
  sleep 0.2
@@ -211,7 +210,6 @@ module MikePlayer
211
210
  end
212
211
 
213
212
  @state = STOPPED
214
- @pid = nil
215
213
  end
216
214
 
217
215
  def pid_alive?(pid = @pid)
@@ -223,16 +221,20 @@ module MikePlayer
223
221
  end
224
222
 
225
223
  def next_song
224
+ debug('n')
226
225
  stop_song
227
226
 
228
- @playlist.next
227
+ @song_i += 1
229
228
  end
230
229
 
231
230
  def previous_song
231
+ debug('p')
232
232
  stop_song
233
233
 
234
234
  if (playing_time < 10)
235
- @playlist.previous
235
+ @song_i -= 1 unless @song_i <= 0
236
+ else
237
+ debug('x')
236
238
  end
237
239
  end
238
240
 
@@ -271,5 +273,9 @@ module MikePlayer
271
273
  return (@minutes - ((Time.now - @timer_start).to_i / 60).to_i)
272
274
  end
273
275
  end
276
+
277
+ def debug(str)
278
+ print(str) if @settings.debug?
279
+ end
274
280
  end
275
281
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikeplayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Crockett