Class: EhbrsRubyUtils::WebUtils::Videos::FilesList
- Inherits:
-
Object
- Object
- EhbrsRubyUtils::WebUtils::Videos::FilesList
- Defined in:
- lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb
Instance Method Summary collapse
- #data ⇒ Object
- #file_data(path) ⇒ Object
- #file_ffprobe_data(path) ⇒ Object
- #files_data ⇒ Object
- #movies_files_data ⇒ Object
- #series_files_data ⇒ Object
- #write_to(path = nil) ⇒ Object
Instance Method Details
#data ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 25 def data { root_path: root_path.to_path, type: type_class, files: files_data } end |
#file_data(path) ⇒ Object
57 58 59 60 61 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 57 def file_data(path) r = { original_path: path } r[:ffprobe_data] = file_ffprobe_data(path) if ::File.file?(path) r end |
#file_ffprobe_data(path) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 63 def file_ffprobe_data(path) return {} unless .fetch(:ffprobe) infom "Probing \"#{path}\"..." ::JSON.parse(::EhbrsRubyUtils::Executables.ffprobe.command( '-hide_banner', '-print_format', 'json', '-show_format', '-show_streams', path ).execute!) end |
#files_data ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 33 def files_data case type_class when 'Videos::MovieFile' then movies_files_data when 'Videos::SeriesDirectory' then series_files_data else raise "Unknown type class: \"#{type_class}\"" end end |
#movies_files_data ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 41 def movies_files_data r = [] Dir["#{root_path}/**/*"].each do |path| r << file_data(path) if ::File.file?(path) end r end |
#series_files_data ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 49 def series_files_data r = [] Dir["#{root_path}/*"].each do |path| r << file_data(path) if ::File.directory?(path) end r end |
#write_to(path = nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb', line 19 def write_to(path = nil) path ||= ::EacRubyUtils::Fs::Temp.file.to_path ::File.write(path, data.to_json) path end |