Module: ActiveEncode::FilenameSanitizer
- Included in:
- ActiveEncode
- Defined in:
- lib/active_encode/filename_sanitizer.rb
Instance Method Summary collapse
- #sanitize_base(input_url) ⇒ Object
- #sanitize_filename(input_url) ⇒ Object
-
#sanitize_input(input_url) ⇒ Object
ffmpeg has trouble with double quotes in file names.
- #sanitize_uri(input_url) ⇒ Object
Instance Method Details
#sanitize_base(input_url) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/active_encode/filename_sanitizer.rb', line 9 def sanitize_base(input_url) filepath = input_url.is_a?(URI::HTTP) ? input_url.path : input_url # Replace special characters with underscores and remove excess periods. # This removes the extension before processing so it is safe to delete all detected periods. File.basename(filepath, File.extname(filepath)).gsub(/[^0-9A-Za-z.\-\/]/, '_').delete('.') end |
#sanitize_filename(input_url) ⇒ Object
16 17 18 19 20 |
# File 'lib/active_encode/filename_sanitizer.rb', line 16 def sanitize_filename(input_url) filepath = input_url.is_a?(URI::HTTP) ? input_url.path : input_url # Replace special characters with underscores and remove excess periods. File.basename(filepath).gsub(/[^0-9A-Za-z.\-\/]/, '_').gsub(/\.(?=.*\.)/, '') end |
#sanitize_input(input_url) ⇒ Object
ffmpeg has trouble with double quotes in file names. Escape them to get ffmpeg to find the file.
5 6 7 |
# File 'lib/active_encode/filename_sanitizer.rb', line 5 def sanitize_input(input_url) input_url.gsub(/["]/, '\\\\\0') end |
#sanitize_uri(input_url) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_encode/filename_sanitizer.rb', line 22 def sanitize_uri(input_url) case input_url when /^file\:\/\/\// input_url.to_s.gsub(/file:\/\//, '') when /^s3\:\/\// input_url.to_s.gsub(/#{Addressable::URI.parse(input_url).normalized_site}/, '') when /^https?:\/\// input_url end end |