vkpd 1.3.3 → 1.3.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
  SHA1:
3
- metadata.gz: 56320686f21b1c1cd391dfca5c9797fedf34a6d9
4
- data.tar.gz: dfae90e3d340d7f7491ccda89061c7d10b60afd0
3
+ metadata.gz: 9f0172230df5bc278a55b6381daeba78174cddd6
4
+ data.tar.gz: e075f4be0f23dd55099f70df865ccefd535e8bb0
5
5
  SHA512:
6
- metadata.gz: 3629d7c611799054c2d2663b31df0ee92251b31946fd0d4c933b0cfab784228e195faeebd00ed65e6f7eb8dda85b59b2bb730b0a402549c293e77a0e68a7935f
7
- data.tar.gz: 4cd9854ec60de5bc842c1dc5f6ed3dce18df80ec1539533678d15b5435f7affb5f08b3e11ce5b8e0c29061cd89b2d0fee66fe5dc5a420c51e58d49417e74d140
6
+ metadata.gz: 31cec65e08e73c75a11d304cd2712668e97a76f24be1df3f54c925128eef2449c67b7fe43deaffcdb768aa3584e905bd07484a811f06722a91a50184dfa1ae00
7
+ data.tar.gz: 2413965094bf9397bdad20c0117818b7de9ed2e4f64accc95aa20f5e4157920164753da07d95b6d7ffee4663a31a7fb1e5b92a45c09e22bcc63e930a21d6a9c3
data/lib/vkpd.rb CHANGED
@@ -7,6 +7,7 @@ require 'io/console'
7
7
  require 'yaml'
8
8
  require 'json'
9
9
  require 'pathname'
10
+ require 'tempfile'
10
11
  require 'sinatra/base'
11
12
  require 'launchy'
12
13
  require 'ruby-mpd'
data/lib/vkpd/cli.rb CHANGED
@@ -9,7 +9,7 @@ module Vkpd
9
9
  do_clear = true
10
10
  do_play = true
11
11
  params["auto_complete"] = '1'
12
- player = ENV['VKPD_PLAYER'].to_sym || :mpd
12
+ player = ENV['VKPD_PLAYER'] || 'mpd'
13
13
  random = false
14
14
 
15
15
  if ARGV.empty?
@@ -29,7 +29,6 @@ module Vkpd
29
29
  random = true
30
30
  when '-p', '--player', /^--player=\w+$/
31
31
  player = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
32
- player = player.to_sym
33
32
  when '-c', '--count', /^--count=\d+$/
34
33
  value = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
35
34
  params["count"] = value
@@ -80,29 +79,17 @@ module Vkpd
80
79
  response = response.shuffle if random
81
80
 
82
81
  case player
83
- when :mpd
82
+ when 'mpd'
84
83
  mpd.clear if do_clear
85
84
  response.each do |song|
86
85
  puts song if @verbose
87
86
  mpd.add song["url"]
88
87
  end
89
88
  mpd.play if do_play
90
- when :mplayer, :mpv
91
- catch :stop do
92
- response.each do |song|
93
- ap song
94
- system "#{player} -cache 8192 -cache-min 2 #{song['url']}"
95
- begin
96
- Timeout::timeout 0.25 do
97
- case key = STDIN.getch
98
- when 'q' then throw :stop
99
- end
100
- end
101
- rescue Timeout::Error
102
- # do nothing
103
- end
104
- end
105
- end
89
+ when 'mplayer', 'mpv'
90
+ with_playlist(response){|pls| system "#{player} -cache 8192 -cache-min 2 -playlist #{pls}" }
91
+ else # e.g. "vlc -I ncurses"
92
+ with_playlist(response){|pls| system "#{player} #{pls}" }
106
93
  end
107
94
  end
108
95
 
@@ -133,5 +120,23 @@ module Vkpd
133
120
  data["response"]
134
121
  end
135
122
 
123
+ def with_playlist(response)
124
+ file = Tempfile.new(['vkpd','.pls'])
125
+ write_playlist(file, response)
126
+ file.close
127
+ yield file.path
128
+ ensure
129
+ file.unlink
130
+ end
131
+
132
+ def write_playlist(f, response)
133
+ f.puts '[playlist]'
134
+ f.puts "NumberOfEntries=#{response.size}"
135
+ response.each_with_index do |song,i|
136
+ f.puts "File#{i+1}=#{song['url']}"
137
+ f.puts "Title#{i+1}=#{song['artist']} - #{song['title']}"
138
+ f.puts "Length#{i+1}=#{song['duration']}"
139
+ end
140
+ end
136
141
  end
137
142
  end
data/lib/vkpd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vkpd
2
- VERSION = "1.3.3"
2
+ VERSION = "1.3.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vkpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ales Guzik