<commit_before>require 'net/http'
require 'ruby-progressbar'

class Episode
  def initialize(episode_no, link)
    @number = episode_no
    @link = link
  end
  attr_reader :number, :link

  def download_to(path = ".")
    url_base = @link.split('/')[2]
    url_path = '/'+@link.split('/')[3..-1].join('/')

    Net::HTTP.start(url_base) do |http|
      response = http.request_head(URI.escape(url_path))
      progress_bar = ProgressBar.create(:progress_mark => "\#", :length => 80, :total => response['content-length'].to_i)
      file = File.new( File.join( path, "Episode #{@number}.mp4" ), 'w')

      begin
        http.get(URI.escape(url_path)) do |str|
          file.write(str)

          begin
            progress_bar.progress += str.length
          rescue
            # Bypass InvalidProgressBar Error if raised
          end
        end
      rescue Exception
        # Handle SystemExit or Interrupt
        puts "Download incomplete. Deleting file."
        File.delete(File.join( path, "Episode #{@number}.mp4" ))
        raise
        exit
      end

      progress_bar.finish
    end

    puts "\n"
  end

  def details
    return "Episode #{@number}: #{@link}\n"
  end
end<commit_msg>Added line to rename file after download.<commit_after>require 'net/http'
require 'ruby-progressbar'

class Episode
  def initialize(episode_no, link)
    @number = episode_no
    @link = link
  end
  attr_reader :number, :link

  def download_to(path = ".")
    url_base = @link.split('/')[2]                    # Animeheaven
    url_path = '/'+@link.split('/')[3..-1].join('/')  # Sub Url

    Net::HTTP.start(url_base) do |http|
      response = http.request_head(URI.escape(url_path))
      progress_bar = ProgressBar.create(:progress_mark => "\#", :length => 80, :total => response['content-length'].to_i)
      file = File.new( File.join( path, "Episode #{@number}.mp4.tmp" ), 'w')

      begin
        http.get(URI.escape(url_path)) do |str|
          file.write(str)

          begin
            progress_bar.progress += str.length
          rescue # Bypass InvalidProgressBar Error if raised
          end
        end
      rescue Exception
        # Handle SystemExit or Interrupt
        puts "Download incomplete. Deleting file.\n\n"
        File.delete(File.join( path, "Episode #{@number}.mp4" ))
        raise
        exit
      end

      progress_bar.finish
      File.rename(file, File.join( path, "Episode #{@number}.mp4" ))
    end

    puts "\n"
  end

  def details
    return "Episode #{@number}: #{@link}\n"
  end
end
{'fraction_non_alphanumeric': 0.1387033398821218, 'fraction_numerical': 0.005893909626719057, 'mean_word_length': 2.3811420982735725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4461349', 'n_tokens_mistral': 827, 'n_tokens_neox': 805, 'n_words': 189}