vkpd 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/vkpd/cli.rb +28 -12
  2. data/lib/vkpd/version.rb +1 -1
  3. metadata +2 -2
data/lib/vkpd/cli.rb CHANGED
@@ -21,8 +21,8 @@ module Vkpd
21
21
  filename = Pathname(__FILE__).dirname+'../../README'
22
22
  puts File.read(filename)
23
23
  exit 0
24
- when '-d', '--debug'
25
- @debug = true
24
+ when '-v', '--verbose'
25
+ @verbose = true
26
26
  when '-c', '--count', /^--count=\d+$/
27
27
  value = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
28
28
  params["count"] = value
@@ -32,6 +32,10 @@ module Vkpd
32
32
  when '-s', '--sort', /^--sort=\d+$/
33
33
  value = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
34
34
  params["sort"] = value
35
+ when '-nf','--no-fix', '--exact'
36
+ params["auto_complete"] = '0'
37
+ when '--https'
38
+ params['https'] = '1'
35
39
  when 'user'
36
40
  method = 'audio.get'
37
41
  if !ARGV.empty? and ARGV.first.match(/^\d+$/)
@@ -45,10 +49,6 @@ module Vkpd
45
49
  when 'add'
46
50
  do_clear = false
47
51
  do_play = false
48
- when '-nf','--no-fix', '--exact'
49
- params["auto_complete"] = '0'
50
- when '--https'
51
- params['https'] = '1'
52
52
  when 'auth'
53
53
  Thread.new do
54
54
  sleep 1
@@ -63,19 +63,15 @@ module Vkpd
63
63
  end
64
64
  end
65
65
 
66
-
67
66
  params["access_token"]=Vkpd::config["access_token"]
68
67
 
69
- connection=Net::HTTP.new("api.vk.com",443)
70
- connection.use_ssl=true
71
- data=connection.get("/method/#{method}?#{hash_to_params(params)}").body
72
- response = JSON.parse(data)["response"]
68
+ response = make_vk_request(method,params)
73
69
  if method.match /search/
74
70
  response.shift
75
71
  end
76
72
  mpd.clear if do_clear
77
73
  response.each do |song|
78
- puts song if @debug
74
+ puts song if @verbose
79
75
  mpd.add song["url"]
80
76
  end
81
77
  mpd.play if do_play
@@ -88,5 +84,25 @@ module Vkpd
88
84
  hash.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join("&")
89
85
  end
90
86
 
87
+ def make_vk_request(method, params)
88
+ connection=Net::HTTP.new("api.vk.com",443)
89
+ connection.use_ssl=true
90
+ data = JSON.parse connection.get("/method/#{method}?#{hash_to_params(params)}").body
91
+ p data if @verbose
92
+ while data['error'] and data['error']['error_code'].to_i == 14
93
+ p data['error'] if @verbose
94
+ captcha_sid = data['error']['captcha_sid']
95
+ captcha_img = data['error']['captcha_img']
96
+ system "display #{captcha_img} &"
97
+ print "captcha: "
98
+ captcha_key = gets.chomp
99
+ params['captcha_sid'] = captcha_sid
100
+ params['captcha_key'] = captcha_key
101
+ data = JSON.parse connection.get("/method/#{method}?#{hash_to_params(params)}").body
102
+ p data if @verbose
103
+ end
104
+ data["response"]
105
+ end
106
+
91
107
  end
92
108
  end
data/lib/vkpd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vkpd
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
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.2.2
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-20 00:00:00.000000000 Z
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra