Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:00:00+00:00 2026-05-16T14:00:00+00:00

require ‘net/http’; require ‘uri’; require ‘rexml/document’; require ‘sqlite3’; def download_torrent(episode_id, torrent_url, limit = 10)

  • 0

require 'net/http';
require 'uri';
require 'rexml/document';
require 'sqlite3';

def download_torrent(episode_id, torrent_url, limit = 10)
  # Check to make sure we haven't been trapped in an infinite loop
  if limit == 0 then
    puts "Too much redirection, skipping #{episode_id}";
    return true;
  else
    # Convert the URL of the torrent into a URI usable by Net:HTTP
    torrent_uri = URI.parse(torrent_url);
    # Open a connection to the torrent URL
    Net::HTTP.get_response(torrent_uri) { |http|
      # Check to see if we were able to connect to the torrent URL
      case http
      # We connected just fine
      when Net::HTTPSuccess then
        # Create a torrent file to store the data in
        File.open("#{episode_id}.torrent", 'wb') { |torrent_file|
          # Write the torrent data to the torrent file
          torrent_file.write(http.body);
          # Close the torrent file
          torrent_file.close
          # Check to see if we've download a 'locked' torrent file (html) instead of a regular torrent (.torrent)
          if(File.exists?('download.torrent.html'))
            # Delete the html file
            File.delete('download_torrent.html');
            return false;
          else
            return true;
          end
        }
      when Net::HTTPRedirection then
          download_torrent(episode_id, http['location'], limit - 1);
      end
    }
  end
end

My function does not return ‘true’ in the boolean sense. It keeps returning <Net::HTTPFound:0x3186c60> which causes my ‘does this function return true’ conditional to evaluate to false. Why is this function not exiting when it hits the first return statement (like every other language I’ve used)

I know this is totally a Ruby Newbie (I Rhymed!) question, but I appreciate the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:00:01+00:00Added an answer on May 16, 2026 at 2:00 pm

    Apparently, Net::HTTP.get_response has passed Net::HTTPFound instance as http parameter into inner block. Therefore, return statement was never reached and your download_torrent method returned the last object “on stack”, which happens to be return value of Net::HTTP.get_response.

    If that description is a little vague, here’s a shorter example. With return true part, do_it method will return true. Without it, do_it method will return object returned by do_that.

    def do_it
      do_that {|param|
    #    return true;
      }
    end
    

    I have little experience with net/http package, you’ll probably have to read docs and handle Net::HTTPFound response in your case operator somehow.

    Personally, this always worked for me in fetching webpage contents: Net::HTTP.get(URI.parse(url)). It’s simpler without code block and simply returns content as string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

require 'net/http' 1.upto(99) do |novel| puts Downloading ##{novel}... Net::HTTP.start(http://www.nbc.com) do |http| resp = http.get(/heroes/novels/downloads/Heroes_novel_0#{novel}.pdf)
require 'net/http' urls = [ {'link' => 'http://www.google.com/'}, {'link' => 'http://www.facebook.com/'}, {'link' => 'http://www.yahoo.com/'}
Require the following to work: http://jsfiddle.net/xavi3r/4J583/ <div class=cmAuto active a default></div> $('body').append(<div> + $('div').hasClass('.active.default')
require 'nokogiri' require 'open-uri' page = Nokogiri::HTML(open(http://wwp.greenwichmeantime.com/)) puts page.xpath(.//*[@id='offset']/span[1]).text this should output the gmt
require 'open-uri' print Enter a URL add = gets open(#{add}) do |f| j =
I require ASP.NET server side code in a SVG that I created. To accomplish
require 'rubygems' require 'test/unit' class Thing attr_accessor :foo def set_stuff @foo = 'bar' end
require 'rubygems' require 'mechanize' agent = Mechanize.new page = agent.get(http://google.com/) This simple script works
Require.js seems to be adding ?v= at the end of my http requests for
require 'mechanize' agent = Mechanize.new login = agent.get('http://www.schoolnet.ch/DE/HomeDE.htm') agent.click login.link_with text: /Login/ And I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.