Class: Cejo::Media::Play
- Inherits:
-
Object
- Object
- Cejo::Media::Play
- Defined in:
- lib/cejo/media/play/play.rb
Overview
Play file, random media in folder or with url.
Constant Summary collapse
- PLAYER =
'mpv'
- PLAYER_CONFIG =
'--no-config --no-audio-display'
- PLAYER_FORMAT =
'--ytdl-format="bestvideo[height<=?1080]+bestaudio/best"'
Instance Attribute Summary collapse
-
#media ⇒ Object
readonly
Returns the value of attribute media.
Instance Method Summary collapse
- #final_command ⇒ Object
-
#initialize(media) ⇒ Play
constructor
A new instance of Play.
- #pick_media ⇒ Object
- #pick_random_media_in_folder(folder) ⇒ Object
- #player_settings ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(media) ⇒ Play
Returns a new instance of Play.
14 15 16 |
# File 'lib/cejo/media/play/play.rb', line 14 def initialize(media) @media = media end |
Instance Attribute Details
#media ⇒ Object (readonly)
Returns the value of attribute media.
12 13 14 |
# File 'lib/cejo/media/play/play.rb', line 12 def media @media end |
Instance Method Details
#final_command ⇒ Object
36 37 38 |
# File 'lib/cejo/media/play/play.rb', line 36 def final_command "#{player_settings} #{pick_media}" end |
#pick_media ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/cejo/media/play/play.rb', line 23 def pick_media filepath = Pathname.new(media) return filepath.to_path if filepath.file? return pick_random_media_in_folder(filepath) if filepath.directory? media end |
#pick_random_media_in_folder(folder) ⇒ Object
18 19 20 21 |
# File 'lib/cejo/media/play/play.rb', line 18 def pick_random_media_in_folder(folder) file = folder.children.sample folder.join(file).to_path end |
#player_settings ⇒ Object
32 33 34 |
# File 'lib/cejo/media/play/play.rb', line 32 def player_settings "#{PLAYER} #{PLAYER_CONFIG} #{PLAYER_FORMAT}" end |
#run ⇒ Object
40 41 42 |
# File 'lib/cejo/media/play/play.rb', line 40 def run system final_command end |