Class: Ayadn::NowPlaying
- Inherits:
-
Object
- Object
- Ayadn::NowPlaying
- Defined in:
- lib/ayadn/nowplaying.rb
Instance Method Summary collapse
-
#initialize(api, view, workers, options = {}) ⇒ NowPlaying
constructor
A new instance of NowPlaying.
- #itunes(options) ⇒ Object
- #lastfm(options) ⇒ Object
Constructor Details
#initialize(api, view, workers, options = {}) ⇒ NowPlaying
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ayadn/nowplaying.rb', line 8 def initialize api, view, workers, = {} @api = api @view = view @workers = workers @status = Status.new unless [:hashtag] @hashtag = "#nowplaying" else @hashtag = "##{options[:hashtag].join()}" end unless [:text] @custom_text = nil else @custom_text = "\n \n#{options[:text].join(' ')}" end @affiliate_suffix = "&at=1l3vtb8&ct=ayadn" end |
Instance Method Details
#itunes(options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ayadn/nowplaying.rb', line 48 def itunes begin unless Settings.config[:platform] =~ /darwin/ @status.error_only_osx exit end @status.fetching_from('iTunes') itunes = get_itunes_track_infos() itunes.each do |el| if el.length == 0 @status.empty_fields exit end end @status.itunes_store store = [] unless ['no_url'] store = itunes_istore_request(itunes) if store['code'] == 404 && itunes.artist =~ /(and)/ itunes.artist.gsub!('and', '&') store = itunes_istore_request(itunes) end end text_to_post = "#{@hashtag}\n \nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’#{@custom_text}" (text_to_post, store, ) rescue => e @status.wtf Errors.global_error({error: e, caller: caller, data: [itunes, store, ]}) end end |
#lastfm(options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ayadn/nowplaying.rb', line 26 def lastfm begin user = Settings.[:nowplaying][:lastfm] || create_lastfm_user() @status.fetching_from('Last.fm') artist, track = get_lastfm_track_infos(user) @status.itunes_store store = [] unless ['no_url'] store = lastfm_istore_request(artist, track) if store['code'] == 404 && artist =~ /(and)/ artist.gsub!('and', '&') store = lastfm_istore_request(artist, track) end end text_to_post = "#{@hashtag}\n \nTitle: ‘#{track}’\nArtist: #{artist}#{@custom_text}" (text_to_post, store, ) rescue => e @status.wtf Errors.global_error({error: e, caller: caller, data: [store, ]}) end end |