vkpd 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README +37 -0
- data/Rakefile +1 -0
- data/bin/vkpd +3 -0
- data/lib/vkpd/auth.rb +32 -0
- data/lib/vkpd/cli.rb +100 -0
- data/lib/vkpd/version.rb +3 -0
- data/lib/vkpd.rb +29 -0
- data/vkpd.gemspec +23 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ales Guzik
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
vkpd [options] [search request]
|
2
|
+
|
3
|
+
Requirements:
|
4
|
+
vkpd requires mpc to work and sinatra to authenticate
|
5
|
+
|
6
|
+
Options:
|
7
|
+
|
8
|
+
-c, --count=n
|
9
|
+
Limit songs count
|
10
|
+
-o, --offset=n
|
11
|
+
Drop first n results
|
12
|
+
-s, --sort=n
|
13
|
+
Sort by: 0 - popularity, 1 - length, 2 - upload date
|
14
|
+
-nf, --no-fix, --exact
|
15
|
+
Do not try to fix typos
|
16
|
+
user [user_id]
|
17
|
+
Load user songs. If user_id not supplied use current user's id
|
18
|
+
group <group_id>
|
19
|
+
Load group songs
|
20
|
+
add
|
21
|
+
Add songs to current playlist instead of replacing it
|
22
|
+
|
23
|
+
Some examples:
|
24
|
+
vkpd Beatles # replaces current mpd playlist with The Beatles' songs and starts playing
|
25
|
+
vkpd play Beatles # the same
|
26
|
+
vkpd add Beatles # adds found songs to playlist and starts playing
|
27
|
+
vkpd -c 5 Beatles # get just first five search results
|
28
|
+
vkpd -c 5 -o 5 beatles # get second five results
|
29
|
+
vkpd --count 5 --offset=5 beatles # the same
|
30
|
+
vkpd user 3885655 # plays user's songs
|
31
|
+
vkpd user 3885655 -c 3 # plays last three songs added by user
|
32
|
+
vkpd user # current user's songs
|
33
|
+
vkpd user -c 1 # current user's last added song
|
34
|
+
vkpd group 1 # plays songs from group with id = 1
|
35
|
+
vkpd --no-fix Beetles # prevents from searching for Beatles
|
36
|
+
vkpd -nf Beetles # same as above
|
37
|
+
vkpd -s 1 Beatles # sorted by length. 0 to sort by popularity, 2 to sort by upload date
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/vkpd
ADDED
data/lib/vkpd/auth.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8; mode: ruby -*-
|
2
|
+
module Vkpd
|
3
|
+
class Auth < Sinatra::Base
|
4
|
+
def auth_url(app_id,settings,redirect_uri,display)
|
5
|
+
"http://oauth.vkontakte.ru/authorize?client_id=#{app_id}&scope=#{settings}&redirect_uri=#{redirect_uri}&display=#{display}&response_type=token"
|
6
|
+
end
|
7
|
+
|
8
|
+
get '/' do
|
9
|
+
redirect auth_url(APP_ID,"audio,offline","localhost.localdomain:#{request.port}/return","page")
|
10
|
+
end
|
11
|
+
|
12
|
+
get '/return' do
|
13
|
+
'<html><head><script type="text/javascript" src="https://www.google.com/jsapi"></script><script>
|
14
|
+
google.load("jquery", "1.7.1");
|
15
|
+
var hash = location.hash.replace("#","/auth_data?");
|
16
|
+
location.href = hash;
|
17
|
+
</script></head><body>'+ params.to_s + '</body></html>'
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/auth_data' do
|
21
|
+
File.open(Vkpd::config_path, "w") do |f|
|
22
|
+
f.write(params.merge({"app_id" => APP_ID}).to_yaml)
|
23
|
+
end
|
24
|
+
Thread.new do
|
25
|
+
sleep 0.5
|
26
|
+
puts "Authorized. Terminating now."
|
27
|
+
Kernel.exec("true")
|
28
|
+
end
|
29
|
+
"authorized. now close me and go back to your term"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/vkpd/cli.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
module Vkpd
|
2
|
+
class CLI
|
3
|
+
# Reads config file, parses it as yaml and caches the result
|
4
|
+
def config
|
5
|
+
unless File.exist? Vkpd::config_path
|
6
|
+
puts 'Please authenticate. Start vkpd-auth.rb and point your browser to http://localhost.localdomain:4567/'
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
@config ||= YAML.load File.read(Vkpd::config_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
# main CLI method
|
13
|
+
def main
|
14
|
+
method = "audio.search"
|
15
|
+
params = {}
|
16
|
+
action_before = 'mpc clear'
|
17
|
+
action_after = 'mpc play'
|
18
|
+
params["auto_complete"] = '1'
|
19
|
+
|
20
|
+
if ARGV.empty?
|
21
|
+
ARGV.push "-h"
|
22
|
+
end
|
23
|
+
|
24
|
+
while ARGV.size > 0
|
25
|
+
current = ARGV.shift
|
26
|
+
case current
|
27
|
+
when '-h','--help'
|
28
|
+
filename = Pathname(__FILE__).dirname+'../../README'
|
29
|
+
puts File.read(filename)
|
30
|
+
exit 0
|
31
|
+
when '-d', '--debug'
|
32
|
+
@debug = true
|
33
|
+
when '-c', '--count', /^--count=\d+$/
|
34
|
+
value = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
|
35
|
+
params["count"] = value
|
36
|
+
when '-o', '--offset', /^--offset=\d+$/
|
37
|
+
value = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
|
38
|
+
params["offset"] = value
|
39
|
+
when '-s', '--sort', /^--sort=\d+$/
|
40
|
+
value = current.include?("=") ? current.match(/=(.*)/)[1] : ARGV.shift
|
41
|
+
params["sort"] = value
|
42
|
+
when 'user'
|
43
|
+
method = 'audio.get'
|
44
|
+
if !ARGV.empty? and ARGV.first.match(/^\d+$/)
|
45
|
+
params['uid'] = ARGV.shift
|
46
|
+
else
|
47
|
+
params['uid'] = config["user_id"]
|
48
|
+
end
|
49
|
+
when 'group'
|
50
|
+
method = 'audio.get'
|
51
|
+
params['gid'] = ARGV.shift
|
52
|
+
when 'add'
|
53
|
+
action_before = ''
|
54
|
+
action_after = ''
|
55
|
+
when '-nf','--no-fix', '--exact'
|
56
|
+
params["auto_complete"] = '0'
|
57
|
+
when 'auth'
|
58
|
+
Vkpd::Auth.run!
|
59
|
+
when 'play'
|
60
|
+
# do nothing
|
61
|
+
else
|
62
|
+
params["q"]=ARGV.unshift(current).join(" ")
|
63
|
+
ARGV.clear
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
params["access_token"]=config["access_token"]
|
69
|
+
|
70
|
+
connection=Net::HTTP.new("api.vk.com",443)
|
71
|
+
connection.use_ssl=true
|
72
|
+
data=connection.get("/method/#{method}?#{hash_to_params(params)}").body
|
73
|
+
response = JSON.parse(data)["response"]
|
74
|
+
if method.match /search/
|
75
|
+
response.shift
|
76
|
+
end
|
77
|
+
run action_before
|
78
|
+
response.each do |song|
|
79
|
+
run "mpc add #{song["url"]}"
|
80
|
+
end
|
81
|
+
run action_after
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# Makes string with params for http request from hash
|
87
|
+
def hash_to_params(hash)
|
88
|
+
hash.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join("&")
|
89
|
+
end
|
90
|
+
|
91
|
+
# Run external command. In debug mode simply prints its arguments.
|
92
|
+
def run(*args)
|
93
|
+
if @debug
|
94
|
+
puts(*args)
|
95
|
+
else
|
96
|
+
system(*args)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/vkpd/version.rb
ADDED
data/lib/vkpd.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8; mode: ruby -*-
|
2
|
+
require "net/http"
|
3
|
+
require "net/https"
|
4
|
+
require "cgi"
|
5
|
+
require "yaml"
|
6
|
+
require "json"
|
7
|
+
require "pathname"
|
8
|
+
require "sinatra/base"
|
9
|
+
require 'vkpd/version'
|
10
|
+
require 'vkpd/cli'
|
11
|
+
require 'vkpd/auth'
|
12
|
+
|
13
|
+
module Vkpd
|
14
|
+
APP_ID='2803517'
|
15
|
+
|
16
|
+
def self.config_path
|
17
|
+
@config_path ||= "#{ENV['HOME']}/.config/vkpd.yaml"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Reads config file, parses it as yaml and caches the result
|
21
|
+
def config
|
22
|
+
unless File.exist? config_path
|
23
|
+
puts 'Please authenticate. Type `vkpd auth` and point your browser to http://localhost.localdomain:4567/'
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
@config ||= YAML.load File.read(config_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/vkpd.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vkpd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vkpd"
|
8
|
+
spec.version = Vkpd::VERSION
|
9
|
+
spec.authors = ["Ales Guzik"]
|
10
|
+
spec.email = ["public@aguzik.net"]
|
11
|
+
spec.description = %q{VKPD searches for music files on russian social network vk.com and adds/plays it with MPD.}
|
12
|
+
spec.summary = %q{Play any music from vk.com via MPD}
|
13
|
+
spec.homepage = "https://github.com/alesguzik/vkpd"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vkpd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ales Guzik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: VKPD searches for music files on russian social network vk.com and adds/plays
|
47
|
+
it with MPD.
|
48
|
+
email:
|
49
|
+
- public@aguzik.net
|
50
|
+
executables:
|
51
|
+
- vkpd
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README
|
59
|
+
- Rakefile
|
60
|
+
- bin/vkpd
|
61
|
+
- lib/vkpd.rb
|
62
|
+
- lib/vkpd/auth.rb
|
63
|
+
- lib/vkpd/cli.rb
|
64
|
+
- lib/vkpd/version.rb
|
65
|
+
- vkpd.gemspec
|
66
|
+
homepage: https://github.com/alesguzik/vkpd
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Play any music from vk.com via MPD
|
91
|
+
test_files: []
|
92
|
+
has_rdoc:
|