Class: Ehbrs::Tools::Runner::WebUtils::Videos::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs/tools/runner/web_utils/videos/upload.rb

Instance Method Summary collapse

Instance Method Details

#movies_files_list_uncachedObject



49
50
51
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 49

def movies_files_list_uncached
  write_files_list('Videos::MovieFile', :movies_directory)
end

#process_response(files_list_path) ⇒ Object



38
39
40
41
42
43
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 38

def process_response(files_list_path)
  upload_request(files_list_path).body
rescue ::EhbrsRubyUtils::WebUtils::RequestError => e
  system('firefox', e.body_file_path.to_path)
  fatal_error("Retornou com erro: #{e.message}")
end

#runObject



14
15
16
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 14

def run
  %w[movies series].each { |type| upload_files_list(type) }
end

#series_files_list_uncachedObject



45
46
47
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 45

def series_files_list_uncached
  write_files_list('Videos::SeriesDirectory', :series_directory)
end

#upload_files_list(type) ⇒ Object



18
19
20
21
22
23
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 18

def upload_files_list(type)
  infom "Uploading \"#{type}\" files list..."
  files_list_path = send("#{type}_files_list")
  infov 'Path', files_list_path
  process_response(files_list_path)
end

#upload_request(files_list_path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 25

def upload_request(files_list_path)
  runner_context.call(:instance).http_request(
    '/videos/files/import',
    method: :put,
    body: {
      'videos_local_files_import_list[list_file]' => ::File.new(files_list_path)
    },
    header: {
      'Accept' => 'application/json'
    }
  )
end

#write_files_list(file_class, read_entry) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/ehbrs/tools/runner/web_utils/videos/upload.rb', line 53

def write_files_list(file_class, read_entry)
  files_list = ::EhbrsRubyUtils::WebUtils::Videos::FilesList.new(
    file_class,
    runner_context.call(:instance).read_entry(read_entry),
    ffprobe: !parsed.no_ffprobe?
  )
  infov 'Files found', files_list.data.fetch(:files).count
  files_list.write_to
end