Class: CourseraDownloader::Downloader

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

Constant Summary collapse

MAX_BATCH_SIZE =
10

Instance Method Summary collapse

Constructor Details

#initialize(cookie_file, policy, store, logger) ⇒ Downloader

Returns a new instance of Downloader.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/coursera_downloader/downloader.rb', line 9

def initialize(cookie_file, policy, store, logger)
  @cookie_file = cookie_file
  @store = store
  @policy = policy
  @logger = logger

  @queue = []
  @enqueued = Set.new # all URLs that have been ever enqueued during this run

  read_state
end

Instance Method Details

#get(url) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/coursera_downloader/downloader.rb', line 21

def get(url)
  url = URI.parse(url) unless url.is_a?(URI)

  enqueue_new_url(url)
  fetch_all
  @logger.info("Downloaded #{@enqueued.length} total files")
end