Class: TivoHMO::Adapters::Plex::Movie

Inherits:
Object
  • Object
show all
Includes:
GemLogger::LoggerSupport, TivoHMO::API::Item
Defined in:
lib/tivohmo/adapters/plex/movie.rb

Instance Attribute Summary collapse

Attributes included from TivoHMO::API::Item

#file, #subtitle

Attributes included from TivoHMO::API::Node

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

Instance Method Summary collapse

Methods included from TivoHMO::API::Item

#to_s, #transcoder

Methods included from TivoHMO::API::Node

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

Constructor Details

#initialize(delegate, subtitle = nil) ⇒ Movie



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tivohmo/adapters/plex/movie.rb', line 11

def initialize(delegate, subtitle=nil)
  # delegate is a Plex::Movie
  @delegate = delegate

  super(delegate.key)

  self.file = CGI.unescape(delegate.medias.first.parts.first.file)
  self.subtitle = subtitle

  self.title = delegate.title
  self.title = "[#{subtitle.language_code} #{subtitle.type} sub] #{self.title}" if subtitle

  self.modified_at = Time.at(delegate.updated_at.to_i)
  self.created_at = Time.parse(delegate.originally_available_at) rescue nil
  self.created_at ||= Time.at(delegate.added_at.to_i)
end

Instance Attribute Details

#delegateObject (readonly)

Returns the value of attribute delegate.



9
10
11
# File 'lib/tivohmo/adapters/plex/movie.rb', line 9

def delegate
  @delegate
end

Instance Method Details

#metadataObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tivohmo/adapters/plex/movie.rb', line 28

def 
  md = super

  begin

    md.movie_year = Time.parse(delegate.originally_available_at).year rescue nil

    rating_name = delegate.content_rating.upcase rescue nil
    rating_value = TivoHMO::API::Metadata::MPAA_RATINGS[rating_name]
    if rating_value
      md.mpaa_rating = {name: rating_name, value: rating_value}
    end

    md.actors = delegate.roles.collect(&:tag) rescue nil
    md.program_genres = delegate.genres.collect(&:tag) rescue nil

    %w[writers directors producers].each do |md_name|
      md.send("#{md_name}=", delegate.send(md_name).collect(&:tag)) rescue nil
    end

  rescue => e
    logger.log_exception e, "Failed to read plex metadata for #{self}"
  end

  md
end