Class: Mediaman::MediaFilename

Inherits:
Object
  • Object
show all
Defined in:
lib/mediaman/media_filename.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ MediaFilename

Returns a new instance of MediaFilename.



9
10
11
12
# File 'lib/mediaman/media_filename.rb', line 9

def initialize(filename)        
  self.filename = override_filename filename
  @parsed_name = self.to_name
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



7
8
9
# File 'lib/mediaman/media_filename.rb', line 7

def filename
  @filename
end

Instance Method Details

#episodeObject



73
74
75
# File 'lib/mediaman/media_filename.rb', line 73

def episode
  @parsed_name[:episode_number]
end

#formatted_nameObject



51
52
53
54
55
56
57
58
# File 'lib/mediaman/media_filename.rb', line 51

def formatted_name
  name = @parsed_name[:name]

  # Hacks
  name.gsub! /Extended( Version)?( Edition)?/i, ""

  name.strip.chomp
end

#h264?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/mediaman/media_filename.rb', line 93

def h264?
  (self.filename =~ /m4v|mp4|h264|x264/i).present?
end

#hd?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/mediaman/media_filename.rb', line 89

def hd?
  self.filename.include?("720p") || self.filename.include?("1080p") || self.filename.include?("HDTV")  || self.filename.include?("HDRip")
end

#hd_formatObject



97
98
99
100
101
102
103
104
105
106
# File 'lib/mediaman/media_filename.rb', line 97

def hd_format
  return "SD" unless hd?
  if self.filename.include?("720p")
    "720p"
  elsif self.filename.include?("1080p")
    "1080p"
  else
    "HD"
  end
end

#movie?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/mediaman/media_filename.rb', line 85

def movie?
  !tv? && year.present?
end

#override_filename(name) ⇒ Object



14
15
16
17
# File 'lib/mediaman/media_filename.rb', line 14

def override_filename(name)
  name.gsub!("2012", "") if name.include?("Newsroom")
  name
end

#raw_nameObject



47
48
49
# File 'lib/mediaman/media_filename.rb', line 47

def raw_name
  self.filename
end

#seasonObject



69
70
71
# File 'lib/mediaman/media_filename.rb', line 69

def season
  @parsed_name[:season_number]
end

#title_slugObject



60
61
62
63
64
65
66
67
# File 'lib/mediaman/media_filename.rb', line 60

def title_slug
  slug = formatted_name.parameterize

  #Hacks
  slug = "the-newsroom-2012" if slug == "the-newsroom"

  slug
end

#to_hashObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mediaman/media_filename.rb', line 31

def to_hash
  {
    filename: self.filename,
    name: self.formatted_name,
    raw_name: self.raw_name,
    year: self.year,
    tv: self.tv?,
    movie: self.movie?,
    season_number: self.season,
    episode_number: self.episode,
    hd: self.hd?,
    hd_format: self.hd_format,
    title_slug: self.title_slug
  }
end

#to_nameObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mediaman/media_filename.rb', line 19

def to_name
  fn = ToName.to_name(filename)
  {
    name: fn.name,
    year: fn.year,
    raw_name: fn.raw_name,
    location: fn.location,
    season_number: fn.series,
    episode_number: fn.episode
  }
end

#to_sObject



108
109
110
# File 'lib/mediaman/media_filename.rb', line 108

def to_s
  formatted_name
end

#tv?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/mediaman/media_filename.rb', line 77

def tv?
  episode.present? && season.present?
end

#yearObject



81
82
83
# File 'lib/mediaman/media_filename.rb', line 81

def year
  @parsed_name[:year]
end