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.



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

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

Instance Attribute Details

Returns the value of attribute banner_url.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def banner_url
  @banner_url
end

#dateObject

Returns the value of attribute date.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def date
  @date
end

Returns the value of attribute imdb_link.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def imdb_link
  @imdb_link
end

#languageObject

Returns the value of attribute language.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def language
  @language
end

Returns the value of attribute link.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def link
  @link
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def name
  @name
end

#plotObject

Returns the value of attribute plot.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def plot
  @plot
end

#poster_urlObject

Returns the value of attribute poster_url.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def poster_url
  @poster_url
end

#tagObject

Returns the value of attribute tag.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def tag
  @tag
end

#textObject

Returns the value of attribute text.



16
17
18
# File 'lib/ayadn/tvshow.rb', line 16

def text
  @text
end

Instance Method Details

#cancelObject



122
123
124
125
# File 'lib/ayadn/tvshow.rb', line 122

def cancel
  @status.canceled
  exit
end

#create_details(show_obj) ⇒ Object



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

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ayadn/tvshow.rb', line 66

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



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

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



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

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



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ayadn/tvshow.rb', line 81

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



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

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