Skip to content

Commit

Permalink
Fixed bug with Not finding disk info in DB & Made the GUI a bit nicer…
Browse files Browse the repository at this point in the history
… when it comes to what is going on

commit-id:a50256ab
  • Loading branch information
brand-it committed Apr 22, 2024
1 parent 45f8a68 commit df8c858
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
70 changes: 38 additions & 32 deletions app/components/movie_title_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
<table class="table" id="<%= dom_id %>">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Duration</th>
<th>Size</th>
<th></th>
</tr>
</thead>
<tbody class="disk_titles">
<% 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) %>

<tr>
<th scope="row" class="<%= text_class %>"><%= disk_title.id %></th>
<td class="<%= text_class %>"><%= disk_title.name %></td>
<td class="<%= text_class %>"><%= distance_of_time_in_words(disk_title.duration.seconds) %></td>
<td class="<%= disk_title.size >= free_disk_space ? 'text-danger' : text_class %>">
<%= 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 %>
</td>
<td class="<%= text_class %>">
<%= link_to 'Rip', video_disk_title_path(movie, disk_title), data: { turbo_method: :patch } %>
</td>
</tr>
<% if disks.any? %>
<table class="table" id="<%= dom_id %>">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Duration (<%= distance_of_time_in_words @movie.movie_runtime.seconds %>)</th>
<th>Size</th>
<th></th>
</tr>
</thead>
<tbody class="disk_titles">
<% 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 %>
<tr>
<th scope="row" class="<%= text_class %>"><%= disk_title.id %></th>
<td class="<%= text_class %>"><%= disk_title.name %></td>
<td class="<%= text_class %>"><%= distance_of_time_in_words(disk_title.duration.seconds) %></td>
<td class="<%= disk_title.size >= free_disk_space ? 'text-danger' : text_class %>">
<%= 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 %>
</td>
<td class="<%= text_class %>">
<%= link_to 'Rip', video_disk_title_path(movie, disk_title), data: { turbo_method: :patch } %>
</td>
</tr>
<% end %>
<% end %>

<% end %>
</tbody>
</table>
</tbody>
</table>
<% elsif LoadDiskWorker.job.pending? %>
<p class="text-info">Loading Disk this might takes a while. Page will reload once ready. Fell free to refresh the page.</p>
<% else %>
<p class="text-warn">Sorry no Disk is currently loaded or could be detected. Refresh page if your seeing this warning but know a disk is present.</p>
<% end %>
2 changes: 1 addition & 1 deletion app/components/movie_title_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions app/services/list_drives_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/views/movies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<%= link_to_movie_db_movie @movie.the_movie_db_id %>
</small>
</p>
<p class="text-primary-emphasis">Blue Means the disk title is within the runtime range of the movie.</p>
<p class="text-success-emphasis">Gream Means the disk has been ripped before.</p>

<div id='disk-selector'>
<%= render MovieTitleTableComponent.new(disks: @disks, movie: @movie) %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/workers/rip_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df8c858

Please sign in to comment.