Class: Ayadn::TvShow

Inherits:
Object show all
Defined in:
lib/ayadn/ids.rb,
lib/ayadn/tvshow.rb

Constant Summary collapse

TVDB_API_KEY =
'E874ACBC542CAA53'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTvShow

Returns a new instance of TvShow.



22
23
24
25
26
27
# File 'lib/ayadn/tvshow.rb', line 22

def initialize
  @language = 'en'
  @view = View.new
  @tvdb = TvdbParty::Search.new(TVDB_API_KEY)
  @status = Status.new
end

Instance Attribute Details

Returns the value of attribute banner_url.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def banner_url
  @banner_url
end

#dateObject

Returns the value of attribute date.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def date
  @date
end

Returns the value of attribute imdb_link.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def imdb_link
  @imdb_link
end

#languageObject

Returns the value of attribute language.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def language
  @language
end

Returns the value of attribute link.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def link
  @link
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def name
  @name
end

#plotObject

Returns the value of attribute plot.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def plot
  @plot
end

#poster_urlObject

Returns the value of attribute poster_url.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def poster_url
  @poster_url
end

#tagObject

Returns the value of attribute tag.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def tag
  @tag
end

#textObject

Returns the value of attribute text.



20
21
22
# File 'lib/ayadn/tvshow.rb', line 20

def text
  @text
end

Instance Method Details

#cancelObject



126
127
128
129
# File 'lib/ayadn/tvshow.rb', line 126

def cancel
  @status.canceled
  exit
end

#create_details(show_obj) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/ayadn/tvshow.rb', line 59

def create_details show_obj
  @name = show_obj.name
  @poster_url = find_poster_url(show_obj)
  @banner_url = find_banner_url(show_obj)
  @plot = find_plot(show_obj)
  @date = show_obj.first_aired.year
  @imdb_link = "http://imdb.com/title/#{show_obj.imdb_id}/"
  create_text()
  return self
end

#create_textObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ayadn/tvshow.rb', line 70

def create_text
  @link = "[IMDb](#{@imdb_link})"
  @tag = Settings.options[:tvshow][:hashtag]
  @date.nil? ? date = '' : date = "(#{@date})"
  pre = "#{@name} #{date}\n \n"
  presize = pre.length + @tag.length + 4 + @plot.length
  max = 241
  if presize > max
    plot_max = max - (pre.length + @tag.length)
    @text = "#{pre}#{@plot[0..plot_max]}...\n \n#{@link}\n \n##{@tag}"
  else
    @text = "#{pre}#{@plot}\n \n#{@link}\n \n##{@tag}"
  end
end

#find(title) ⇒ Object



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

def find title
  res = find_all(title)
  if res[0].nil?
    @status.no_show
    exit
  end
  if res[0].has_key?('FirstAired')
    return @tvdb.get_series_by_id(res[0]['seriesid'])
  else
    return @tvdb.get_series_by_id(res[1]['seriesid']) unless res[1].nil?
  end
  @status.no_show
  exit
end

#find_alt(title) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ayadn/tvshow.rb', line 44

def find_alt title
  res = find_all(title)
  if res[0].nil?
    @status.no_show
    exit
  end
  if res[0].has_key?('FirstAired')
    return @tvdb.get_series_by_id(res[1]['seriesid']) unless res[1].nil?
  else
    return @tvdb.get_series_by_id(res[2]['seriesid']) unless res[2].nil?
  end
  @status.no_show
  exit
end

#okObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ayadn/tvshow.rb', line 85

def ok
  @view.clear_screen
  @status.writing
  @status.to_be_posted
  thor = Thor::Shell::Basic.new
  puts "\n"
  @text.split("\n").each do |line|
    thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
  end
  puts "\n"
  @status.ok?
  STDIN.getch == ("y" || "Y") ? true : false
end

#post(options = {}) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ayadn/tvshow.rb', line 99

def post options = {}
  options = options.dup
  reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
  filename = "#{@name.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg"
  if options['banner']
    FileOps.download_url(filename, @banner_url)
  else
    FileOps.download_url(filename, @poster_url)
  end
  @view.clear_screen
  @status.info("uploading", "show poster", "yellow")
  options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
  options[:tvshow] = true
  dic = {
    options: options,
    text: @text,
    title: @name,
    source: 'TVDb'
  }
  resp = Post.new.post(dic)
  FileOps.save_post(resp) if Settings.options[:backup][:posts]
  @view.clear_screen
  @status.yourpost
  puts "\n\n"
  @view.show_posted(resp)
end