Class: AirPlayer::Media
- Inherits:
-
Object
- Object
- AirPlayer::Media
- Defined in:
- lib/airplayer/media.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #file? ⇒ Boolean
-
#initialize(target) ⇒ Media
constructor
A new instance of Media.
- #url? ⇒ Boolean
Constructor Details
#initialize(target) ⇒ Media
Returns a new instance of Media.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/airplayer/media.rb', line 25 def initialize(target) path = File.(target) if File.exist? path @path = path @title = File.basename(path) @type = :file else @path = YoutubeDl.get_url(target) @title = YoutubeDl.get_title(target) @type = :url end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/airplayer/media.rb', line 23 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
23 24 25 |
# File 'lib/airplayer/media.rb', line 23 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/airplayer/media.rb', line 23 def type @type end |
Class Method Details
.is_url?(path) ⇒ Boolean
48 49 50 51 52 53 |
# File 'lib/airplayer/media.rb', line 48 def is_url?(path) uri = URI(path) uri.scheme && uri.absolute? rescue URI::InvalidURIError false end |
.playable?(path) ⇒ Boolean
40 41 42 43 44 45 46 |
# File 'lib/airplayer/media.rb', line 40 def playable?(path) if is_url?(path) YoutubeDl.supports?(path) || supported_mime_type?(YoutubeDl.filename(path)) else supported_mime_type?(path) end end |
.supported_mime_type?(path) ⇒ Boolean
55 56 57 58 59 60 61 |
# File 'lib/airplayer/media.rb', line 55 def supported_mime_type?(path) MIME::Types.of(path).map(&:simplified).each do |mimetype| return SUPPORTED_MIME_TYPES.include?(mimetype) end false end |
Instance Method Details
#file? ⇒ Boolean
65 66 67 |
# File 'lib/airplayer/media.rb', line 65 def file? @type == :file end |
#url? ⇒ Boolean
69 70 71 |
# File 'lib/airplayer/media.rb', line 69 def url? @type == :url end |