Class: Ayadn::NowWatching

Inherits:
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.



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, options = {}
  resp = @spotlite.find(args.join(' '))
  if options['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.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



79
80
81
82
83
84
85
# File 'lib/ayadn/nowwatching.rb', line 79

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



32
33
34
35
36
37
38
39
40
# File 'lib/ayadn/nowwatching.rb', line 32

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




22
23
24
# File 'lib/ayadn/nowwatching.rb', line 22

def get_response args, options
  find_by_title(args, options)
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, options
  options = options.dup
  @status.info("connected", "IMDb", "yellow")
  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
  @status.info("uploading", "movie poster", "yellow")
  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][:posts]
  @view.clear_screen
  @status.yourpost
  puts "\n\n"
  @view.show_posted(resp)
end