Skip to content

Instantly share code, notes, and snippets.

@XanderStrike
Last active June 28, 2021 22:09
Show Gist options
  • Save XanderStrike/772686f5d2adedfa3a07c07c13e48f09 to your computer and use it in GitHub Desktop.
Save XanderStrike/772686f5d2adedfa3a07c07c13e48f09 to your computer and use it in GitHub Desktop.

Revisions

  1. XanderStrike revised this gist Jan 3, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions fillgaps.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env ruby

    # fillgaps.rb
    # Alex Standke 2020
    # Alex Standke 2021
    #
    # Requirements:
    # * You must have Gaps and Ombi set up and running
    @@ -10,7 +10,7 @@
    #
    # Use:
    # * Modify the four variables below
    # * Optionally uncomment the line at the bottom to be prompted to confirm each film
    # * Optionally remove the line at the bottom to avoid being prompted for every movie
    # * Run!

    GAPS_RSS=""
  2. XanderStrike created this gist Jan 3, 2021.
    64 changes: 64 additions & 0 deletions fillgaps.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    #!/usr/bin/env ruby

    # fillgaps.rb
    # Alex Standke 2020
    #
    # 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 uncomment the line at the bottom to be prompted to confirm each film
    # * 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