class AirPlayer::Media

Attributes

path[R]
title[R]
type[R]

Public Class Methods

is_url?(path) click to toggle source
# File lib/airplayer/media.rb, line 48
def is_url?(path)
  uri = URI(path)
  uri.scheme && uri.absolute?
rescue URI::InvalidURIError
  false
end
new(target) click to toggle source
# File lib/airplayer/media.rb, line 25
def initialize(target)
  path = File.expand_path(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
playable?(path) click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

file?() click to toggle source
# File lib/airplayer/media.rb, line 65
def file?
  @type == :file
end
url?() click to toggle source
# File lib/airplayer/media.rb, line 69
def url?
  @type == :url
end