Class: Media
- Inherits:
-
Object
- Object
- Media
- Defined in:
- lib/dvdprofiler2xbmc/models/media.rb
Overview
Synopsis
Media encapsulates information about a single media file
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Synopsis The file extension for the media.
-
#fanart_files ⇒ Object
readonly
Synopsis Array of fanart filenames associated with the media.
-
#image_files ⇒ Object
readonly
Synopsis Array of image filenames associated with the media.
-
#imdb_id ⇒ Object
Synopsis The IMDB ID in a String for the media.
-
#isbn ⇒ Object
Synopsis The ISBN number in a String for the media.
-
#media_path ⇒ Object
readonly
Synopsis filespec to the media file.
-
#media_subdirs ⇒ Object
readonly
Synopsis The realative pathspec from the top level directory to the directory that contains the media.
-
#part ⇒ Object
readonly
Synopsis nil or a String contain the media part (ex: cd1, disk2).
-
#resolution ⇒ Object
Synopsis The video resolution as a String.
-
#title ⇒ Object
readonly
Synopsis The media’s title String.
-
#title_with_year ⇒ Object
readonly
Synopsis The media’s title and year String (“title (year)”).
-
#year ⇒ Object
Synopsis The media’s production year.
Class Method Summary collapse
-
.parse(filespec) ⇒ Object
Synopsis parse the given filespec into a hash the consists of the found parts with keys: :title required :year optional :part optional :extension required.
Instance Method Summary collapse
-
#initialize(directory, media_file) ⇒ Media
constructor
Synopsis directory => String containing pathspec to the top level directory of the media media_file => String containing relative pathspec from the top level directory of the media to the media file.
-
#path_to(type) ⇒ Object
Synopsis return a path to a file file based on the media’s filespec but without any stacking parts and with the given extension instead of the media’s extension.
-
#to_s ⇒ Object
Synopsis return human readable string representation.
Constructor Details
#initialize(directory, media_file) ⇒ Media
Synopsis
directory => String containing pathspec to the top level directory of the media media_file => String containing relative pathspec from the top level
directory of the media to the media file
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 58 def initialize(directory, media_file) @media_subdirs = File.dirname(media_file) @media_path = File.(File.join(directory, media_file)) Dir.chdir(File.dirname(@media_path)) do @nfo_files = Dir.glob("*.{#{AppConfig[:extensions][:nfo]}}") @image_files = Dir.glob("*.{#{AppConfig[:extensions][:thumbnail]}}") @fanart_files = Dir.glob("*#{AppConfig[:extensions][:fanart]}*}") end components = Media.parse(@media_path) unless components.nil? @year = components[:year] @year = (@year.to_i > 0 ? @year : nil) unless @year.blank? @title = components[:title] @part = components[:part] @extension = components[:extension] @resolution = components[:resolution] end @title_with_year = find_title_with_year(@title, @year) end |
Instance Attribute Details
#extension ⇒ Object (readonly)
Synopsis
The file extension for the media
36 37 38 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 36 def extension @extension end |
#fanart_files ⇒ Object (readonly)
Synopsis
Array of fanart filenames associated with the media
15 16 17 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 15 def fanart_files @fanart_files end |
#image_files ⇒ Object (readonly)
Synopsis
Array of image filenames associated with the media
11 12 13 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 11 def image_files @image_files end |
#imdb_id ⇒ Object
Synopsis
The IMDB ID in a String for the media
44 45 46 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 44 def imdb_id @imdb_id end |
#isbn ⇒ Object
Synopsis
The ISBN number in a String for the media
40 41 42 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 40 def isbn @isbn end |
#media_path ⇒ Object (readonly)
Synopsis
filespec to the media file
7 8 9 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 7 def media_path @media_path end |
#media_subdirs ⇒ Object (readonly)
Synopsis
The realative pathspec from the top level directory to the directory that contains the media
20 21 22 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 20 def media_subdirs @media_subdirs end |
#part ⇒ Object (readonly)
Synopsis
nil or a String contain the media part (ex: cd1, disk2)
32 33 34 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 32 def part @part end |
#resolution ⇒ Object
Synopsis
The video resolution as a String
48 49 50 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 48 def resolution @resolution end |
#title ⇒ Object (readonly)
Synopsis
The media’s title String
24 25 26 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 24 def title @title end |
#title_with_year ⇒ Object (readonly)
Synopsis
The media’s title and year String (“title (year)”)
28 29 30 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 28 def title_with_year @title_with_year end |
#year ⇒ Object
Synopsis
The media’s production year
52 53 54 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 52 def year @year end |
Class Method Details
.parse(filespec) ⇒ Object
Synopsis
parse the given filespec into a hash the consists of the found parts with keys:
:title required
:year optional
:part optional
:extension required
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 101 def self.parse(filespec) result = nil filename = File.basename(filespec) AppConfig[:media_parsers].each do |parser| match_data = parser.regex.match(filename) unless match_data.nil? if((match_data.length - 1) == parser.tokens.length) index = 1 result = {} parser.tokens.each do |token| result[token] = match_data[index] index += 1 end break end end end result end |
Instance Method Details
#path_to(type) ⇒ Object
Synopsis
return a path to a file file based on the media’s filespec but without any stacking parts and with the given extension instead of the media’s extension. Example:
media_path = '/a/b/c.m4v'
path_to('nfo') => '/a/b/c.nfo'
media_path = '/a/b/c.part1.m4v'
path_to('nfo') => '/a/b/c.nfo'
89 90 91 92 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 89 def path_to(type) # ditch all extensions (ex, a.b => a, a.cd1.b => a) DvdProfiler2Xbmc.generate_filespec(@media_path, type, :year => @year, :resolution => @resolution) end |
#to_s ⇒ Object
Synopsis
return human readable string representation
123 124 125 126 127 128 129 |
# File 'lib/dvdprofiler2xbmc/models/media.rb', line 123 def to_s buf = [] buf << @media_path buf << '-' buf << title_with_year buf.join(' ') end |