xhochy-scrobbler-notify 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,9 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ sample.rb
7
+ Rakefile~
8
+ README.rdoc~
9
+ *.rb~
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Uwe L. Korn
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,7 @@
1
+ = scrobbler-notify
2
+
3
+ Library for notifiying the user of tracks played at a certain Last.fm account
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Uwe L. Korn. 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 = "scrobbler-notify"
8
+ gem.summary = %Q{Displays the current songs and some other information via certain notify libs on different systems}
9
+ gem.email = "uwelk@xhochy.org"
10
+ gem.homepage = "http://github.com/xhochy/scrobbler-notify"
11
+ gem.authors = ["Uwe L. Korn"]
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 = "last.fm-notify-osd #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+
3
+ require 'notifier_wrapper'
4
+ require 'scrobbler'
5
+ require 'tempfile'
6
+
7
+ module Scrobbler
8
+ class Notify < NotifierWrapper
9
+ alias :notify_raw :notify
10
+
11
+ def initialize(user, options = {})
12
+ options = {:should_play => true}.merge(options)
13
+ super(options)
14
+ @should_play = options[:should_play]
15
+ @user = user
16
+ end
17
+
18
+ # This should be called contionously as this checks for a new track
19
+ def trigger
20
+ latest_track = @user.recent_tracks(true, :limit => 1).first
21
+ if @track.nil? || @track != latest_track
22
+ @track = latest_track
23
+ notify if latest_track.now_playing || (not @should_play)
24
+ end
25
+ end
26
+
27
+ # Show a notification that the track has changed
28
+ def notify
29
+ image = image_get
30
+ params = {:timeout => 5}
31
+ params[:icon] = image unless image.nil?
32
+ notify_raw("Last.fm - #{@user.username}", "#{@track.artist.name} - #{@track.name}", params)
33
+ image_clean
34
+ end
35
+
36
+ # Download a image releated to the played track
37
+ def image_get
38
+ @image = Tempfile.new('scrobbler-notify')
39
+ if @track.image(:small).nil? || @track.image(:small).empty?
40
+ if @track.album.nil? || @track.album.image(:small).nil? || @track.album.image(:small).empty?
41
+ if @track.artist.nil? || @track.artist.image(:small).nil? || @track.artist.image(:small).empty?
42
+ image_uri = nil
43
+ else
44
+ image_uri = URI.parse(@track.artist.image(:small))
45
+ end
46
+ else
47
+ image_uri = URI.parse(@track.album.image(:small))
48
+ end
49
+ else
50
+ image_uri = URI.parse(@track.image(:small))
51
+ end
52
+ @image.print(Net::HTTP.get(image_uri)) unless image_uri.nil?
53
+ @image.close
54
+ @image.path
55
+ end
56
+
57
+ # Cleanup everthing needed to fetch the image
58
+ def image_clean
59
+ @image.unlink
60
+ end
61
+
62
+ end # Notify
63
+ end # Scrobbler
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'last.fm-notify-osd'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xhochy-scrobbler-notify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Uwe L. Korn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: uwelk@xhochy.org
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
+ - VERSION
32
+ - lib/scrobbler/notify.rb
33
+ - spec/spec_helper.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/xhochy/scrobbler-notify
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --charset=UTF-8
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: Displays the current songs and some other information via certain notify libs on different systems
60
+ test_files:
61
+ - spec/spec_helper.rb