Class: TivoHMO::Adapters::Plex::Metadata

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

Constant Summary

Constants included from TivoHMO::API::Metadata

TivoHMO::API::Metadata::MPAA_RATINGS, TivoHMO::API::Metadata::TV_RATINGS

Instance Attribute Summary

Attributes included from TivoHMO::API::Metadata

#actors, #actual_showing, #advisory, #bookmark, #channel, #choreographers, #color_code, #description, #directors, #duration, #episode_number, #episode_title, #executive_producers, #guest_stars, #hosts, #is_episode, #item, #movie_year, #mpaa_rating, #original_air_date, #part_count, #part_index, #producers, #program_genres, #program_id, #recording_quality, #series_genres, #series_id, #series_title, #show_type, #showing_bits, #source_size, #star_rating, #start_time, #stop_time, #time, #title, #tv_rating, #writers

Instance Method Summary collapse

Methods included from TivoHMO::API::Metadata

#estimate_source_size

Constructor Details

#initialize(item) ⇒ Metadata

Returns a new instance of Metadata.



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

def initialize(item)
  super

  begin
    self.description = item.delegate.summary
    self.duration = (item.delegate.duration.to_i / 1000).to_i

    # plex 0-10 => tivo 1-7 for value, 0-4 in .5 increments for name
    plex_rating = item.delegate.rating.to_f
    rating_value = (plex_rating / 10 * 6).round
    rating_name = [1, 1.5, 2, 2.5, 3, 3.5, 4][rating_value]
    self.star_rating = {name: rating_name, value: rating_value + 1}

  rescue => e
    logger.error "Failed to read plex metadata: #{e}"
  end
end