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

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

Instance Method Summary collapse

Instance Method Details

#movies_files_list_uncachedObject



58
59
60
# File 'lib/ehbrs/runner/web_utils/videos/upload.rb', line 58

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

#process_response(response) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ehbrs/runner/web_utils/videos/upload.rb', line 42

def process_response(response)
  infov 'Response status', response.status
  if response.status == 200
    pp ::JSON.parse(response.body) # rubocop:disable Rails/Output
  else
    error_file = '/tmp/ehbrsutils.html'
    ::File.write(error_file, response.body)
    system('firefox', error_file)
    fatal_error('Retornou com status de erro: ' + error_file)
  end
end

#runObject



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

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

#series_files_list_uncachedObject



54
55
56
# File 'lib/ehbrs/runner/web_utils/videos/upload.rb', line 54

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

#upload_files_list(type) ⇒ Object



22
23
24
25
26
27
# File 'lib/ehbrs/runner/web_utils/videos/upload.rb', line 22

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

#upload_request(files_list_path) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ehbrs/runner/web_utils/videos/upload.rb', line 29

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

#write_files_list(file_class, read_entry) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/ehbrs/runner/web_utils/videos/upload.rb', line 62

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