Class: Ayadn::TvShow

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

Constant Summary collapse

AYADN_TVDB_API_KEY =
'E874ACBC542CAA53'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTvShow

Returns a new instance of TvShow.



12
13
14
15
16
# File 'lib/ayadn/tvshow.rb', line 12

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

Instance Attribute Details

Returns the value of attribute banner_url.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def banner_url
  @banner_url
end

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def date
  @date
end

Returns the value of attribute imdb_link.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def imdb_link
  @imdb_link
end

#languageObject

Returns the value of attribute language.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def language
  @language
end

Returns the value of attribute link.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def link
  @link
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def name
  @name
end

#plotObject

Returns the value of attribute plot.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def plot
  @plot
end

#poster_urlObject

Returns the value of attribute poster_url.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def poster_url
  @poster_url
end

#tagObject

Returns the value of attribute tag.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def tag
  @tag
end

#textObject

Returns the value of attribute text.



10
11
12
# File 'lib/ayadn/tvshow.rb', line 10

def text
  @text
end

Instance Method Details

#cancelObject



101
102
103
# File 'lib/ayadn/tvshow.rb', line 101

def cancel
  abort(Status.canceled)
end

#create_details(show_obj) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/ayadn/tvshow.rb', line 40

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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ayadn/tvshow.rb', line 51

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



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

def find title
  res = find_all(title)
  abort(Status.no_show) if res[0].nil?
  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
  abort(Status.no_show)
end

#find_alt(title) ⇒ Object



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

def find_alt title
  res = find_all(title)
  abort(Status.no_show) if res[0].nil?
  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
  abort(Status.no_show)
end

#okObject



66
67
68
69
70
71
72
73
# File 'lib/ayadn/tvshow.rb', line 66

def ok
  @view.clear_screen
  puts Status.writing
  puts "\nYour post:\n\n".color(:cyan)
  puts @text
  puts "\n\nIs it ok? (y/N)".color(:yellow)
  STDIN.getch == ("y" || "Y") ? true : false
end

#post(options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ayadn/tvshow.rb', line 75

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
  puts "\nPosting and uploading the show poster...\n".color(:green)
  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][:auto_save_sent_posts]
  @view.clear_screen
  puts Status.yourpost
  @view.show_posted(resp)
end