Permalink
Browse files

Created Sonice module, added Gemfile

  • Loading branch information...
1 parent dda038c commit b5dec918e4595efcdbdf93648fab423d4d639c67 @sunny committed Dec 6, 2010
View
@@ -0,0 +1,2 @@
+.bundle
+
View
@@ -0,0 +1,7 @@
+source "http://rubygems.org"
+
+gem "sinatra"
+gem "haml"
+gem "xml-simple"
+gem "json"
+
View
@@ -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
View
@@ -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/)
View
@@ -1,22 +0,0 @@
-require 'xmlsimple'
-require 'json'
-require 'open-uri'
-
-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
View
@@ -1,39 +0,0 @@
-require 'timeout'
-
-class MusicPlayer
- MUSIC_PLAYERS = []
-
- def name
- self.class.to_s.gsub(/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
-
View
@@ -1,51 +0,0 @@
-class ItunesPlayer < MusicPlayer
- def playpause
- tell_to 'playpause'
- end
-
- def prev
- tell_to 'previous track'
- end
-
- def next
- tell_to 'next track'
- end
-
- def voldown
- tell_to 'set sound volume to sound volume - 10'
- end
-
- def volup
- tell_to 'set sound volume to sound volume + 10'
- end
-
- def volume
- tell_to 'return sound volume'
- end
-
- def track
- tell_to 'return name of current track'
- end
-
- def artist
- tell_to 'return artist of current track'
- end
-
- def album
- tell_to 'return album of current track'
- end
-
- def launched?
- track
- $? == 0
- end
-
- def name
- "iTunes"
- end
-
- private
- def tell_to(command)
- %x(osascript -e 'tell app "iTunes" to #{command}').rstrip
- end
-end
@@ -1,51 +0,0 @@
-class ItunesWinPlayer < MusicPlayer
- def playpause
- @itunes.PlayPause()
- end
-
- def prev
- @itunes.PreviousTrack()
- end
-
- def next
- @itunes.NextTrack()
- end
-
- def voldown
- @itunes.SoundVolume=@itunes.SoundVolume - 10
- end
-
- def volup
- @itunes.SoundVolume=@itunes.SoundVolume + 10
- end
-
- def volume
- @itunes.SoundVolume
- end
-
- def track
- @itunes.CurrentTrack.name
- end
-
- def artist
- @itunes.CurrentTrack.Artist
- end
-
- def album
- @itunes.CurrentTrack.Album
- end
-
- def launched?
- begin
- require 'win32ole'
- @itunes = WIN32OLE.new("iTunes.Application")
- return true
- rescue LoadError
- return false
- end
- end
-
- def name
- "iTunes Windows"
- end
-end
View
@@ -1,53 +0,0 @@
-class MpdPlayer < MusicPlayer
- def playpause
- mpc 'toggle'
- end
-
- def prev
- mpc 'prev'
- end
-
- def next
- mpc 'next'
- end
-
- def voldown
- mpc 'volume -10'
- end
-
- def volup
- mpc 'volume +10'
- end
-
- def volume
- mpc('volume').grep(/([0-9]+)/)
- $1
- end
-
- def track
- mpc('')
- end
-
- def artist
- ''
- end
-
- def album
- ''
- end
-
- def launched?
- %x(mpc 2> /dev/null)
- $? == 0
- end
-
- def host
- ENV['MPD_HOST'] || super
- end
-
- private
- def mpc(command)
- %x(mpc #{command}).split("\n").first
- end
-end
-
@@ -1,46 +0,0 @@
-class RhythmboxPlayer < MusicPlayer
- def playpause
- tell_to 'play-pause'
- end
-
- def prev
- tell_to 'previous'
- end
-
- def next
- tell_to 'next'
- end
-
- def voldown
- tell_to 'volume-down'
- end
-
- def volup
- tell_to 'volume-up'
- end
-
- def volume
- tell_to 'print-volume'
- end
-
- def track
- tell_to 'print-playing-format=%tt'
- end
-
- def artist
- tell_to 'print-playing-format=%ta'
- end
-
- def album
- tell_to 'print-playing-format=%at'
- end
-
- def launched?
- %x(rhythmbox-client --no-start --print-playing 2>/dev/null).rstrip != ""
- end
-
- private
- def tell_to(command)
- %x(rhythmbox-client --no-start --#{command}).rstrip
- end
-end
@@ -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
+
View
@@ -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
+
Oops, something went wrong. Retry.

0 comments on commit b5dec91

Please sign in to comment.