mikeplayer 1.1.2 → 1.3.0

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: 75710f4741268d6bbc3c8708b626733ac02bf3dbbcaf3c8224761ddaea270ca4
4
- data.tar.gz: 75fff78aa2ebfa4b4a2815a743fca6a923a4f85ee9bddf25f528167b08cdfaf0
3
+ metadata.gz: dc4762ff6cf9ce9e9cbbd87c1d46a92629faab94444a79423a9797ce257fc284
4
+ data.tar.gz: d629eb95a5a352242dc03b41a1565bf71089ef2bc8986519131f020db73a69fc
5
5
  SHA512:
6
- metadata.gz: 8d20411df67b44cd5f25b4aaea1b1ab22e632eaa8505a47c3fbee652e88e75e314e42785e525cfbb97bf71876fdf4300165248d90deb0bfeaf9be1eeba459e06
7
- data.tar.gz: a2877632fb5b48cb60d1eec6502f8b3d5015384c952852a47d6aace6531690b6adee4d66851e07ec29bf040d3b69139bdd5ca5d95bb4cc20c2d28ae66fbb65c2
6
+ metadata.gz: b73c5011fea15ef7c33866d7abd727132a7f23b737c8985bbbf223e724517dcc8de6d17b592a83e9eb2f11035d585504fe499f2ca755fd0c457e9be83b4b0ecc
7
+ data.tar.gz: 80cad1d3712f04b2886a1dca59fa850aa9fb6c8b3497759e9e61fed8048389465e198c0e20e58c6fd3e65a69f5bb681c3d4e47a0c864ab40775faba7c0698aa1
data/bin/MikePlayer.rb CHANGED
@@ -14,14 +14,15 @@ OptionParser.new do |opt|
14
14
 
15
15
  EOF
16
16
  opt.on('-s', '--shuffle', 'Shuffle playlist.') { |o| options[:shuffle] = true }
17
- opt.on('-r', '--random n', 'Create playlist with randomly picked n songs.') { |o| options[:random] = o.to_i }
17
+ opt.on('-r', '--random n', Integer, 'Create playlist with randomly picked n songs.') { |o| options[:random] = o }
18
18
  opt.on('-o', '--overwrite', 'Overwrite playlist.') { |o| options[:overwrite] = true }
19
- opt.on('-v', '--volume n', 'Changes default volume.') { |o| options[:volume] = o }
19
+ opt.on('-v', '--volume n', Float, 'Changes default volume.') { |o| options[:volume] = o }
20
20
  opt.on('-p', '--playlist name', 'Play playlist name.') { |o| options[:playlist] = o }
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
- opt.on('-t', '--time minutes', 'Limit time to number of minutes.') { |o| options[:minutes] = o }
23
+ opt.on('-t', '--time minutes', Integer, 'Limit time to number of minutes.') { |o| options[:minutes] = o }
24
24
  opt.on('-x', '--debug', 'Turn on debug.') { |o| options[:debug] = true }
25
+ opt.on('-f', '--fullscreen', 'Use an alternate full-screen buffer while playing.') { |o| options[:fullscreen] = true }
25
26
  end.parse!
26
27
 
27
28
  MikePlayer::Player.new(options, ARGV).play
@@ -2,25 +2,70 @@ module MikePlayer
2
2
  class Display
3
3
  PAUSE_INDICATOR = '||'.freeze
4
4
  INDICATOR_SIZE = 4
5
+ PROGRESS_WIDTH = 40
5
6
 
6
- def initialize
7
- @width = 0
8
- @indicator = ''
9
- @changed = false
7
+ TITLE_ROW = 4
8
+ BAR_ROW = 5
9
+ HINT_ROW = 7
10
+
11
+ HINT_TEXT = 'c: pause/play v: next z: previous t: set timer q: quit'.freeze
12
+
13
+ RESET = "\e[0m".freeze
14
+ TITLE_COLOR = "\e[1;36m".freeze # bold cyan
15
+ DIM_COLOR = "\e[2m".freeze # dim gray
16
+ BANNER_COLOR = "\e[1;37m".freeze # bold white
17
+ ELAPSED_COLOR = "\e[37m".freeze # white
18
+ COUNTDOWN_COLOR = "\e[33m".freeze # yellow
19
+ PLAY_COLOR = "\e[32m".freeze # green
20
+ PAUSE_COLOR = "\e[1;31m".freeze # bold red
21
+
22
+ ENTER_ALT_SCREEN = "\e[?1049h\e[2J\e[H\e[?25l".freeze
23
+ EXIT_ALT_SCREEN = "\e[?25h\e[?1049l".freeze
24
+
25
+ def self.colorize(text, color)
26
+ return text unless $stdout.tty?
27
+
28
+ "#{color}#{text}#{RESET}"
29
+ end
30
+
31
+ def self.enter_fullscreen
32
+ print(ENTER_ALT_SCREEN)
33
+ $stdout.flush
34
+ end
35
+
36
+ def self.exit_fullscreen
37
+ print(EXIT_ALT_SCREEN)
38
+ $stdout.flush
39
+ end
40
+
41
+ def initialize(fullscreen: false)
42
+ @width = 0
43
+ @indicator = ''
44
+ @paused = false
45
+ @changed = false
46
+ @color = $stdout.tty?
47
+ @fullscreen = fullscreen
48
+ @elapsed_seconds = 0
49
+ @length = 0
10
50
  end
11
51
 
12
52
  def song_info=(v)
13
- @info_prefix = "\r#{v}".freeze
53
+ @position = v[:position].freeze
54
+ @title = v[:title].freeze
55
+ @length = v[:length].to_f
14
56
  end
15
57
 
16
58
  def elapsed=(v)
59
+ @elapsed_seconds = v
17
60
  @indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE)
61
+ @paused = false
18
62
  @changed = true
19
63
  end
20
64
 
21
65
  def paused
22
- if (false == @indicator.include?(PAUSE_INDICATOR))
66
+ if (false == @paused)
23
67
  @indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE)
68
+ @paused = true
24
69
  @changed = true
25
70
  end
26
71
  end
@@ -28,22 +73,76 @@ module MikePlayer
28
73
  def display!(elapsed_info, countdown = nil)
29
74
  return unless changed?
30
75
 
76
+ if @fullscreen
77
+ display_panel!(elapsed_info, countdown)
78
+ else
79
+ display_line!(elapsed_info, countdown)
80
+ end
81
+ end
82
+
83
+ def changed?
84
+ true == @changed
85
+ end
86
+
87
+ private
88
+
89
+ def display_line!(elapsed_info, countdown)
31
90
  mindicator = "(#{countdown}↓) " if countdown
32
91
 
33
- print("\r" << ' '.ljust(@width))
92
+ position = colorize(@position, DIM_COLOR)
93
+ title = colorize(@title, TITLE_COLOR)
94
+ elapsed = colorize(elapsed_info, ELAPSED_COLOR)
95
+ indicator = colorize(@indicator, @paused ? PAUSE_COLOR : PLAY_COLOR)
96
+ count = countdown ? colorize(mindicator, COUNTDOWN_COLOR) : ''
97
+
98
+ plain_info = "Playing #{@position}: #{@title} #{elapsed_info} #{mindicator}#{@indicator}"
99
+ info = "\rPlaying #{position}: #{title} #{elapsed} #{count}#{indicator}"
34
100
 
35
- info = "#{@info_prefix} #{elapsed_info} #{mindicator}#{@indicator}"
101
+ print("\r" << ' '.ljust(@width))
36
102
 
37
103
  print(info)
38
104
 
39
- @width = info.size
105
+ @width = plain_info.size
40
106
  @changed = false
41
107
 
42
108
  $stdout.flush
43
109
  end
44
110
 
45
- def changed?
46
- true == @changed
111
+ def display_panel!(elapsed_info, countdown)
112
+ mindicator = "(#{countdown}↓) " if countdown
113
+ count = countdown ? colorize(mindicator, COUNTDOWN_COLOR) : ''
114
+ state = colorize(@paused ? 'PAUSED' : 'PLAYING', @paused ? PAUSE_COLOR : PLAY_COLOR)
115
+
116
+ move_to(TITLE_ROW)
117
+ print("Playing #{colorize(@position, DIM_COLOR)}: #{colorize(@title, TITLE_COLOR)}")
118
+
119
+ move_to(BAR_ROW)
120
+ print("#{progress_bar} #{colorize(elapsed_info, ELAPSED_COLOR)} #{count}#{state}")
121
+
122
+ move_to(HINT_ROW)
123
+ print(colorize(HINT_TEXT, DIM_COLOR))
124
+
125
+ @changed = false
126
+
127
+ $stdout.flush
128
+ end
129
+
130
+ def move_to(row)
131
+ print("\e[#{row};1H\e[2K")
132
+ end
133
+
134
+ def progress_bar
135
+ pct = @length.positive? ? (@elapsed_seconds.to_f / @length).clamp(0, 1) : 0
136
+ filled = (pct * PROGRESS_WIDTH).round
137
+ bar = "[#{'#' * filled}#{'-' * (PROGRESS_WIDTH - filled)}]"
138
+
139
+ colorize(bar, @paused ? PAUSE_COLOR : PLAY_COLOR)
140
+ end
141
+
142
+ def colorize(text, color)
143
+ return text unless @color
144
+
145
+ "#{color}#{text}#{RESET}"
47
146
  end
48
147
  end
49
148
  end
@@ -16,6 +16,7 @@ module MikePlayer
16
16
 
17
17
  if paused?
18
18
  start_position = @elapsed
19
+ @paused = false
19
20
  else
20
21
  @elapsed = 0
21
22
  end
@@ -69,8 +69,9 @@ module MikePlayer
69
69
 
70
70
  def song_info(i)
71
71
  song_i_str = "#{i + 1}".rjust(self.size.to_s.size)
72
+ song = get(i)
72
73
 
73
- return "Playing (#{song_i_str}/#{self.size}): #{get(i).info}".freeze
74
+ return { position: "(#{song_i_str}/#{self.size})", title: song.info, length: song.length }
74
75
  end
75
76
 
76
77
  def size
@@ -16,8 +16,9 @@ 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]
20
- @random = options[:random].to_i
19
+ @debug = options[:debug]
20
+ @random = options[:random].to_i
21
+ @fullscreen = options[:fullscreen]
21
22
 
22
23
  if (false == Dir.exist?(@settings_dir))
23
24
  Dir.mkdir(@settings_dir)
@@ -48,6 +49,10 @@ module MikePlayer
48
49
  return true == @list
49
50
  end
50
51
 
52
+ def fullscreen?
53
+ return true == @fullscreen
54
+ end
55
+
51
56
  private
52
57
 
53
58
  def find_playlist(user_option)
@@ -1,3 +1,3 @@
1
1
  module MikePlayer
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
data/lib/mikeplayer.rb CHANGED
@@ -49,8 +49,13 @@ module MikePlayer
49
49
  def play
50
50
  @playlist.shuffle! if @settings.shuffle?
51
51
 
52
- puts "Mike Player v#{MikePlayer::VERSION}"
53
- puts "Playlist #{@playlist.info}\n"
52
+ if @settings.fullscreen?
53
+ Display.enter_fullscreen
54
+ at_exit { Display.exit_fullscreen }
55
+ end
56
+
57
+ puts Display.colorize("Mike Player v#{MikePlayer::VERSION}", Display::BANNER_COLOR)
58
+ puts "#{Display.colorize("Playlist #{@playlist.info}", Display::DIM_COLOR)}\n"
54
59
 
55
60
  if (0 == @playlist.size)
56
61
  puts "No songs in playlist."
@@ -59,7 +64,7 @@ module MikePlayer
59
64
  end
60
65
 
61
66
  @thread = Thread.new do
62
- @display = Display.new
67
+ @display = Display.new(fullscreen: @settings.fullscreen?)
63
68
  @song_i = 0
64
69
 
65
70
  while (@song_i < @playlist.size)
@@ -79,12 +84,14 @@ module MikePlayer
79
84
  sleep(sleep_time)
80
85
  end
81
86
 
82
- if playing? && @player.stopped?
83
- next_song
84
- elsif paused?
87
+ if @player.paused?
88
+ @display.display!(song.length_str(@player.elapsed), minutes_remaining)
89
+
85
90
  while paused?
86
91
  sleep(sleep_time)
87
92
  end
93
+ elsif playing?
94
+ next_song
88
95
  end
89
96
  end
90
97
 
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.1.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Crockett