diff --git a/app/components/movie_title_table_component.html.erb b/app/components/movie_title_table_component.html.erb
index 03399f7a..62dcac90 100644
--- a/app/components/movie_title_table_component.html.erb
+++ b/app/components/movie_title_table_component.html.erb
@@ -1,34 +1,40 @@
-
-
-
- # |
- Name |
- Duration |
- Size |
- |
-
-
-
- <% disks.each do |disk| %>
- <% disk.disk_titles.sort_by { |d| movie.runtime_range.include?(d.duration) ? 0 : 1 }.each do |disk_title| %>
- <% text_class = 'text-primary-emphasis' if movie.runtime_range.include?(disk_title.duration) %>
-
- <%= disk_title.id %> |
- <%= disk_title.name %> |
- <%= distance_of_time_in_words(disk_title.duration.seconds) %> |
-
- <%= number_to_human_size(disk_title.size, precision: 3) %>
- <% if disk_title.size >= free_disk_space %>
- WARNING: Not enough space available to rip need another <%= number_to_human_size(disk_title.size - free_disk_space, precision: 3) %>
- <% end %>
- |
-
- <%= link_to 'Rip', video_disk_title_path(movie, disk_title), data: { turbo_method: :patch } %>
- |
-
+<% if disks.any? %>
+
+
+
+ # |
+ Name |
+ Duration (<%= distance_of_time_in_words @movie.movie_runtime.seconds %>) |
+ Size |
+ |
+
+
+
+ <% disks.each do |disk| %>
+ <% disk.disk_titles.sort_by { |d| movie.runtime_range.include?(d.duration) ? 0 : 1 }.each do |disk_title| %>
+ <% text_class = 'text-primary-emphasis' if movie.runtime_range.include?(disk_title.duration) %>
+ <% text_class = 'text-success-emphasis' if movie.disk_title&.name == disk_title.name %>
+
+ <%= disk_title.id %> |
+ <%= disk_title.name %> |
+ <%= distance_of_time_in_words(disk_title.duration.seconds) %> |
+
+ <%= number_to_human_size(disk_title.size, precision: 3) %>
+ <% if disk_title.size >= free_disk_space %>
+ WARNING: Not enough space available to rip need another <%= number_to_human_size(disk_title.size - free_disk_space, precision: 3) %>
+ <% end %>
+ |
+
+ <%= link_to 'Rip', video_disk_title_path(movie, disk_title), data: { turbo_method: :patch } %>
+ |
+
+ <% end %>
<% end %>
-
- <% end %>
-
-
+
+
+<% elsif LoadDiskWorker.job.pending? %>
+ Loading Disk this might takes a while. Page will reload once ready. Fell free to refresh the page.
+<% else %>
+ Sorry no Disk is currently loaded or could be detected. Refresh page if your seeing this warning but know a disk is present.
+<% end %>
diff --git a/app/components/movie_title_table_component.rb b/app/components/movie_title_table_component.rb
index 71390aee..7cb901ff 100644
--- a/app/components/movie_title_table_component.rb
+++ b/app/components/movie_title_table_component.rb
@@ -3,7 +3,7 @@
class MovieTitleTableComponent < ViewComponent::Base
extend Dry::Initializer
- option :disks, Types::Array.of(Types.Instance(Disk))
+ option :disks, Types::Coercible::Array.of(Types.Instance(Disk))
option :movie, Types.Instance(Movie)
def dom_id
diff --git a/app/services/find_existing_disks_service.rb b/app/services/find_existing_disks_service.rb
index 38f4f4e8..7ca4318a 100644
--- a/app/services/find_existing_disks_service.rb
+++ b/app/services/find_existing_disks_service.rb
@@ -1,7 +1,13 @@
# frozen_string_literal: true
class FindExistingDisksService
- MOUNT_LINE = %r{\A(?\S+)\son\s(?:/Volumes/|)(?\S+)}
+ MOUNT_LINE = %r{\A(?\S+)\son\s(?:/Volumes/|)(?.*)\s[(]}
+ Device = Struct.new(:name, :disk_name) do
+ def rdisk_name
+ disk_name.gsub('/dev/', '/dev/r')
+ end
+ end
+
class << self
delegate :call, to: :new
end
@@ -9,15 +15,32 @@ class << self
# example line:
# /dev/disk4 on /Volumes/PLANET51 (udf, local, nodev, nosuid, read-only, noowners)
def call
- mounts = `mount`
- disks = []
- mounts.each_line do |line|
+ index = 0
+ devices.reduce(Disk.all) do |disks, device|
+ if index.zero?
+ disks.where(
+ name: device.name,
+ disk_name: [device.disk_name, device.rdisk_name]
+ )
+ else
+ disks.or(
+ Disk.where(
+ name: device.name,
+ disk_name: [device.disk_name, device.rdisk_name]
+ )
+ )
+ end.tap { index += 1 }
+ end
+ end
+
+ private
+
+ def devices
+ @devices ||= `mount`.each_line.filter_map do |line|
next unless line.start_with?('/dev/')
match = line.match(MOUNT_LINE)
- rdisk_name = match[:disk_name].gsub('/dev/', '/dev/r')
- disks << Disk.find_by(name: match[:name], disk_name: [match[:disk_name], rdisk_name])
+ Device.new(match[:name], match[:disk_name])
end
- disks.compact
end
end
diff --git a/app/services/list_drives_service.rb b/app/services/list_drives_service.rb
index f3a69a63..41a3dd54 100644
--- a/app/services/list_drives_service.rb
+++ b/app/services/list_drives_service.rb
@@ -2,14 +2,12 @@
class ListDrivesService
extend Dry::Initializer
- include Shell
- include MkvParser
option :noscan, Types::Bool, default: -> { false }
class << self
- def results(*)
- new(*).results
+ def results(...)
+ new(...).results
end
end
@@ -32,7 +30,7 @@ def info
end
def drives
- @drives ||= parse_mkv_string(info.stdout_str).select do |i|
+ @drives ||= info.parsed_mkv.select do |i|
i.is_a?(MkvParser::DRV) && i.enabled.to_i.positive?
end
end
diff --git a/app/tool_box/shell.rb b/app/tool_box/shell.rb
index 3b8d49c2..73b5ee25 100755
--- a/app/tool_box/shell.rb
+++ b/app/tool_box/shell.rb
@@ -3,7 +3,17 @@
module Shell
class Error < StandardError; end
- Standard = Struct.new(:stdout_str, :stderr_str, :status, keyword_init: true)
+ Standard = Struct.new(:stdout_str, :stderr_str, :status, keyword_init: true) do
+ include MkvParser
+
+ def success?
+ status.success?
+ end
+
+ def parsed_mkv
+ @parsed_mkv ||= parse_mkv_string(stdout_str)
+ end
+ end
def capture3(*cmd)
Rails.logger.debug { "command: #{cmd.join(', ')}" }
diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb
index 0ea4eb60..fb756d25 100644
--- a/app/views/movies/show.html.erb
+++ b/app/views/movies/show.html.erb
@@ -17,6 +17,9 @@
<%= link_to_movie_db_movie @movie.the_movie_db_id %>
+ Blue Means the disk title is within the runtime range of the movie.
+ Gream Means the disk has been ripped before.
+
<%= render MovieTitleTableComponent.new(disks: @disks, movie: @movie) %>
diff --git a/app/workers/rip_worker.rb b/app/workers/rip_worker.rb
index d05fdf7c..a79c4342 100644
--- a/app/workers/rip_worker.rb
+++ b/app/workers/rip_worker.rb
@@ -23,7 +23,7 @@ def create_mkv(disk_title)
def upload_mkv(disk_title)
sleep 1 while UploadWorker.job.pending?
- UploadWorker.perform_async(disk_title)
+ UploadWorker.perform_async(disk_title:)
end
def disk_titles