sandro-tagooru 0.0.1 → 0.1.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.
- data/.gitignore +1 -0
- data/README.rdoc +10 -6
- data/VERSION +1 -0
- data/lib/httparty_ext.rb +19 -0
- data/lib/tagooru/playlist.rb +0 -14
- data/lib/tagooru/track.rb +15 -0
- data/lib/tagooru.rb +22 -3
- data/spec/spec_helper.rb +2 -2
- data/spec/tagooru/playlist_spec.rb +2 -2
- data/tagooru.gemspec +55 -0
- metadata +8 -3
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -3,13 +3,17 @@
|
|
3
3
|
Ruby wrapper for the tagoo.ru search engine
|
4
4
|
|
5
5
|
== Example
|
6
|
-
require 'tagooru'
|
6
|
+
<tt>require 'tagooru'</tt>
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
<tt>>> playlist = Tagooru.search("radiohead 15 step")</tt>
|
9
|
+
|
10
|
+
<tt>>> playlist.first.name</tt>
|
11
|
+
|
12
|
+
<tt>=> "Radiohead - 15 Step"</tt>
|
13
|
+
|
14
|
+
<tt>>> playlist.first.location</tt>
|
15
|
+
|
16
|
+
<tt>=> "someurl.com/music/radiohead/15_step.mp3"</tt>
|
13
17
|
|
14
18
|
== Copyright
|
15
19
|
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/httparty_ext.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module HTTParty
|
2
|
+
class Request
|
3
|
+
class << self
|
4
|
+
attr_accessor :debug
|
5
|
+
end
|
6
|
+
|
7
|
+
def perform_with_debug
|
8
|
+
if self.class.debug
|
9
|
+
puts "HTTParty making #{http_method::METHOD} request to:"
|
10
|
+
puts uri
|
11
|
+
end
|
12
|
+
perform_without_debug
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :perform_without_debug, :perform
|
16
|
+
alias_method :perform, :perform_with_debug
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/tagooru/playlist.rb
CHANGED
@@ -26,19 +26,5 @@ class Tagooru
|
|
26
26
|
list.map {|line| line.chomp}
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
class Track < Struct.new(:name, :location)
|
31
|
-
def accessible?
|
32
|
-
url = URI.parse(location)
|
33
|
-
http = Net::HTTP.new url.host
|
34
|
-
http.open_timeout = 2
|
35
|
-
http.read_timeout = 2
|
36
|
-
begin
|
37
|
-
(200..399).include? http.request_head(url.path).code.to_i
|
38
|
-
rescue SocketError
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
29
|
end
|
44
30
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Tagooru
|
2
|
+
class Track < Struct.new(:name, :location)
|
3
|
+
def accessible?
|
4
|
+
url = URI.parse(location)
|
5
|
+
http = Net::HTTP.new url.host
|
6
|
+
http.open_timeout = 2
|
7
|
+
http.read_timeout = 2
|
8
|
+
begin
|
9
|
+
(200..399).include? http.request_head(url.path).code.to_i
|
10
|
+
rescue Timeout::Error, SocketError
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/tagooru.rb
CHANGED
@@ -2,17 +2,36 @@ require 'rubygems'
|
|
2
2
|
require 'httparty'
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
require 'httparty_ext.rb'
|
5
6
|
|
6
7
|
class Tagooru
|
7
8
|
autoload :Playlist, 'tagooru/playlist'
|
9
|
+
autoload :Track, 'tagooru/track'
|
8
10
|
|
9
11
|
include HTTParty
|
10
12
|
base_uri 'http://tagoo.ru'
|
11
|
-
default_params :for => :audio
|
13
|
+
default_params :for => :audio, :key => '74d8940f'
|
14
|
+
headers 'Referer' => 'http://tagoo.ru/en/webmaster.php?mode=json_api'
|
15
|
+
format :plain
|
16
|
+
|
17
|
+
# override method from HTTParty to prevent cookies from overriding other
|
18
|
+
# header data (httparty 0.4.4)
|
19
|
+
def self.perform_request(http_method, path, options) #:nodoc:
|
20
|
+
Request.new(http_method, path, default_options.dup.merge(options)).perform
|
21
|
+
end
|
12
22
|
|
13
23
|
def self.search(query, page = 1)
|
14
|
-
|
15
|
-
|
24
|
+
response = get '/api_search.php', :query => {:search => query, :page => page, :seed => generate_seed}
|
25
|
+
data = Crack::JSON.parse(response.sub(/^.+= /, ''))
|
26
|
+
data['data'].map do |d|
|
27
|
+
Track.new d['title'], d['file_url']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# seed argument taken from search api
|
32
|
+
# http://tagoo.ru/script/api/search.js
|
33
|
+
def self.generate_seed
|
34
|
+
(rand * 100_000).to_i
|
16
35
|
end
|
17
36
|
|
18
37
|
def self.first(query, page = 1)
|
data/spec/spec_helper.rb
CHANGED
@@ -45,9 +45,9 @@ describe Tagooru::Playlist do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe Tagooru::
|
48
|
+
describe Tagooru::Track do
|
49
49
|
before do
|
50
|
-
@track = Tagooru::
|
50
|
+
@track = Tagooru::Track.new "Fix You", "http://google.com/?q=fixyou.mp3"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "has a name and location" do
|
data/tagooru.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tagooru}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Sandro Turriate"]
|
9
|
+
s.date = %q{2009-08-10}
|
10
|
+
s.email = %q{sandro.turriate@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/httparty_ext.rb",
|
23
|
+
"lib/tagooru.rb",
|
24
|
+
"lib/tagooru/playlist.rb",
|
25
|
+
"lib/tagooru/track.rb",
|
26
|
+
"script/console",
|
27
|
+
"spec/fixtures/fix.m3u",
|
28
|
+
"spec/spec.opts",
|
29
|
+
"spec/spec_helper.rb",
|
30
|
+
"spec/tagooru/playlist_spec.rb",
|
31
|
+
"spec/tagooru_spec.rb",
|
32
|
+
"tagooru.gemspec"
|
33
|
+
]
|
34
|
+
s.has_rdoc = true
|
35
|
+
s.homepage = %q{http://github.com/sandro/tagooru}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.1}
|
39
|
+
s.summary = %q{Ruby wrapper for the tagoo search engine}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/tagooru/playlist_spec.rb",
|
43
|
+
"spec/tagooru_spec.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 2
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
else
|
52
|
+
end
|
53
|
+
else
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandro-tagooru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Turriate
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,16 +28,21 @@ files:
|
|
28
28
|
- LICENSE
|
29
29
|
- README.rdoc
|
30
30
|
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- lib/httparty_ext.rb
|
31
33
|
- lib/tagooru.rb
|
32
34
|
- lib/tagooru/playlist.rb
|
35
|
+
- lib/tagooru/track.rb
|
33
36
|
- script/console
|
34
37
|
- spec/fixtures/fix.m3u
|
35
38
|
- spec/spec.opts
|
36
39
|
- spec/spec_helper.rb
|
37
40
|
- spec/tagooru/playlist_spec.rb
|
38
41
|
- spec/tagooru_spec.rb
|
42
|
+
- tagooru.gemspec
|
39
43
|
has_rdoc: true
|
40
44
|
homepage: http://github.com/sandro/tagooru
|
45
|
+
licenses:
|
41
46
|
post_install_message:
|
42
47
|
rdoc_options:
|
43
48
|
- --charset=UTF-8
|
@@ -58,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
63
|
requirements: []
|
59
64
|
|
60
65
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.3.5
|
62
67
|
signing_key:
|
63
68
|
specification_version: 2
|
64
69
|
summary: Ruby wrapper for the tagoo search engine
|