sandro-tagooru 0.0.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Sandro Turriate
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ = tagooru
2
+
3
+ Ruby wrapper for the tagoo.ru search engine
4
+
5
+ == Example
6
+ require 'tagooru'
7
+
8
+ >> playlist = Tagooru.search("radiohead 15 step")
9
+ >> playlist.first.name
10
+ => "Radiohead - 15 Step"
11
+ >> playlist.first.location
12
+ => "http://someurl.com/music/radiohead/15_step.mp3"
13
+
14
+ == Copyright
15
+
16
+ Copyright (c) 2009 Sandro Turriate. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tagooru"
8
+ gem.summary = %Q{Ruby wrapper for the tagoo search engine}
9
+ gem.email = "sandro.turriate@gmail.com"
10
+ gem.homepage = "http://github.com/sandro/tagooru"
11
+ gem.authors = ["Sandro Turriate"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "tagooru #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
@@ -0,0 +1,44 @@
1
+ class Tagooru
2
+ class Playlist
3
+ require 'enumerator'
4
+
5
+ attr_reader :contents
6
+
7
+ def initialize(contents)
8
+ @contents = contents
9
+ end
10
+
11
+ def parse
12
+ tracks = []
13
+ lines.each_slice(2) do |track_info|
14
+ name = track_info[0].split(",", 2).last
15
+ tracks << Track.new(name, track_info[1])
16
+ end
17
+ tracks
18
+ end
19
+
20
+ private
21
+
22
+ def lines
23
+ @lines ||= begin
24
+ list = contents.to_a
25
+ list.shift
26
+ list.map {|line| line.chomp}
27
+ end
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
+ end
44
+ end
data/lib/tagooru.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ class Tagooru
7
+ autoload :Playlist, 'tagooru/playlist'
8
+
9
+ include HTTParty
10
+ base_uri 'http://tagoo.ru'
11
+ default_params :for => :audio
12
+
13
+ def self.search(query, page = 1)
14
+ playlist = get '/en/search_playlist.php', :query => {:search => query, :page => page}
15
+ Playlist.new(playlist).parse
16
+ end
17
+
18
+ def self.first(query, page = 1)
19
+ search(query, page).detect {|t| t.accessible?}
20
+ end
21
+ end
data/script/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ libs << " -r lib/tagooru.rb"
7
+
8
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,21 @@
1
+ #EXTMP3U
2
+ #EXTINF:00:03:17,Necro - You Did It
3
+ http://files.raplife.ru/jka/xxx/17--you_did_it-ftd.mp3
4
+ #EXTINF:00:03:23,Necro - Beautiful Music For You To Die To
5
+ http://files.raplife.ru/jka/xxx/02--beautiful_music_for_you_to_die_to-ftd.mp3
6
+ #EXTINF:00:05:46,Bob Dylan - I Don't Believe You (She Acts Like We Never Have Met)
7
+ http://box.net/shared/static/9qf5jq6os8.mp3
8
+ #EXTINF:00:03:14,Speckled Red - You Got To Fix It
9
+ http://prewarblues.org/files/you_got_to_fix.mp3
10
+ #EXTINF:00:05:18,Slyde - You're My Fix
11
+ http://music2.synclub.ru/breaks_breakbeat/Slyde%20-%20Everyone%27s%20Entitled%20To%20Our%20Opinion%20(2008)/03.You%27re%20My%20Fix.mp3
12
+ #EXTINF:00:05:18,Slyde - You're My Fix
13
+ http://music2.synclub.ru/breaks_breakbeat/Flrcd019_-_Slyde_-_Everyone_s_Entitled_To_Our_Opinion__2008/03.You%27re%20My%20Fix.mp3
14
+ #EXTINF:00:01:16,Chris - Can you fix it?
15
+ http://media.switchpod.com/users/davegraham04/DWR0002.mp3
16
+ #EXTINF:00:04:20,Jackson 5 - I Want You Back (Chew Fu Big Room Fix)
17
+ http://viprhealthcare.typepad.com/files/i-want-you-back-chew-fu-big-room-fix.mp3
18
+ #EXTINF:01:19:53,Various Artists - Mix Fix 022: What You Deserve
19
+ http://jm00nchild.com/audio/mixsets/Mix_Fix_022-J.M00nchild-What_You_Deserve-2007.12.02.mp3
20
+ #EXTINF:00:04:44,Jesus - I Fix my Eyes, on, You
21
+ http://mylightandlife.org/Music_Library/Worship_Team_Catalog/I%20Fix%20My%20Eyes%20On%20You.mp3
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format specdoc
@@ -0,0 +1,19 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'tagooru'
6
+
7
+ def fixture(filename)
8
+ filename = File.basename(filename)
9
+ file = File.join(File.dirname(__FILE__), "fixtures", filename)
10
+ if File.exist?(file)
11
+ fixture_store[filename] || fixture_store[filename] = File.read(file)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def fixture_store
18
+ @fixture_store ||= {}
19
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe Tagooru::Playlist do
4
+ it "requires contents when instantiated" do
5
+ lambda {
6
+ Tagooru::Playlist.new('hi')
7
+ }.should_not raise_error
8
+ end
9
+
10
+ describe "parsing" do
11
+ before do
12
+ @playlist = Tagooru::Playlist.new fixture("fix.m3u")
13
+ end
14
+
15
+ it "scans playlist lines" do
16
+ @playlist.should_receive(:lines).and_return([])
17
+ @playlist.parse
18
+ end
19
+
20
+ it "includes track names and track locations" do
21
+ track = @playlist.parse.first
22
+ track.name.should == "Necro - You Did It"
23
+ track.location.should == 'http://files.raplife.ru/jka/xxx/17--you_did_it-ftd.mp3'
24
+ end
25
+
26
+ it "understands track names with commas in them" do
27
+ track = @playlist.parse.last
28
+ track.name.should == "Jesus - I Fix my Eyes, on, You"
29
+ end
30
+
31
+ describe "#lines" do
32
+ before do
33
+ @array = @playlist.contents.to_a
34
+ @playlist.contents.stub!(:to_a => @array)
35
+ end
36
+
37
+ it "skips the first line" do
38
+ @array.should_receive(:shift).and_return([])
39
+ @playlist.send(:lines)
40
+ end
41
+
42
+ it "removes line separators" do
43
+ @playlist.send(:lines).first.should_not =~ /(\r|\n)$/
44
+ end
45
+ end
46
+ end
47
+
48
+ describe Tagooru::Playlist::Track do
49
+ before do
50
+ @track = Tagooru::Playlist::Track.new "Fix You", "http://google.com/?q=fixyou.mp3"
51
+ end
52
+
53
+ it "has a name and location" do
54
+ @track.name.should == "Fix You"
55
+ @track.location.should == "http://google.com/?q=fixyou.mp3"
56
+ end
57
+
58
+ describe "accessibility" do
59
+ it "is accessible" do
60
+ http = stub(:request_head => stub(:code => 200), :null_object => true)
61
+ Net::HTTP.stub!(:new => http)
62
+ @track.should be_accessible
63
+ end
64
+
65
+ it 'is not accessible' do
66
+ http = stub(:null_object => true)
67
+ http.should_receive(:request_head).and_raise(SocketError)
68
+ Net::HTTP.stub!(:new => http)
69
+ @track.should_not be_accessible
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Tagooru" do
4
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sandro-tagooru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sandro Turriate
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: sandro.turriate@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - lib/tagooru.rb
32
+ - lib/tagooru/playlist.rb
33
+ - script/console
34
+ - spec/fixtures/fix.m3u
35
+ - spec/spec.opts
36
+ - spec/spec_helper.rb
37
+ - spec/tagooru/playlist_spec.rb
38
+ - spec/tagooru_spec.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/sandro/tagooru
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Ruby wrapper for the tagoo search engine
65
+ test_files:
66
+ - spec/spec_helper.rb
67
+ - spec/tagooru/playlist_spec.rb
68
+ - spec/tagooru_spec.rb