Class: AirPlayer::Media

Inherits:
Object
  • Object
show all
Defined in:
lib/airplayer/media.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



23
24
25
# File 'lib/airplayer/media.rb', line 23

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



23
24
25
# File 'lib/airplayer/media.rb', line 23

def title
  @title
end

#typeObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


65
66
67
# File 'lib/airplayer/media.rb', line 65

def file?
  @type == :file
end

#url?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/airplayer/media.rb', line 69

def url?
  @type == :url
end