Class: Ayadn::NowWatching

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

Instance Method Summary collapse

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, options = {}
  resp = @spotlite.find(args.join(' '))
  if options['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.options[: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.options[: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, options
  options = options.dup
  response = get_response(args, options)
  filename = create_filename(response)
  FileOps.download_url(filename, response.poster_url)
  options[:embed] ||= []
  options[:embed] << "#{Settings.config[:paths][:downloads]}/#{filename}"
  return options
end

#get_response(args, options) ⇒ Object




15
16
17
# File 'lib/ayadn/nowwatching.rb', line 15

def get_response args, options
  find_by_title(args, options)
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, options
  options = options.dup
  puts "\nContacting IMDb.com...".color(:cyan)
  response = find_by_title(args, options)
  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)
  options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
  options[:movie] = true
  dic = {
    options: options,
    text: text,
    title: response.title,
    source: 'IMDb'
  }
  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