19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/searchlink/searches/tmdb.rb', line 19
def search(search_type, terms, link_text)
type = case search_type
when /t$/
"tv"
when /m$/
"movie"
when /a$/
"person"
else
"multi"
end
body = `/usr/bin/curl -sSL 'https://api.themoviedb.org/3/search/#{type}?query=#{terms.url_encode}&api_key=2bd76548656d92517f14d64766e87a02'`
data = JSON.parse(body)
if data.key?("results") && data["results"].count.positive?
res = data["results"][0]
type = res["media_type"] if type == "multi"
id = res["id"]
url = "https://www.themoviedb.org/#{type}/#{id}"
title = res["name"]
title ||= res["title"]
title ||= terms
else
url, title, link_text = SL.ddg("site:imdb.com #{terms}", link_text)
return false unless url
end
link_text = title if link_text == "" && !SL.titleize
[url, title, link_text]
end
|