Class: Ayadn::TvShow
- Inherits:
-
Object
- Object
- Ayadn::TvShow
- Defined in:
- lib/ayadn/tvshow.rb
Constant Summary collapse
- AYADN_TVDB_API_KEY =
'E874ACBC542CAA53'
Instance Attribute Summary collapse
-
#banner_url ⇒ Object
Returns the value of attribute banner_url.
-
#date ⇒ Object
Returns the value of attribute date.
-
#imdb_link ⇒ Object
Returns the value of attribute imdb_link.
-
#language ⇒ Object
Returns the value of attribute language.
-
#link ⇒ Object
Returns the value of attribute link.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plot ⇒ Object
Returns the value of attribute plot.
-
#poster_url ⇒ Object
Returns the value of attribute poster_url.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #cancel ⇒ Object
- #create_details(show_obj) ⇒ Object
- #create_text ⇒ Object
- #find(title) ⇒ Object
- #find_alt(title) ⇒ Object
-
#initialize ⇒ TvShow
constructor
A new instance of TvShow.
- #ok ⇒ Object
- #post(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ TvShow
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
#banner_url ⇒ Object
Returns the value of attribute banner_url.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def @banner_url end |
#date ⇒ Object
Returns the value of attribute date.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def date @date end |
#imdb_link ⇒ Object
Returns the value of attribute imdb_link.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def imdb_link @imdb_link end |
#language ⇒ Object
Returns the value of attribute language.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def language @language end |
#link ⇒ Object
Returns the value of attribute link.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def name @name end |
#plot ⇒ Object
Returns the value of attribute plot.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def plot @plot end |
#poster_url ⇒ Object
Returns the value of attribute poster_url.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def poster_url @poster_url end |
#tag ⇒ Object
Returns the value of attribute tag.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def tag @tag end |
#text ⇒ Object
Returns the value of attribute text.
10 11 12 |
# File 'lib/ayadn/tvshow.rb', line 10 def text @text end |
Instance Method Details
#cancel ⇒ Object
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 = (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_text ⇒ Object
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.[: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 |
#ok ⇒ Object
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 = {} = .dup reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/ filename = "#{@name.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg" if ['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) [:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"] [:tvshow] = true dic = { options: , text: @text, title: @name, source: 'TVDb' } resp = Post.new.post(dic) FileOps.save_post(resp) if Settings.[:backup][:auto_save_sent_posts] @view.clear_screen puts Status.yourpost @view.show_posted(resp) end |