lib/ayadn/nowplaying.rb in ayadn-3.0 vs lib/ayadn/nowplaying.rb in ayadn-4.0
- old
+ new
@@ -1,31 +1,26 @@
# encoding: utf-8
module Ayadn
class NowPlaying
- # Warning
- # comment next line
require_relative "ids"
- # uncomment next line and insert your own codes
- # AFFILIATE_SUFFIX = ""
- # DEEZER_APP_ID = ""
- # DEEZER_AUTH_URL = ""
begin
require 'rss'
rescue LoadError => e
puts "\nAYADN: Error while loading an external resource\n\n"
puts "RUBY: #{e}\n\n"
exit
end
- def initialize api, view, workers, options = {}
+ def initialize api, view, workers, status, options = {}
@api = api
@view = view
@workers = workers
- @status = Status.new
+ @status = status
+ # @status = Status.new
unless options[:hashtag]
@hashtag = "#nowplaying"
else
@hashtag = "##{options[:hashtag].join()}"
end
@@ -86,11 +81,11 @@
end
end
def itunes options
begin
- unless Settings.config[:platform] =~ /darwin/
+ unless Settings.config.platform =~ /darwin/
@status.error_only_osx
exit
end
@status.fetching_from('iTunes')
itunes = get_itunes_track_infos()
@@ -139,12 +134,12 @@
begin
before = text_to_post
unless options[:no_url] || store.nil?
text_to_post += "\n \n[iTunes Store](#{store['link']})"
end
- poster = Post.new
- poster.post_size_error(text_to_post) if poster.post_size_ok?(text_to_post) == false
+ poster = Post.new(@status)
+ poster.post_size_error(text_to_post) if !poster.post_size_ok?(text_to_post)
@view.clear_screen
@status.writing
show_nowplaying("\n#{before}", options, store)
unless STDIN.getch == ("y" || "Y")
@status.canceled
@@ -187,11 +182,11 @@
link: link,
source: source,
visible: visible
}
resp = poster.post(dic)
- FileOps.save_post(resp) if Settings.options[:backup][:posts]
+ FileOps.save_post(resp) if Settings.options.backup.posts
@view.show_posted(resp)
rescue => e
@status.wtf
Errors.global_error({error: e, caller: caller, data: [dic, store, options]})
end
@@ -243,14 +238,10 @@
get_itunes_store(itunes_url, artist, track)
end
def get_itunes_store url, artist, track
results = JSON.load(CNX.download(URI.escape(url)))['results']
-
- #
- # require 'pp'; pp results; exit
- #
unless results.nil?
if results.empty?
return {
@@ -264,14 +255,10 @@
candidates_track.each do |e|
next if e['artistName'].nil?
candidates << e if e['artistName'].downcase == artist.downcase
end
- #
- # require "pp";pp candidates; exit
- #
-
candidate = if candidates.empty?
results[0]
else
candidates[0]
end
@@ -307,13 +294,12 @@
maker = Struct.new(:artist, :album, :track)
maker.new(artist.chomp!, album.chomp!, track.chomp!)
end
def show_nowplaying(text, options, store)
- # @status.to_be_posted
thor = Thor::Shell::Basic.new
text.split("\n").each do |line|
- thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
+ thor.say_status(nil, line.color(Settings.options.colors.excerpt))
end
puts "\n"
unless options['no_url'] || store['code'] != 200
thor.say_status(nil, "[iTunes link](#1)")
thor.say_status(nil, "[album art](#2)")