Class: TivoHMO::Adapters::Filesystem::FolderContainer

Inherits:
Object
  • Object
show all
Includes:
GemLogger::LoggerSupport, MonitorMixin, TivoHMO::API::Container, Config::Mixin
Defined in:
lib/tivohmo/adapters/filesystem/folder_container.rb

Overview

A Container based on a filesystem folder

Direct Known Subclasses

Application

Constant Summary collapse

VIDEO_EXTENSIONS =
%w[
  tivo mpg avi wmv mov flv f4v vob mp4 m4v mkv
  ts tp trp 3g2 3gp 3gp2 3gpp amv asf avs bik bix box bsf
  dat dif divx dmb dpg dv dvr-ms evo eye flc fli flx gvi ivf
  m1v m21 m2t m2ts m2v m2p m4e mjp mjpeg mod moov movie mp21
  mpe mpeg mpv mpv2 mqv mts mvb nsv nuv nut ogm qt rm rmvb
  rts scm smv ssm svi vdo vfw vid viv vivo vp6 vp7 vro webm
  wm wmd wtv yuv
]

Instance Attribute Summary collapse

Attributes included from TivoHMO::API::Container

#presorted, #uuid

Attributes included from TivoHMO::API::Node

#app, #content_type, #created_at, #identifier, #modified_at, #parent, #root, #source_format, #title

Instance Method Summary collapse

Methods included from TivoHMO::API::Container

#child_count, #refresh

Methods included from TivoHMO::API::Node

#add_child, #app?, #find, #root?, #title_path, #to_s, #tree_string

Constructor Details

#initialize(identifier) ⇒ FolderContainer

Returns a new instance of FolderContainer.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tivohmo/adapters/filesystem/folder_container.rb', line 30

def initialize(identifier)
  @full_path = File.expand_path(identifier)
  raise ArgumentError,
        "Must provide an existing directory: #{full_path}" unless File.directory?(full_path)

  super(full_path)

  self.allowed_item_types = i[file dir]
  self.allowed_item_extensions = VIDEO_EXTENSIONS

  self.title = File.basename(self.identifier).titleize
  self.modified_at = File.mtime(self.identifier)
  self.created_at = File.ctime(self.identifier)

  @subtitles = config_get(:enable_subtitles)
end

Instance Attribute Details

#allowed_item_extensionsObject

Returns the value of attribute allowed_item_extensions.



27
28
29
# File 'lib/tivohmo/adapters/filesystem/folder_container.rb', line 27

def allowed_item_extensions
  @allowed_item_extensions
end

#allowed_item_typesObject

Returns the value of attribute allowed_item_types.



27
28
29
# File 'lib/tivohmo/adapters/filesystem/folder_container.rb', line 27

def allowed_item_types
  @allowed_item_types
end

#full_pathObject (readonly)

Returns the value of attribute full_path.



25
26
27
# File 'lib/tivohmo/adapters/filesystem/folder_container.rb', line 25

def full_path
  @full_path
end

Instance Method Details

#childrenObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tivohmo/adapters/filesystem/folder_container.rb', line 47

def children
  synchronize do
    if super.blank? || @subtitles != config_get(:enable_subtitles)
      super.clear
      @subtitles = config_get(:enable_subtitles)

      items = Dir["#{self.full_path}/*"].group_by do |path|
        if allowed_container?(path)
          :dir
        elsif allowed_item?(path)
          :file
        else
          :skipped
        end
      end

      Array(items[:dir]).each {|path| add_child(FolderContainer.new(path)) }
      Array(items[:file]).each {|path| add_grouped(path) }
      Array(items[:skipped]).each {|path| logger.debug "Ignoring: #{path}" } if logger.debug?

    end
  end

  super
end