Skip to content

Commit

Permalink
Created Sonice module, added Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny committed Dec 6, 2010
1 parent dda038c commit b5dec91
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 278 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bundle

7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "http://rubygems.org"

gem "sinatra"
gem "haml"
gem "xml-simple"
gem "json"

20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GEM
remote: http://rubygems.org/
specs:
haml (3.0.24)
json (1.4.6)
rack (1.2.1)
sinatra (1.1.0)
rack (~> 1.1)
tilt (~> 1.1)
tilt (1.1)
xml-simple (1.0.12)

PLATFORMS
ruby

DEPENDENCIES
haml
json
sinatra
xml-simple
22 changes: 14 additions & 8 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ So Nice
A tiny web application to play, pause, change volume or skip songs playing
in iTunes, Rhythmbox or MPD.

- **Screenshot**: ![Screenshot](https://github.com/sunny/so-nice/raw/master/screenshot.png)
- **Dependencies**: ruby, sinatra, haml, xml-simple & json
![Screenshot](https://github.com/sunny/so-nice/raw/master/screenshot.png)

$ sudo gem install sinatra haml xml-simple json
You will need ruby.

- **Usage**:
With rubygems and git you can install it this way:

$ ruby -rubygems so_nice.rb
$ git clone git://github.com/sunny/so-nice.git
$ cd so-nice
$ gem install bundler
$ bundle

Then visit `http://localhost:4567`
To launch it:

- **Author**: [Sunny Ripert](http://sunfox.org/)
- **Licence**: [WTFPL](http://sam.zoy.org/wtfpl/)
$ ./so_nice.rb

Then visit `http://localhost:4567`

- Author: [Sunny Ripert](http://sunfox.org/)
- Licence: [WTFPL](http://sam.zoy.org/wtfpl/)

22 changes: 0 additions & 22 deletions lib/artist_image.rb

This file was deleted.

39 changes: 0 additions & 39 deletions lib/player.rb

This file was deleted.

51 changes: 0 additions & 51 deletions lib/players/itunes.rb

This file was deleted.

51 changes: 0 additions & 51 deletions lib/players/itunes_win.rb

This file was deleted.

53 changes: 0 additions & 53 deletions lib/players/mpd.rb

This file was deleted.

46 changes: 0 additions & 46 deletions lib/players/rhythmbox.rb

This file was deleted.

25 changes: 25 additions & 0 deletions lib/sonice/artist_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'xmlsimple'
require 'json'
require 'open-uri'

module Sonice
class ArtistImage
attr_reader :uri

LAST_FM_URI = "http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist=%s&api_key=b25b959554ed76058ac220b7b2e0a026"

def initialize(artist)
return unless artist
artist = Rack::Utils.escape(artist)
xml = XmlSimple.xml_in(open(LAST_FM_URI % artist).read.to_s)
images = xml['images'].first['image']
if images
image = images[rand(images.size-1)]["sizes"].first["size"].first
@uri = image['content']
end
rescue OpenURI::HTTPError
""
end
end
end

41 changes: 41 additions & 0 deletions lib/sonice/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'timeout'
module Sonice
class Player
MUSIC_PLAYERS = []

def name
self.class.to_s.gsub(/^Sonice::|Player$/, '')
end

def host
%x(hostname).strip
end

[:launched?, :playpause, :next, :prev,
:voldown, :volup, :volume,
:track, :artist, :album
].each do |method|
define_method method do
raise NotImplementedError, "this player needs a #{method} method"
end
end

def self.inherited(k)
MUSIC_PLAYERS.push k.new
end

def self.launched
MUSIC_PLAYERS.find { |player|
puts "Trying #{player.name}..."
begin
Timeout::timeout(5) { player.launched? }
rescue
puts "Timed out"
nil
end
}
end
end

end

Loading

0 comments on commit b5dec91

Please sign in to comment.