Class: Ayadn::NowWatching
Instance Method Summary collapse
- #create_filename(response) ⇒ Object
- #find_by_title(args, options = {}) ⇒ Object
- #format_plot(response, text) ⇒ Object
- #format_post(response) ⇒ Object
-
#get_poster(args, options) ⇒ Object
This is only for the ‘-M` option in the CLI.
-
#get_response(args, options) ⇒ Object
—–.
-
#initialize(view = nil) ⇒ NowWatching
constructor
A new instance of NowWatching.
-
#post(args, options) ⇒ Object
—–.
Constructor Details
#initialize(view = nil) ⇒ NowWatching
Returns a new instance of NowWatching.
14 15 16 17 18 |
# File 'lib/ayadn/nowwatching.rb', line 14 def initialize view = nil @view = view @spotlite = Spotlite::Movie @status = Status.new end |
Instance Method Details
#create_filename(response) ⇒ Object
26 27 28 29 |
# File 'lib/ayadn/nowwatching.rb', line 26 def create_filename response reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/ "#{response.title.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg" end |
#find_by_title(args, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/ayadn/nowwatching.rb', line 70 def find_by_title args, = {} resp = @spotlite.find(args.join(' ')) if ['alt'] resp[1] else resp[0] end end |
#format_plot(response, text) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ayadn/nowwatching.rb', line 87 def format_plot response, text max = 239 - (text.length + Settings.[:movie][:hashtag].length) short = max - 3 plot = response.description if plot.length > max "#{plot[0..short]}..." else plot end end |
#format_post(response) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/ayadn/nowwatching.rb', line 79 def format_post response tag = Settings.[:movie][:hashtag] text_1 = "'#{response.title}' (#{response.year})" link = "[IMDb](#{response.url})" plot = format_plot(response, text_1) "#{text_1}\n \n#{plot}\n \n#{link}\n \n##{tag}\n\n" end |
#get_poster(args, options) ⇒ Object
This is only for the ‘-M` option in the CLI
32 33 34 35 36 37 38 39 40 |
# File 'lib/ayadn/nowwatching.rb', line 32 def get_poster args, = .dup response = get_response(args, ) filename = create_filename(response) FileOps.download_url(filename, response.poster_url) [:embed] ||= [] [:embed] << "#{Settings.config[:paths][:downloads]}/#{filename}" return end |
#get_response(args, options) ⇒ Object
22 23 24 |
# File 'lib/ayadn/nowwatching.rb', line 22 def get_response args, find_by_title(args, ) end |
#post(args, options) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ayadn/nowwatching.rb', line 44 def post args, = .dup @status.info("connected", "IMDb", "yellow") response = find_by_title(args, ) text = format_post(response) show_post(text) filename = create_filename(response) FileOps.download_url(filename, response.poster_url) @view.clear_screen @status.info("uploading", "movie poster", "yellow") [:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"] [:movie] = true dic = { options: , text: text, title: response.title, source: 'IMDb' } resp = Post.new.post(dic) FileOps.save_post(resp) if Settings.[:backup][:posts] @view.clear_screen @status.yourpost puts "\n\n" @view.show_posted(resp) end |