Class: Tapas::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/tapas/downloader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(episode, config) ⇒ Downloader

Returns a new instance of Downloader.



8
9
10
11
12
# File 'lib/tapas/downloader.rb', line 8

def initialize(episode, config)
  @episode = episode
  @config = config
  @output = default_output(episode, config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/tapas/downloader.rb', line 6

def config
  @config
end

#episodeObject (readonly)

Returns the value of attribute episode.



6
7
8
# File 'lib/tapas/downloader.rb', line 6

def episode
  @episode
end

#outputObject (readonly)

Returns the value of attribute output.



6
7
8
# File 'lib/tapas/downloader.rb', line 6

def output
  @output
end

#progress_barObject (readonly)

Returns the value of attribute progress_bar.



6
7
8
# File 'lib/tapas/downloader.rb', line 6

def progress_bar
  @progress_bar
end

Instance Method Details

#downloadObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tapas/downloader.rb', line 14

def download
  open_opts = {
    http_basic_authentication: [config.username, config.password],
    content_length_proc: length_proc,
    progress_proc: progress_proc
  }
  open(episode.url, open_opts) do |download|
    File.open(output, 'wb') do |out|
      out.write download.read
    end
  end
end