lib/ayadn/action.rb in ayadn-1.1.0 vs lib/ayadn/action.rb in ayadn-1.1.1

- old
+ new

@@ -377,12 +377,15 @@ def unstar(post_id) begin missing_post_id unless post_id.is_integer? puts Status.unstarring(post_id) - if @api.get_details(post_id)['data']['you_starred'] - check_has_been_unstarred(post_id, @api.unstar(post_id)) + resp = @api.get_details(post_id) + id = get_original_id(post_id, resp) + resp = @api.get_details(id) + if resp['data']['you_starred'] + check_has_been_unstarred(id, @api.unstar(id)) else puts Status.not_your_starred end rescue => e Errors.global_error("action/unstar", post_id, e) @@ -393,12 +396,14 @@ def star(post_id) begin missing_post_id unless post_id.is_integer? puts Status.starring(post_id) - check_if_already_starred(@api.get_details(post_id)) - check_has_been_starred(post_id, @api.star(post_id)) + resp = @api.get_details(post_id) + check_if_already_starred(resp) + id = get_original_id(post_id, resp) + check_has_been_starred(id, @api.star(id)) rescue => e Errors.global_error("action/star", post_id, e) ensure Databases.close_all end @@ -835,11 +840,10 @@ itunes = get_track_infos itunes.each do |el| abort(Status.empty_fields) if el.length == 0 end @view.clear_screen - #text_to_post = "#nowplaying '#{itunes.track}' from '#{itunes.album}' by #{itunes.artist}" text_to_post = "#nowplaying\nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’" puts Status.writing show_nowplaying(text_to_post) unless STDIN.getch == ("y" || "Y") puts "\nCanceled.\n\n".color(:red) @@ -850,12 +854,10 @@ puts Status.yourpost @view.show_posted(resp) rescue => e puts Status.wtf Errors.global_error("action/nowplaying", itunes, e) - # ensure - # Databases.close_all end end def random_posts(options) begin @@ -1177,9 +1179,14 @@ stream['data']['username'] == Settings.config[:identity][:username] end def get_track_infos track = `osascript -e 'tell application "iTunes"' -e 'set trackName to name of current track' -e 'return trackName' -e 'end tell'` + if track.empty? + puts "\nCanceled: unable to get info from iTunes.\n".color(:red) + Errors.warn "Nowplaying canceled: unable to get info from iTunes." + exit + end album = `osascript -e 'tell application "iTunes"' -e 'set trackAlbum to album of current track' -e 'return trackAlbum' -e 'end tell'` artist = `osascript -e 'tell application "iTunes"' -e 'set trackArtist to artist of current track' -e 'return trackArtist' -e 'end tell'` maker = Struct.new(:artist, :album, :track) maker.new(artist.chomp!, album.chomp!, track.chomp!) end