Last active
June 28, 2021 22:09
-
-
Save XanderStrike/772686f5d2adedfa3a07c07c13e48f09 to your computer and use it in GitHub Desktop.
API Glue between JasonHHouse/gaps and tidusjar/Ombi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# fillgaps.rb | |
# Alex Standke 2021 | |
# | |
# Requirements: | |
# * You must have Gaps and Ombi set up and running | |
# * https://github.com/JasonHHouse/gaps | |
# * https://github.com/tidusjar/Ombi | |
# | |
# Use: | |
# * Modify the four variables below | |
# * Optionally remove the line at the bottom to avoid being prompted for every movie | |
# * Run! | |
GAPS_RSS="" | |
OMBI_API_KEY="" | |
OMBI_USER="" | |
OMBI_URL="" | |
require 'net/http' | |
require 'json' | |
require 'cgi' | |
def getJSON(url, method: Net::HTTP::Get, body: "") | |
uri = URI(url) | |
req = method.new(uri) | |
req.body = body | |
req['Accept'] = 'application/json' | |
req['Content-Type'] = 'application/json' | |
req['ApiKey'] = OMBI_API_KEY | |
req['UserName'] = OMBI_USER | |
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') {|http| | |
http.request(req) | |
} | |
JSON.parse(res.body) | |
end | |
def request(movie) | |
route = "#{OMBI_URL}/api/v1/Search/movie/#{CGI.escape(movie["title"])}" | |
id = getJSON(route).first["theMovieDbId"] | |
body = { | |
theMovieDbId: id, | |
languageCode: 'en' | |
} | |
route = "#{OMBI_URL}/api/v1/Request/movie" | |
response = getJSON(route, method: Net::HTTP::Post, body: body.to_json) | |
print response["message"], response["errorMessage"], "\n" | |
end | |
someJson = getJSON(GAPS_RSS) | |
puts "#{someJson.count} missing movies identified" | |
someJson.each do |movie| | |
print "Request #{movie['title']}..." | |
next unless gets.downcase.start_with?('y') # remove this line to add em all | |
request(movie) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know. I kinda regret writing/running it to be honest because it pushed so many requests into Ombi that it became unresponsive and I had to clear the database. Sorry about that.