Class: Ayadn::NowWatching
- Inherits:
-
Object
- Object
- Ayadn::NowWatching
- Defined in:
- lib/ayadn/nowwatching.rb
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.
8 9 10 11 |
# File 'lib/ayadn/nowwatching.rb', line 8 def initialize view = nil @view = view @spotlite = Spotlite::Movie end |
Instance Method Details
#create_filename(response) ⇒ Object
19 20 21 22 |
# File 'lib/ayadn/nowwatching.rb', line 19 def create_filename response reg = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/ "#{response.title.downcase.strip.gsub(reg, '_').split(' ').join('_')}.jpg" end |
#find_by_title(args, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/ayadn/nowwatching.rb', line 62 def find_by_title args, = {} resp = @spotlite.find(args.join(' ')) if ['alt'] resp[1] else resp[0] end end |
#format_plot(response, text) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ayadn/nowwatching.rb', line 79 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
71 72 73 74 75 76 77 |
# File 'lib/ayadn/nowwatching.rb', line 71 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
25 26 27 28 29 30 31 32 33 |
# File 'lib/ayadn/nowwatching.rb', line 25 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
15 16 17 |
# File 'lib/ayadn/nowwatching.rb', line 15 def get_response args, find_by_title(args, ) end |
#post(args, options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ayadn/nowwatching.rb', line 37 def post args, = .dup puts "\nContacting IMDb.com...".color(:cyan) 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 puts "\nPosting and uploading the movie poster...\n".color(:green) [: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][:auto_save_sent_posts] @view.clear_screen puts Status.yourpost @view.show_posted(resp) end |