Skip to content

Instantly share code, notes, and snippets.

@bchase
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save bchase/bcecbb625a19293b775f to your computer and use it in GitHub Desktop.

Select an option

Save bchase/bcecbb625a19293b775f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# REQUIREMENTS
# 1. ruby - http://rubyinstaller.org/
# 2. vlc - http://www.videolan.org/vlc/index.html
#
# USAGE
# 1. save this file as `randime.rb` (type: `All Files`)
# 2. beneath `__END__` below, paste in absolute folder paths containing videos you want played
# 3. double click the `randime.rb` icon to play
require 'pathname'
module VLC
def self.exec_path
if Gem.win_platform?
f = 'C:\Program Files (x86)\VideoLAN\VLC\VLC.exe'
File.exist?(f) ? f : 'C:\Program Files\VideoLAN\VLC\VLC.exe'
else
"vlc"
end.inspect
end
def self.build_arg_str(files)
files.map(&:inspect).join(' ')
end
def self.play(files)
vlc, args = exec_path, build_arg_str(files)
%x[ #{vlc} #{args} ]
end
end
class WhitelistedDir < Pathname
VIDEO_FORMATS = %w[.mp4 .mkv .avi]
def self.all
@all ||= DATA.read.split("\n").map{|d|new d}
end
def video_files
files.select{|f| VIDEO_FORMATS.include? File.extname(f) }
end
def files
return unless exist?
pwd = Dir.pwd
Dir.chdir self
files = Dir['*']
Dir.chdir pwd
files.map{|f| self.join(f).to_s}
end
end
class WhitelistedVideo
def self.all
WhitelistedDir.all
.map(&:video_files)
.flatten
.compact
end
end
VLC.play WhitelistedVideo.all.shuffle
__END__
C:/Paths/To/Your
C:/Video/Folders/Here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment