Class: CJOCHLSDownloader

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

Overview

CJOCHLSDownloader class downloads all HLS data from a URL

Instance Method Summary collapse

Constructor Details

#initialize(url, path, logfile = nil, loglevel = Logger::INFO) ⇒ CJOCHLSDownloader

Initialize CJOCHLSDownloader

Parameters:

  • url (String)

    the HLS source string

  • path (String)

    base path of all downloaded content

  • logfile (String) (defaults to: nil)

    log file to save the logs (optional)

  • loglevel (defaults to: Logger::INFO)

    log level, could be Logger::FATAL, Logger::ERROR, Logger::WARN, Logger::INFO, Logger::DEBUG (optional)



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/JOCHLSDownloader.rb', line 23

def initialize(url, path, logfile = nil, loglevel = Logger::INFO)

  @sourceurl = URI(url)
  @destpath = path

  #Start logger
  # Keep data for today and the past 3 days.
  @logger = nil
  if logfile != nil
    @logger = Logger.new(logfile)
    @logger.level = loglevel
  end
end

Instance Method Details

#startdownloadObject

Start to donwload the HLS content



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/JOCHLSDownloader.rb', line 38

def startdownload ()

  Log Logger::DEBUG, "Start download of #{@sourceurl} to #{@destpath}"

  #Get domain
  domain = @sourceurl.host
  url = @sourceurl.path
  port = @sourceurl.port

  Log Logger::DEBUG, "URI host: #{domain}, path: #{url}"

  downloadHLS domain, port, url, @destpath

end