Class: MultimediaParadise::Video::MovieSearcher
- Inherits:
-
Base
- Object
- Base
- MultimediaParadise::Video::MovieSearcher
show all
- Defined in:
- lib/multimedia_paradise/video/movie_searcher.rb
Overview
Constant Summary
collapse
- API_KEY =
else use a hardcoded default.
'946f500a'
Constants inherited
from Base
Base::ERROR, Base::ERROR_LINE, Base::NAMESPACE, Base::USE_THIS_NAMESPACE_FOR_THE_COLOURS, Base::USE_THIS_NAMESPACE_FOR_THE_CORE_COLOURS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#actions, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #cartoons_directory?, #clear_the_internal_hash, #cliner_with_time_stamp, #colourized_comment, #copy_file, #crimson, #dataset_from_file_video_collection, #dd_mm_yyyy, #debug?, #default_readlines, #directory_to_realvids?, #do_not_use_opn, #dodgerblue, #does_the_video_player_support_this_commandline?, #e, #ecomment, #ecrimson, #efancy, #enable_debug, #ensure_main_encoding, #ensure_that_the_output_directory_exists, #eparse, #erev, #esystem, #ewarn, #file_video_collection?, #filter_for_audio_files, #filter_for_video_files, #forestgreen, #gold, #grey, #hh_mm_ss, #home_x_video?, #indianred, #infer_the_namespace, #internal_hash?, #is_audio_file?, #is_mkv?, #is_mp3?, #is_mp4?, #is_multimedia_file?, #is_on_roebe?, #is_video_file?, #konsole_colour_peru, #lightblue, #lightgreen, #load_yaml, #local_audio_directory?, #log_dir?, #map_symbol_to_locally_existing_file, #mediumorchid, #mediumpurple, #mediumslateblue, #mkdir, #move_file, #namespace?, #no_file_exists, #no_file_exists_at, #olive, #olivedrab, #opne, #opnecomment, #opnn, #orange, #palegoldenrod, #palegreen, #powderblue, #project_base_directory?, #rds, #register_sigint, #remove_file, #report_pwd, #reset_the_internal_hash, #return_all_video_files, #return_pwd, #return_random_video, #rev, #royalblue, #save_what_into, #sdir, #seagreen, #seconds_to_time_format, #select_only_video_files_from, #set_be_verbose, #set_use_colours, #sfancy, #sfile, #simp, #skyblue, #slateblue, #springgreen, #steelblue, #swarn, #teal, #time_right_now, #to_hh_mm_ss, #tomato, #true_rev, #try_to_rename_kde_konsole_tab, #ucliner, #use_colours?, #use_opn?, #use_which_video_player?, #verbose_truth, #video_collection?, #violet, #yaml_directory?, #yel
#all_input_starts_with_a_number?, #commandline_arguments?, #commandline_arguments_as_a_string, #first_argument?, #first_non_hyphened_commandline_argument?, #set_commandline_arguments
Constructor Details
#initialize(i = nil, run_already = true) ⇒ MovieSearcher
48
49
50
51
52
53
54
55
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 48
def initialize(
i = nil,
run_already = true
)
reset
set_name_of_the_movie(i)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
265
266
267
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 265
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#api_key? ⇒ Boolean
80
81
82
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 80
def api_key?
@api_key
end
|
#cliner(optional_input = nil) ⇒ Object
#
cliner
If input is provided, then we will use this embedded into the line.
#
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 144
def cliner(optional_input = nil)
result = '=' * @width_limit
if optional_input
_ = " #{optional_input} "
result[1,_.size] = palegoldenrod(_)
end
return result+N
end
|
#determine_whether_rest_client_is_available_and_exit_if_it_is_unavailable ⇒ Object
#
determine_whether_rest_client_is_available_and_exit_if_it_is_unavailable
#
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 159
def determine_whether_rest_client_is_available_and_exit_if_it_is_unavailable
begin
require 'rest-client'
rescue LoadError
unless Object.const_defined? :RestClient
opnn; e "The gem #{slateblue('rest-client')}"\
" appears to be missing. Please install it"
opnn; e 'first, as this class depends on the namespace '\
'RestClient.'
exit 1
end
end
begin
require 'json'
rescue LoadError
unless Object.const_defined? :Json
opnn; e "The gem #{slateblue('json')}"\
" appears to be missing. Please install it"
opnn; e 'first, as this class depends on json indirectly.'
exit 1
end
end
end
|
#display_main_string ⇒ Object
124
125
126
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 124
def display_main_string
e @main_string
end
|
#name_of_the_movie? ⇒ Boolean
Also known as:
movie_name?
108
109
110
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 108
def name_of_the_movie?
@name_of_the_movie
end
|
#report_that_no_movie_has_been_found_with_this_name(i = movie_name?
) ⇒ Object
#
report_that_no_movie_has_been_found_with_this_name
#
131
132
133
134
135
136
137
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 131
def report_that_no_movie_has_been_found_with_this_name(
i = movie_name?
)
e
opnn; e "No movie has been found with this name (#{sfancy(i)})."
e
end
|
#reset ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 60
def reset
super()
infer_the_namespace
@width_limit = 78
@main_string = ''.dup
@api_key = API_KEY
end
|
#run ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 189
def run
determine_whether_rest_client_is_available_and_exit_if_it_is_unavailable
_ = movie_name? case _ when 'quit','exit'
exit 0
else
url = "http://www.omdbapi.com/?t=#{_}&apikey=#{api_key?}"
if debug?
opnn; e 'Now working on the URL `'+sfancy(url)+'`.'
end
response = RestClient.get(url)
info = JSON.parse(response)
case info['Response'].to_s
when 'False'
report_that_no_movie_has_been_found_with_this_name(_)
exit 0
else
begin
title = info['Title']
year = info['Year']
score = info['Ratings'][1]['Value']
rescue
score = 'No Score Found'
end
indent_to_use = 65
rated = info['Rated']
genre = info['Genre']
director = info['Director']
actors = wrap(info['Actors'], indent_to_use)
plot_unformatted = info['Plot']
plot = wrap(plot_unformatted, indent_to_use)
@main_string << "#{N}" << cliner('Movie')
@main_string << "| #{mediumorchid('Title')}: #{title}"+N
@main_string << "| #{mediumpurple('Year')}: #{year.rjust(5)}"+N
@main_string << "| #{skyblue('Tomato')}: #{score.rjust(5)}"+N
@main_string << "| #{royalblue('Rated')}: #{rated.center(5)}"+N
@main_string << "| #{palegreen('Genre')}: #{genre}"+N
@main_string << "| #{indianred('Director')}: #{director}"+N
@main_string << "| #{springgreen('Actors')}: #{actors}"+N
@main_string << "| #{seagreen('Plot')}: #{plot}"+N
@main_string << cliner+N
display_main_string
end
end
end
|
#set_name_of_the_movie(i = '') ⇒ Object
#
set_name_of_the_movie
#
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 87
def set_name_of_the_movie(i = '')
i = i.join(' ').strip if i.is_a? Array
i = i.to_s.dup.chomp.strip
if i.include? '.'
i.sub!(/#{File.extname(i)}/,'')
end
if i.include?('_') and (i =~ /^\d+/)
use_this_regex = /\d{1,3}_(.+)/ i =~ use_this_regex
i = $1.to_s.dup if $1
end
@name_of_the_movie = i
end
|
#wrap(i, width_limit = @width_limit) ⇒ Object
#
wrap (wrap tag)
A word-wrapping method.
#
117
118
119
|
# File 'lib/multimedia_paradise/video/movie_searcher.rb', line 117
def wrap(i, width_limit = @width_limit)
i.gsub(/(.{1,#{width_limit}})(\s+|\Z)/, "\\1\n| ")
end
|