cinch-spotify 0.0.3 → 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/README.rdoc CHANGED
@@ -1,18 +1,29 @@
1
1
  = cinch-spotify
2
2
 
3
- A Spotify plugin for the IRC bot library Cinch.
3
+ A Cinch plugin for the Spotify meta api.
4
+
5
+ The gem can be installed with:
6
+
7
+ gem install cinch-spotify
4
8
 
5
9
  == Usage
6
10
 
11
+ require 'cinch'
12
+ require 'cinch/plugins/spotify'
13
+
7
14
  bot = Cinch::Bot.new do
8
15
  configure do |c|
9
16
  c.nick = "Spotibot"
10
17
  c.server = "irc.freenode.org"
11
- c.channels = ["#cinch-bots"]
12
- c.plugins.plugins = [Cinch::Plugins::Netfeed::Spotify]
18
+ c.channels = ["#cinchbots"]
19
+ c.plugins.plugins = [Cinch::Plugins::Spotify]
13
20
  end
14
21
  end
15
22
 
23
+ == Notice
24
+
25
+ This product uses a SPOTIFY API but is not endorsed, certified or otherwise approved in any way by Spotify. Spotify is the registered trade mark of the Spotify Group.
26
+
16
27
  == Copyright
17
28
 
18
29
  Copyright (c) 2010 Victor Bergöö. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2010 Victor Bergöö
4
+ # This program is made available under the terms of the MIT License.
5
+
6
+ require 'cinch'
7
+ require 'json'
8
+ require 'curb'
9
+
10
+ module Cinch
11
+ module Plugins
12
+ class Spotify
13
+ include Cinch::Plugin
14
+
15
+ match /(spotify:(album|track|artist):[a-zA-Z0-9]+)/, :use_prefix => false
16
+ match /(http:\/\/open.spotify.com\/(album|track|artist)\/[a-zA-Z0-9]+)/, :use_prefix => false
17
+
18
+ def execute m, uri, type
19
+ msg = case type
20
+ when /artist/ then _artist uri
21
+ when /album/ then _album uri
22
+ when /track/ then _track uri
23
+ else 'something went wrong'
24
+ end
25
+
26
+ m.reply("Spotify: #{msg}")
27
+ end
28
+
29
+ def _artist uri
30
+ json = _lookup uri
31
+ name = json['artist']['name']
32
+ "Artist: #{name}"
33
+ end
34
+
35
+ def _album uri
36
+ json = _lookup uri
37
+ artist = json['album']['artist']
38
+ album = json['album']['name']
39
+ "Album: #{album} by #{artist}"
40
+ end
41
+
42
+ def _track uri
43
+ json = _lookup uri
44
+ artist = json['track']['artists'].first['name']
45
+ album = json['track']['album']['name']
46
+ track = json['track']['name']
47
+ "Track: #{track} by #{artist} (#{album})"
48
+ end
49
+
50
+ def _lookup spotify_uri
51
+ content = Curl::Easy.perform("http://ws.spotify.com/lookup/1/.json?uri=#{spotify_uri}").body_str
52
+ JSON.parse(content)
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Victor Bergoo
@@ -14,8 +14,8 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-27 00:00:00 +02:00
18
- default_executable: cinch-spotify
17
+ date: 2011-01-30 00:00:00 +01:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cinch
@@ -31,7 +31,7 @@ dependencies:
31
31
  type: :runtime
32
32
  version_requirements: *id001
33
33
  - !ruby/object:Gem::Dependency
34
- name: nokogiri
34
+ name: json
35
35
  prerelease: false
36
36
  requirement: &id002 !ruby/object:Gem::Requirement
37
37
  none: false
@@ -44,7 +44,7 @@ dependencies:
44
44
  type: :runtime
45
45
  version_requirements: *id002
46
46
  - !ruby/object:Gem::Dependency
47
- name: httpclient
47
+ name: curb
48
48
  prerelease: false
49
49
  requirement: &id003 !ruby/object:Gem::Requirement
50
50
  none: false
@@ -58,29 +58,24 @@ dependencies:
58
58
  version_requirements: *id003
59
59
  description: A spotify plugin for the Cinch IRC framework
60
60
  email: victor.bergoo@gmail.com
61
- executables:
62
- - cinch-spotify
61
+ executables: []
62
+
63
63
  extensions: []
64
64
 
65
65
  extra_rdoc_files:
66
66
  - LICENSE
67
67
  - README.rdoc
68
68
  files:
69
- - .gitignore
69
+ - lib/cinch/plugins/spotify.rb
70
70
  - LICENSE
71
71
  - README.rdoc
72
- - Rakefile
73
- - VERSION
74
- - bin/cinch-spotify
75
- - cinch-spotify.gemspec
76
- - lib/cinch-spotify.rb
77
72
  has_rdoc: true
78
73
  homepage: http://github.com/netfeed/cinch-spotify
79
74
  licenses: []
80
75
 
81
76
  post_install_message:
82
- rdoc_options:
83
- - --charset=UTF-8
77
+ rdoc_options: []
78
+
84
79
  require_paths:
85
80
  - lib
86
81
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- pkg
data/Rakefile DELETED
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "cinch-spotify"
8
- gem.summary = %Q{Spotify plugin for the Cinch IRC framework}
9
- gem.description = %Q{A spotify plugin for the Cinch IRC framework}
10
- gem.email = "victor.bergoo@gmail.com"
11
- gem.homepage = "http://github.com/netfeed/cinch-spotify"
12
- gem.authors = ["Victor Bergoo"]
13
- gem.add_dependency "cinch"
14
- gem.add_dependency "nokogiri"
15
- gem.add_dependency "httpclient"
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
- end
21
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.3
data/bin/cinch-spotify DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- # Copyright (c) 2010 Victor Bergöö
4
- # This program is made available under the terms of the MIT License.
5
-
6
- require 'rubygems'
7
- require File.expand_path('../../lib/cinch-spotify', __FILE__)
8
-
9
- bot = Cinch::Bot.new do
10
- configure do |c|
11
- c.nick = "Spotibot"
12
- c.server = "irc.freenode.org"
13
- c.channels = ["#cinch-bots"]
14
- c.plugins.plugins = [Cinch::Plugins::Netfeed::Spotify]
15
- end
16
- end
17
-
18
- bot.start
@@ -1,56 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{cinch-spotify}
8
- s.version = "0.0.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Victor Bergoo"]
12
- s.date = %q{2010-10-27}
13
- s.default_executable = %q{cinch-spotify}
14
- s.description = %q{A spotify plugin for the Cinch IRC framework}
15
- s.email = %q{victor.bergoo@gmail.com}
16
- s.executables = ["cinch-spotify"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.rdoc"
20
- ]
21
- s.files = [
22
- ".gitignore",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "bin/cinch-spotify",
28
- "cinch-spotify.gemspec",
29
- "lib/cinch-spotify.rb"
30
- ]
31
- s.homepage = %q{http://github.com/netfeed/cinch-spotify}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{Spotify plugin for the Cinch IRC framework}
36
-
37
- if s.respond_to? :specification_version then
38
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
- s.specification_version = 3
40
-
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<cinch>, [">= 0"])
43
- s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
44
- s.add_runtime_dependency(%q<httpclient>, [">= 0"])
45
- else
46
- s.add_dependency(%q<cinch>, [">= 0"])
47
- s.add_dependency(%q<nokogiri>, [">= 0"])
48
- s.add_dependency(%q<httpclient>, [">= 0"])
49
- end
50
- else
51
- s.add_dependency(%q<cinch>, [">= 0"])
52
- s.add_dependency(%q<nokogiri>, [">= 0"])
53
- s.add_dependency(%q<httpclient>, [">= 0"])
54
- end
55
- end
56
-
data/lib/cinch-spotify.rb DELETED
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- # Copyright (c) 2010 Victor Bergöö
4
- # This program is made available under the terms of the MIT License.
5
-
6
- require 'cinch'
7
- require 'nokogiri'
8
- require 'httpclient'
9
-
10
- module Cinch
11
- module Plugins
12
- module Netfeed
13
- class Spotify
14
- include Cinch::Plugin
15
-
16
- match /(spotify:(album|track|artist):[a-zA-Z0-9]+)/, :use_prefix => false
17
- match /(http:\/\/open.spotify.com\/(album|track|artist)\/[a-zA-Z0-9]+)/, :use_prefix => false
18
-
19
- def execute m, uri, type
20
- msg = case type
21
- when /artist/ then _artist uri
22
- when /album/ then _album uri
23
- when /track/ then _track uri
24
- else 'something went wrong'
25
- end
26
-
27
- m.reply("Spotify: #{msg}")
28
- end
29
-
30
- def _artist uri
31
- p = Nokogiri::XML _data(uri)
32
- artist = p.xpath("//xmlns:artist/xmlns:name").first.content
33
- "Artist: #{artist}"
34
- end
35
-
36
- def _album uri
37
- p = Nokogiri::XML _data(uri)
38
- artist = p.xpath("//xmlns:artist/xmlns:name").first.content
39
- album = p.xpath("//xmlns:album/xmlns:name").first.content
40
- "Album: #{album} by #{artist}"
41
- end
42
-
43
- def _track uri
44
- p = Nokogiri::XML _data(uri)
45
- artist = p.xpath("//xmlns:artist/xmlns:name").first.content
46
- album = p.xpath("//xmlns:album/xmlns:name").first.content
47
- track = p.xpath("//xmlns:track/xmlns:name").first.content
48
- "Track: #{track} by #{artist} (#{album})"
49
- end
50
-
51
- def _data spotify_uri
52
- client = HTTPClient.new
53
- resp = client.get("http://ws.spotify.com/lookup/1/", { :uri => spotify_uri })
54
- resp.content
55
- end
56
- end
57
- end
58
- end
59
- end