Skip to content

Commit

Permalink
V4.0.0 Working on new system for handling extras on movies (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
brand-it authored Jul 15, 2024
1 parent 4ef7c87 commit 90773ef
Show file tree
Hide file tree
Showing 58 changed files with 604 additions and 479 deletions.
16 changes: 11 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
# on 2024-07-14 00:55:29 UTC using RuboCop version 1.65.0.
# on 2024-07-15 20:10:17 UTC using RuboCop version 1.65.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -27,21 +27,25 @@ Lint/UnreachableCode:
Exclude:
- 'lib/tasks/upload.rake'

# Offense count: 8
# Offense count: 11
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'app/listeners/mkv_progress_listener.rb'
- 'app/models/video_blob.rb'
- 'app/services/create_disks_service.rb'
- 'app/services/create_mkv_service.rb'
- 'app/services/eject_disk_service.rb'
- 'app/workers/rip_worker.rb'
- 'app/workers/scan_plex_worker.rb'

# Offense count: 1
# Offense count: 3
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
- 'app/listeners/mkv_progress_listener.rb'
- 'app/models/video_blob.rb'
- 'app/workers/scan_plex_worker.rb'

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Expand All @@ -50,11 +54,13 @@ Metrics/CyclomaticComplexity:
- 'app/controllers/start_controller.rb'
- 'app/models/video_blob.rb'

# Offense count: 5
# Offense count: 9
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
- 'app/models/video_blob.rb'
- 'app/services/create_disks_service.rb'
- 'app/services/create_mkv_service.rb'
- 'app/workers/scan_plex_worker.rb'

# Offense count: 3
Expand Down Expand Up @@ -84,7 +90,7 @@ RSpec/MultipleMemoizedHelpers:
Exclude:
- 'spec/workers/rip_worker_spec.rb'

# Offense count: 11
# Offense count: 12
Rails/I18nLocaleTexts:
Exclude:
- 'app/controllers/config/make_mkvs_controller.rb'
Expand Down
68 changes: 48 additions & 20 deletions app/components/movie_title_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,43 +1,71 @@

<% if disks.any? %>
<table class="table" id="<%= dom_id %>">
<thead>
<tr>
<th>#</th>
<th>Name(video title)</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| %>
<%= simple_form_for :movies, url: rip_movie_path(movie) do |f| %>
<% disk = disks.first %>
<%= hidden_field_tag :disk_id, disk&.id %>
<table class="table" id="<%= dom_id %>">
<thead>
<tr>
<th>#</th>
<th>Ripped</th>
<th>Uploaded</th>
<th>Name(video title)</th>
<th>Duration (<%= distance_of_time_in_words @movie.movie_runtime.seconds %>)</th>
<th>Size</th>
<th></th>
</tr>
</thead>
<tbody class="disk_titles">
<% disk.disk_titles.sort_by { |d| movie.runtime_range.include?(d.duration) ? 0 : 1 }.each do |disk_title| %>
<%= hidden_field_tag "movies[][disk_title_id]", disk_title.id %>
<% text_class = 'text-primary-emphasis' if movie.runtime_range.include?(disk_title.duration) %>
<% text_class = 'text-success-emphasis' if movie.disk_titles.include?(disk_title) %>
<% text_class = 'text-success-emphasis' if movie.video_blobs.any? %>
<tr>
<th scope="row" class="<%= text_class %>"><%= disk_title.id %></th>
<td scope="row" class="<%= text_class %>"><%= disk_title.id %></td>
<td class="text-center">
<h1>
<% if movie.ripped_disk_titles.any? %>
<%= icon('square-check') %>
<% else %>
<%= icon('square') %>
<% end %>
</h1>
</td>
<td class="text-center">
<h1>
<% if disk_title.video_blob&.uploaded? %>
<%= icon('square-check') %>
<% else %>
<%= icon('square') %>
<% end %>
</h1>
</td>

<td class="<%= text_class %>">
<%= disk_title.name %>
<% if disk_title.video %>
(<%= disk_title.video&.title %>)
<% end %>
</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 %>">
<td class="<%= disk_title.size >= free_disk_space ? 'text-warn' : 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) %>
WARNING: There Might Not enough space available to rip, needs another <%= number_to_human_size(disk_title.size - free_disk_space, precision: 3) %>
<% end %>
</td>
<td class="<%= text_class %>">
<%= link_to 'Rip', rip_movie_path(movie, disk_title_id: disk_title.id), data: { turbo_method: :post }, class: 'btn btn-outline-light' %>

<%= select_tag "movies[][extra_type]", options_for_select(VideoBlob.extra_types.keys), prompt: "Extra Type" %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</tbody>
<div class='bg-dark w-100 fixed-bottom mt-1 text-right p-3 border-top'>
<%= f.button :submit, 'Rip Disk' %>
</div>
</table>
<% end %>
<% elsif LoadDiskWorker.job.active? %>
<p class="text-info">Stand by the disk is still being loading from the CD drive this could take a while. Page will update once the disk is ready so no need to refresh the page but if you do it won't hurt anything.</p>
<% else %>
Expand Down
1 change: 1 addition & 0 deletions app/components/movie_title_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class MovieTitleTableComponent < ViewComponent::Base
extend Dry::Initializer
include IconHelper

option :disks, Types::Coercible::Array.of(Types.Instance(Disk))
option :movie, Types.Instance(Movie)
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/config/make_mkvs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ def create
@config_make_mkv = Config::MakeMkv.new(make_mkv_params)

if @config_make_mkv.save
redirect_to root_path, notice: 'Make MKV Config was successfully created.'
redirect_to root_path, success: 'Make MKV Config was successfully created.'
else
flash.now[:error] = 'Could not create MKV Config'
render :new
end
end

def update
flash[:success] = 'Updated Make MKV' if @config_make_mkv.update(make_mkv_params)
redirect_to root_path
if @config_make_mkv.update(make_mkv_params)
flash[:success] = 'Updated Make MKV'
redirect_to root_path
else
flash.now[:error] = 'Could not update MKV Config'
render :edit
end
end

def install
Expand All @@ -42,7 +48,7 @@ def set_make_mkv
end

def make_mkv_params
params.require(:config_slack).permit(:settings_makemkvcon_path, :settings_registration_key)
params.require(:config_make_mkv).permit(:settings_makemkvcon_path, :settings_registration_key)
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/config/plexes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create
@config_plex = Config::Plex.new(config_plex_params)

if @config_plex.save
ScanPlexWorker.perform_async
redirect_to root_path, notice: 'Plex was successfully created.'
else
render :new
Expand All @@ -30,6 +31,7 @@ def create

def update
if @config_plex.update(config_plex_params)
ScanPlexWorker.perform_async
redirect_to root_path, notice: 'Plex was successfully updated.'
else
render :edit
Expand Down
26 changes: 23 additions & 3 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,29 @@ def show
# rip_movie POST /movies/:id/rip(.:format)
def rip
movie = Movie.find(params[:id])
disk_title = DiskTitle.find(params[:disk_title_id])
disk_title.update!(video: movie)
job = RipWorker.perform_async(disk_id: disk_title.disk.id, disk_title_ids: [disk_title.id])
disk = Disk.find(params[:disk_id])
disk_titles = rip_disk_titles(disk, movie)
job = RipWorker.perform_async(
disk_id: disk.id,
disk_title_ids: disk_titles.map(&:id),
extra_types: movies_params.pluck(:extra_type).compact_blank
)
redirect_to job_path(job)
end

private

def rip_disk_titles(disk, movie)
movies_params.filter_map do |movie_params|
next if movie_params[:extra_type].blank?

disk_title = disk.disk_titles.find(movie_params[:disk_title_id])
disk_title.update!(video: movie)
disk_title
end
end

def movies_params
params.required(:movies)
end
end
4 changes: 2 additions & 2 deletions app/listeners/the_movie_db/video_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

module TheMovieDb
class VideoListener
def tv_saving(tv)
def tv_validating(tv)
TheMovieDb::TvUpdateService.call(tv)
end

def movie_saving(movie)
def movie_validating(movie)
TheMovieDb::MovieUpdateService.call(movie)
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/listeners/upload_progress_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UploadProgressListener

delegate :render, to: :ApplicationController

option :disk_title, Types.Instance(::DiskTitle)
option :video_blob, Types.Instance(::VideoBlob)
option :file_size, Types::Integer
attr_reader :completed

Expand Down Expand Up @@ -63,13 +63,13 @@ def next_update
end

def title
if disk_title.video.is_a?(Tv)
episode = disk_title.episode
if video_blob.video.is_a?(Tv)
episode = video_blob.episode
season = episode.season
"#{disk_title.video.title} - S#{season.season_number}E#{episode.episode_number} " \
"#{video_blob.video.title} - S#{season.season_number}E#{episode.episode_number} " \
"#{episode.name}"
else
disk_title.video.title
video_blob.video.title
end
end
end
6 changes: 6 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

def unmark_for_destruction
return unless instance_variable_defined?(:@marked_for_destruction)

remove_instance_variable(:@marked_for_destruction)
end
end
10 changes: 10 additions & 0 deletions app/models/config/slack.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: configs
#
# id :integer not null, primary key
# settings :text
# type :string default("Config"), not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Config
class Slack < Config
setting do |s|
Expand Down
37 changes: 4 additions & 33 deletions app/models/disk_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# episode_id :integer
# mkv_progress_id :bigint
# title_id :integer not null
# video_blob_id :integer
# video_id :integer
#
# Indexes
Expand All @@ -23,6 +24,7 @@
# index_disk_titles_on_episode_id (episode_id)
# index_disk_titles_on_mkv_progress_id (mkv_progress_id)
# index_disk_titles_on_video (video_id)
# index_disk_titles_on_video_blob_id (video_blob_id)
#
class DiskTitle < ApplicationRecord
include ActionView::Helpers::DateHelper
Expand All @@ -31,6 +33,8 @@ class DiskTitle < ApplicationRecord
belongs_to :episode, optional: true
belongs_to :disk, optional: true

belongs_to :video_blob, optional: true

scope :not_ripped, -> { where(ripped_at: nil) }
scope :ripped, -> { where.not(ripped_at: nil) }

Expand All @@ -41,37 +45,4 @@ def duration
def to_label
"##{title_id} #{name} #{distance_of_time_in_words(duration)}"
end

def tmp_plex_path
require_movie_or_episode!
video.is_a?(Tv) ? episode.tmp_plex_path : video.tmp_plex_path
end

def plex_path
require_movie_or_episode!
video.is_a?(Tv) ? episode.plex_path : video.plex_path
end

def plex_name
require_movie_or_episode!
video.is_a?(Tv) ? episode.plex_name : video.plex_name
end

def tmp_plex_dir
require_movie_or_episode!
video.is_a?(Tv) ? episode.tmp_plex_dir : video.tmp_plex_dir
end

def tmp_plex_path_exists?
return false if video.nil?

video.is_a?(Tv) ? episode.tmp_plex_path_exists? : video.tmp_plex_path_exists?
end

def require_movie_or_episode!
return if video.is_a?(Movie)
return if video.is_a?(Tv) && episode

raise 'requires episode or movie to rip'
end
end
Loading

0 comments on commit 90773ef

Please sign in to comment.