Class: Mediaman::Metadata

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/mediaman/metadata.rb

Instance Method Summary collapse

Instance Method Details

#canonical_descriptionObject



38
39
40
41
42
43
44
# File 'lib/mediaman/metadata.rb', line 38

def canonical_description
  if tv?
    episode_details.try(:[], "overview").presence
  else
    movie_details.try(:[], "overview").presence
  end
end

#canonical_directorObject



46
47
48
49
50
51
52
53
# File 'lib/mediaman/metadata.rb', line 46

def canonical_director
  if movie?
    d = movie_details.try(:[], "people").try(:[], "directors").presence
    if d
      d.map{|director| director.name}.join ", "
    end
  end
end

#canonical_episode_nameObject



12
13
14
# File 'lib/mediaman/metadata.rb', line 12

def canonical_episode_name
  episode_details.try(:title).presence
end

#canonical_image_urlObject



30
31
32
33
34
35
36
# File 'lib/mediaman/metadata.rb', line 30

def canonical_image_url
  if tv?
    episode_details.try(:[], "images").try(:first).try(:last)
  else
    movie_details.try(:[], "poster").presence
  end
end

#canonical_movie_titleObject



16
17
18
# File 'lib/mediaman/metadata.rb', line 16

def canonical_movie_title
  movie_details.try(:title).presence || name.presence || raw_name.presence
end

#canonical_ratingObject



55
56
57
# File 'lib/mediaman/metadata.rb', line 55

def canonical_rating
  movie_details.try(:[], "certification").presence
end

#canonical_show_nameObject



8
9
10
# File 'lib/mediaman/metadata.rb', line 8

def canonical_show_name
  show_details.try(:title).presence || name.presence || raw_name.presence
end

#canonical_yearObject



59
60
61
# File 'lib/mediaman/metadata.rb', line 59

def canonical_year
  movie_details.try(:[], "year").presence || year.presence
end

#episode_idObject



20
21
22
# File 'lib/mediaman/metadata.rb', line 20

def episode_id
  "#{season_number}x#{"%02d" % episode_number}"
end

#library_categoryObject



24
25
26
27
28
# File 'lib/mediaman/metadata.rb', line 24

def library_category
  return "TV Shows" if tv?
  return "Movies" if movie?
  "Other Media"
end

#to_subler_hashObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mediaman/metadata.rb', line 67

def to_subler_hash
  h = {}
  if movie?
    h[:name] = canonical_movie_title
    h[:media_kind] = "Movie"
    h[:rating] = canonical_rating if canonical_rating
    h[:year] = canonical_year if canonical_year
  end
  if tv?
    h[:name] = canonical_episode_name
    h[:tv_show] = canonical_show_name
    h[:album] = canonical_show_name
    h[:tv_episode_id] = episode_id
    h[:tv_episode_number] = episode_number
    h[:tv_season] = season_number
    h[:track_number] = "#{episode_number}/0"
    h[:media_kind] = "TV Show"
  end
  h[:description] = canonical_description if canonical_description.present?
  h[:hd_video] = true if hd?
  h
end

#uuidObject



63
64
65
# File 'lib/mediaman/metadata.rb', line 63

def uuid
  movie_details.try(:[], "imdb_id") || Digest::MD5.hexdigest("#{filename}")
end