Class: MyLocalPutio::SubtitlesManager

Inherits:
Object
  • Object
show all
Defined in:
lib/my-local-putio/subtitles_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ SubtitlesManager

Returns a new instance of SubtitlesManager.



5
6
7
8
9
10
# File 'lib/my-local-putio/subtitles_manager.rb', line 5

def initialize(configuration)
  @configuration = configuration
  @logger = configuration.logger
  @cli = PutioCli.new(@configuration)
  @downloader = Downloader.new(@configuration)
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli.



3
4
5
# File 'lib/my-local-putio/subtitles_manager.rb', line 3

def cli
  @cli
end

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/my-local-putio/subtitles_manager.rb', line 3

def configuration
  @configuration
end

#downloaderObject (readonly)

Returns the value of attribute downloader.



3
4
5
# File 'lib/my-local-putio/subtitles_manager.rb', line 3

def downloader
  @downloader
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/my-local-putio/subtitles_manager.rb', line 3

def logger
  @logger
end

Instance Method Details

#fetch(file, path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/my-local-putio/subtitles_manager.rb', line 12

def fetch(file, path)
  return unless configuration.with_subtitles
  return unless file_is_video?(file)

  local_subtitle_path = File.join(path, filename(file))
  logger.log "Trying to fetch the preferred subtitle for: #{file.name}"
  subtitles = cli.get_subtitles(file.id)["subtitles"]
  if subtitles.empty?
    logger.log ":( Could not find any preferred subtitle for: #{file.name}"
    return
  end

  process_subtitle(subtitles, local_subtitle_path)
end