Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve love/unlove capabilities.

  • Loading branch information...
commit b916b5e270ba1c8629e34299eb8d2c415f326860 1 parent 8cbe380
@meh authored
View
2  README.md
@@ -32,7 +32,7 @@ This allows for some neat features, like easily scrobbling from a radio, the fol
how to scrobble songs from trance.fm.
```ruby
-%w(listened love now_playing).each {|name|
+%w(listened love unlove now_playing).each {|name|
on name do |song|
next if song.artist || !song.stream?
View
12 bin/LOLastfm-send
@@ -21,6 +21,14 @@ OptionParser.new do |o|
options[:love] = true
end
+ o.on '--unlove', 'enable unlove sending' do
+ options[:unlove] = true
+ end
+
+ o.on '-c', '--current', 'work on the current song' do
+ options[:current] = true
+ end
+
o.on '-t', '--title TITLE', 'title of the song' do |value|
options[:song][:title] = value
end
@@ -72,7 +80,9 @@ else
if options[:now_playing]
socket.puts [:now_playing, options[:song]].to_json
elsif options[:love]
- socket.puts [:love, options[:song].empty? ? nil : options[:song]].to_json
+ socket.puts [:love, options[:song].empty? ? (options[:current] ? :current : nil) : options[:song]].to_json
+ elsif options[:unlove]
+ socket.puts [:unlove, options[:song].empty? ? (options[:current] ? :current : nil) : options[:song]].to_json
else
socket.puts [:listened, options[:song]].to_json
end
View
24 lib/LOLastfm.rb
@@ -157,6 +157,7 @@ def listened! (song)
def love (song = nil)
song = @last_played or return unless song
+ song = now_playing? or return if song == 'current' || song == :current
song = Song.new(song) unless song.is_a? Song
song = song.dup
@@ -177,6 +178,29 @@ def love! (song)
false
end
+ def unlove (song = nil)
+ song = @last_played or return unless song
+ song = now_playing? or return if song == 'current' || song == :current
+ song = Song.new(song) unless song.is_a? Song
+ song = song.dup
+
+ return false unless fire :unlove, song
+
+ return false if song.nil?
+
+ unless unlove! song
+ @cache.unlove(song)
+ end
+
+ true
+ end
+
+ def unlove! (song)
+ @session.track.unlove(song.artist, song.title)
+ rescue
+ false
+ end
+
def stopped_playing!
@now_playing = nil
end
View
29 lib/LOLastfm/cache.rb
@@ -20,6 +20,7 @@ def initialize (fm)
@listened = []
@loved = []
+ @unloved = []
end
def listened (song)
@@ -34,8 +35,14 @@ def love (song)
@loved << song
end
+ def unlove (song)
+ return if @unloved.member? song
+
+ @unloved << song
+ end
+
def empty?
- @listened.empty? && @loved.empty?
+ @listened.empty? && @loved.empty? && @unloved.empty?
end
def flush!
@@ -50,6 +57,12 @@ def flush!
@loved.shift
end
+
+ until @unloved.empty?
+ break unless fm.unlove! @unloved.first
+
+ @unloved.shift
+ end
end
def load (path)
@@ -57,15 +70,23 @@ def load (path)
data['listened'].each {|song|
listened(Song.new(song))
- }
+ } if data['listened']
data['loved'].each {|song|
love(Song.new(song))
- }
+ } if data['loved']
+
+ data['unloved'].each {|song|
+ unlove(Song.new(song))
+ } if data['unloved']
end
def to_yaml
- { 'listened' => @listened.map(&:to_hash), 'loved' => @loved.map(&:to_hash) }.to_yaml
+ {
+ 'listened' => @listened.map(&:to_hash),
+ 'loved' => @loved.map(&:to_hash),
+ 'unloved' => @unloved.map(&:to_hash)
+ }.to_yaml
end
end
View
4 lib/LOLastfm/connection.rb
@@ -36,6 +36,10 @@ class LOLastfm
love song
end
+define_command :unlove do |song|
+ unlove song
+end
+
define_command :hint do |*args|
hint *args
end
Please sign in to comment.
Something went wrong with that request. Please try again.