vlcraptor 0.3.0 → 0.4.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -1
- data/exe/vlcraptor +9 -0
- data/lib/vlcraptor/notifiers.rb +2 -0
- data/lib/vlcraptor/player_controller.rb +22 -17
- data/lib/vlcraptor/queue.rb +29 -0
- data/lib/vlcraptor/scrobbler.rb +15 -11
- data/lib/vlcraptor/version.rb +1 -1
- data/lib/vlcraptor.rb +21 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62d27be7a5541a19d3e2f69cf98ee1506b8b65560deffa547c9e621f860977b9
|
4
|
+
data.tar.gz: af56137e7d23b949a5ba94453f9d3bb4e0c45020722b3d0456393b7c7bfed4b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03d0920671d6dfa40dd866c70a915fe7ac6c13a5d84dd0507cdaa6104d0fc2352b2d4b4ab6af10957b7b3ad078f673a2ceda91552134c0b32172186fcafcb75d
|
7
|
+
data.tar.gz: 8519f300d25106c8138cf4921c03f2394191f28f853220203b09079d39d9f972cf40331f6e30a2a9f8549028014a9d1542f6c1b841fef9a1f772fffa1d86c910
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -37,11 +37,19 @@ You can quit with 'q', pause with ' ', stop with 's', play (resume) with 'p' and
|
|
37
37
|
`vlcraptor queue folder_containing_audio_files audio_file.mp3` will place any number of audio files in the
|
38
38
|
queue and the player should immediately start playing the first track.
|
39
39
|
|
40
|
-
###
|
40
|
+
### Viewing queue contents
|
41
41
|
|
42
42
|
`vlcraptor list` will list currently queued tracks with an estimated start time if the player is currently
|
43
43
|
running and playing a track.
|
44
44
|
|
45
|
+
### Managing queue
|
46
|
+
|
47
|
+
`vlcraptor clear` will clear all queued tracks.
|
48
|
+
|
49
|
+
`vlcraptor remove 2` will remove queued track at index position 2.
|
50
|
+
|
51
|
+
`vlcraptor swap 2 4` will swap the tracks at index positions 2 and 4.
|
52
|
+
|
45
53
|
### Media controls
|
46
54
|
|
47
55
|
`vlcraptor pause` will pause, `vlcraptor stop` will stop and `vlcraptor play` will resume.
|
data/exe/vlcraptor
CHANGED
@@ -11,6 +11,8 @@ command = ARGV.shift
|
|
11
11
|
case command
|
12
12
|
when "autoplay"
|
13
13
|
Vlcraptor.autoplay(ARGV.shift)
|
14
|
+
when "clear"
|
15
|
+
Vlcraptor.clear
|
14
16
|
when "crossfade"
|
15
17
|
Vlcraptor.crossfade(ARGV.shift)
|
16
18
|
when "history"
|
@@ -23,6 +25,8 @@ when "play"
|
|
23
25
|
Vlcraptor.play
|
24
26
|
when "player"
|
25
27
|
Vlcraptor.player
|
28
|
+
when "remove"
|
29
|
+
Vlcraptor.remove(ARGV.shift)
|
26
30
|
when "queue"
|
27
31
|
Vlcraptor.queue(ARGV)
|
28
32
|
when "scrobble"
|
@@ -31,9 +35,12 @@ when "skip"
|
|
31
35
|
Vlcraptor.skip
|
32
36
|
when "stop"
|
33
37
|
Vlcraptor.stop
|
38
|
+
when "swap"
|
39
|
+
Vlcraptor.swap(ARGV)
|
34
40
|
else
|
35
41
|
puts "Unknown command \"#{command}\":"
|
36
42
|
puts " autoplay on/off: continue playing tracks or stop at the end of current track"
|
43
|
+
puts " clear: clear queue"
|
37
44
|
puts " crossfade on/off: 5 second crossfade when changing tracks"
|
38
45
|
puts " history: display play history"
|
39
46
|
puts " list: list current queue"
|
@@ -41,7 +48,9 @@ else
|
|
41
48
|
puts " play: resume after pause/stop"
|
42
49
|
puts " player: start the player"
|
43
50
|
puts " queue paths: queue folders or files containing music tracks"
|
51
|
+
puts " remove a: remove track from queue at index position a"
|
44
52
|
puts " scrobble on/off: send track information to last.fm (requires an api key)"
|
45
53
|
puts " skip: skip the current track"
|
46
54
|
puts " stop: stop the player (resume with play)"
|
55
|
+
puts " swap a b: swap tracks in queue at index positions a and b"
|
47
56
|
end
|
data/lib/vlcraptor/notifiers.rb
CHANGED
@@ -20,7 +20,7 @@ module Vlcraptor
|
|
20
20
|
return on_pause if @preferences.pause?
|
21
21
|
return on_stop if @preferences.stop?
|
22
22
|
return on_play if @preferences.play?
|
23
|
-
return
|
23
|
+
return on_suspended if @suspended
|
24
24
|
return when_playing if @player.playing?
|
25
25
|
return when_auto if @preferences.continue?
|
26
26
|
|
@@ -28,41 +28,45 @@ module Vlcraptor
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def cleanup
|
31
|
+
@notifiers.track_suspended
|
32
|
+
@player.fadeout
|
31
33
|
@player.cleanup
|
32
34
|
end
|
33
35
|
|
34
36
|
private
|
35
37
|
|
36
38
|
def on_pause
|
37
|
-
|
38
|
-
@player.pause
|
39
|
-
@suspended = true
|
40
|
-
@status = "Now Paused"
|
41
|
-
@notifiers.track_suspended
|
42
|
-
when_suspended
|
39
|
+
when_suspended("Now Paused", :pause)
|
43
40
|
end
|
44
41
|
|
45
42
|
def on_stop
|
46
|
-
|
47
|
-
|
43
|
+
when_suspended("Now Stopped", :stop)
|
44
|
+
end
|
45
|
+
|
46
|
+
def when_suspended(status, method)
|
47
|
+
if @player.playing?
|
48
|
+
@player.fadeout
|
49
|
+
@player.send(method)
|
50
|
+
end
|
51
|
+
@status = status
|
48
52
|
@suspended = true
|
49
|
-
@status = "Now Stopped"
|
50
53
|
@notifiers.track_suspended
|
51
|
-
|
54
|
+
on_suspended
|
55
|
+
end
|
56
|
+
|
57
|
+
def on_suspended
|
58
|
+
build
|
52
59
|
end
|
53
60
|
|
54
61
|
def on_play
|
55
|
-
@player.
|
62
|
+
unless @player.playing?
|
63
|
+
@player.fadein
|
64
|
+
end
|
56
65
|
@suspended = false
|
57
|
-
@status = ""
|
58
66
|
@notifiers.track_resumed(@track, @player.time)
|
59
67
|
when_playing_track(@player.remaining)
|
60
68
|
end
|
61
69
|
|
62
|
-
def when_suspended
|
63
|
-
build
|
64
|
-
end
|
65
|
-
|
66
70
|
def when_playing
|
67
71
|
return on_skip if @preferences.skip?
|
68
72
|
return on_crossfade if @preferences.crossfade? && @player.remaining < 5
|
@@ -72,6 +76,7 @@ module Vlcraptor
|
|
72
76
|
|
73
77
|
def on_skip
|
74
78
|
@track = @queue.next
|
79
|
+
@notifiers.track_suspended
|
75
80
|
if @track
|
76
81
|
@notifiers.track_started(@track)
|
77
82
|
@player.crossfade(@track[:path])
|
data/lib/vlcraptor/queue.rb
CHANGED
@@ -18,6 +18,10 @@ module Vlcraptor
|
|
18
18
|
File.exist?(result[:path]) ? result : self.next
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.clear
|
22
|
+
`rm -rf /tmp/queue`
|
23
|
+
end
|
24
|
+
|
21
25
|
def self.length
|
22
26
|
Dir["/tmp/queue/*.yml"].length
|
23
27
|
end
|
@@ -28,6 +32,31 @@ module Vlcraptor
|
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
35
|
+
def self.remove(index)
|
36
|
+
path = Dir["/tmp/queue/*.yml"].sort[index.to_i]
|
37
|
+
if path
|
38
|
+
`rm #{path}`
|
39
|
+
yield
|
40
|
+
else
|
41
|
+
puts "Could not find track at position #{index}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.swap(a, b)
|
46
|
+
all = Dir["/tmp/queue/*.yml"].sort
|
47
|
+
path_a = all[a.to_i]
|
48
|
+
path_b = all[b.to_i]
|
49
|
+
|
50
|
+
if path_a && path_b
|
51
|
+
`mv #{path_a} #{path_a}.tmp`
|
52
|
+
`mv #{path_b} #{path_a}`
|
53
|
+
`mv #{path_a}.tmp #{path_b}`
|
54
|
+
yield
|
55
|
+
else
|
56
|
+
puts "Could not find tracks at positions #{a} and #{b}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
31
60
|
def self.add(path)
|
32
61
|
unless %w[.mp3 .m4a].include?(File.extname(path))
|
33
62
|
puts "skipping #{path}"
|
data/lib/vlcraptor/scrobbler.rb
CHANGED
@@ -16,24 +16,26 @@ module Vlcraptor
|
|
16
16
|
|
17
17
|
def self.ask(prompt)
|
18
18
|
puts prompt
|
19
|
-
gets.chomp
|
19
|
+
gets.chomp.strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.blank(attribute)
|
23
|
+
(attribute || "").length.zero?
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.load
|
23
|
-
conf = Vlcraptor::Settings.new("
|
27
|
+
conf = Vlcraptor::Settings.new("~/.lastfm.yml")
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
conf["secret"] = ask("What is the secret ")
|
29
|
-
end
|
29
|
+
conf[:api_key] = ask("What is the api key? ") if blank(conf[:api_key])
|
30
|
+
conf[:secret] = ask("What is the secret? ") if blank(conf[:secret])
|
31
|
+
conf[:user] = ask("What is your lastfm username? ") if blank(conf[:user])
|
30
32
|
|
31
|
-
conf[
|
33
|
+
return nil if blank(conf[:api_key]) || blank(conf[:secret]) || blank(conf[:user])
|
32
34
|
|
33
|
-
scrobbler = Vlcraptor::Scrobbler.new(conf[
|
35
|
+
scrobbler = Vlcraptor::Scrobbler.new(conf[:api_key], conf[:secret], conf[:user], conf[:session])
|
34
36
|
|
35
|
-
unless conf[
|
36
|
-
conf[
|
37
|
+
unless conf[:session]
|
38
|
+
conf[:session] = scrobbler.fetch_session_key do |url|
|
37
39
|
puts "A browser will now launch to allow to authorise this application to access your lastfm account"
|
38
40
|
`open '#{url}'`
|
39
41
|
puts "Press enter when you have authorised the application"
|
@@ -41,6 +43,8 @@ module Vlcraptor
|
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
46
|
+
return nil if blank(conf[:session])
|
47
|
+
|
44
48
|
scrobbler
|
45
49
|
end
|
46
50
|
|
data/lib/vlcraptor/version.rb
CHANGED
data/lib/vlcraptor.rb
CHANGED
@@ -7,12 +7,17 @@ require_relative "vlcraptor/player_controller"
|
|
7
7
|
require_relative "vlcraptor/preferences"
|
8
8
|
require_relative "vlcraptor/queue"
|
9
9
|
require_relative "vlcraptor/notifiers"
|
10
|
+
require_relative "vlcraptor/scrobbler"
|
10
11
|
|
11
12
|
module Vlcraptor
|
12
13
|
def self.autoplay(value)
|
13
14
|
Vlcraptor::Preferences.new[:autoplay] = value == "on"
|
14
15
|
end
|
15
16
|
|
17
|
+
def self.clear
|
18
|
+
Vlcraptor::Queue.clear
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.crossfade(value)
|
17
22
|
Vlcraptor::Preferences.new[:crossfade] = value == "on"
|
18
23
|
end
|
@@ -24,8 +29,9 @@ module Vlcraptor
|
|
24
29
|
def self.list
|
25
30
|
started = Vlcraptor::Preferences.new[:started]
|
26
31
|
offset = 0
|
32
|
+
index = 0
|
27
33
|
Vlcraptor::Queue.each do |track|
|
28
|
-
array = []
|
34
|
+
array = [Rainbow(index.to_s).magenta]
|
29
35
|
array << Time.at(started + offset).strftime("%I:%M:%S") if started
|
30
36
|
array += [Rainbow(track[:title]).green, "by", Rainbow(track[:artist]).yellow]
|
31
37
|
array += ["from", Rainbow(track[:album]).cyan] if (track[:album] || "").length.positive?
|
@@ -36,6 +42,7 @@ module Vlcraptor
|
|
36
42
|
end
|
37
43
|
puts array.join(" ")
|
38
44
|
offset += track[:length]
|
45
|
+
index += 1
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
@@ -96,6 +103,10 @@ module Vlcraptor
|
|
96
103
|
Curses.close_screen
|
97
104
|
end
|
98
105
|
|
106
|
+
def self.remove(index)
|
107
|
+
Vlcraptor::Queue.remove(index) { list }
|
108
|
+
end
|
109
|
+
|
99
110
|
def self.queue(paths)
|
100
111
|
paths.each do |path|
|
101
112
|
if File.file?(path)
|
@@ -109,7 +120,10 @@ module Vlcraptor
|
|
109
120
|
end
|
110
121
|
|
111
122
|
def self.scrobble(value)
|
112
|
-
Vlcraptor::Preferences.new
|
123
|
+
preferences = Vlcraptor::Preferences.new
|
124
|
+
preferences[:scrobble] = value == "on"
|
125
|
+
scrobbler = Vlcraptor::Scrobbler.load if preferences.scrobble?
|
126
|
+
preferences[:scrobble] = false unless scrobbler
|
113
127
|
end
|
114
128
|
|
115
129
|
def self.skip
|
@@ -119,4 +133,9 @@ module Vlcraptor
|
|
119
133
|
def self.stop
|
120
134
|
Vlcraptor::Preferences.new[:stop] = true
|
121
135
|
end
|
136
|
+
|
137
|
+
def self.swap(args)
|
138
|
+
a, b = *args
|
139
|
+
Vlcraptor::Queue.swap(a, b) { list }
|
140
|
+
end
|
122
141
|
end
|