Class: Ayadn::NowPlaying

Inherits:
Object
  • Object
show all
Defined in:
lib/ayadn/nowplaying.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, view, workers) ⇒ NowPlaying

Returns a new instance of NowPlaying.



8
9
10
11
12
# File 'lib/ayadn/nowplaying.rb', line 8

def initialize api, view, workers
  @api = api
  @view = view
  @workers = workers
end

Instance Method Details

#itunes(options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ayadn/nowplaying.rb', line 29

def itunes options
  begin
    abort(Status.error_only_osx) unless Settings.config[:platform] =~ /darwin/
    puts Status.fetching_from('iTunes')
    itunes = get_itunes_track_infos()
    itunes.each {|el| abort(Status.empty_fields) if el.length == 0}
    puts Status.itunes_store
    store = itunes_istore_request(itunes) unless options['no_url']
    text_to_post = "#nowplaying\n \nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’"
    post_nowplaying(text_to_post, store, options)
  rescue => e
    puts Status.wtf
    Errors.global_error({error: e, caller: caller, data: [itunes, store, options]})
  end
end

#lastfm(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ayadn/nowplaying.rb', line 14

def lastfm options
  begin
    user = Settings.options[:nowplaying][:lastfm] || create_lastfm_user()
    puts Status.fetching_from('Last.fm')
    artist, track = get_lastfm_track_infos(user)
    puts Status.itunes_store
    store = lastfm_istore_request(artist, track) unless options['no_url']
    text_to_post = "#nowplaying\n \nTitle: ‘#{track}’\nArtist: #{artist}"
    post_nowplaying(text_to_post, store, options)
  rescue => e
    puts Status.wtf
    Errors.global_error({error: e, caller: caller, data: [store, options]})
  end
end