Skip to content

Commit

Permalink
Import crew credits
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed May 14, 2021
1 parent a7d8b9d commit 13518de
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Trestle.resource(:credits) do
Trestle.resource(:acting_credits) do
form dialog: true do |credit|
row do
col(sm: 4) do
Expand Down
24 changes: 24 additions & 0 deletions app/admin/crew_credits_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Trestle.resource(:crew_credits) do
form dialog: true do |credit|
row do
col(sm: 4) do
form_group :profile, label: false do
link_to image_tag(credit.profile_url), credit.profile_url, data: { behavior: "zoom" }
end if credit.profile?
end

col(sm: 8) do
select :person_id, Person.alphabetical
text_field :job
end
end
end

table do
column :profile, header: false, align: :center, blank: nil do |credit|
avatar(fallback: credit.initials) { image_tag(credit.profile_url("w185")) if credit.profile? }
end
column :name, link: true
column :job, truncate: false
end
end
8 changes: 6 additions & 2 deletions app/admin/movies_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@
end
end

tab :acting_credits, badge: movie.acting_credits.count do
table CreditsAdmin.table, collection: movie.acting_credits.includes(:person)
tab :credits, badge: movie.acting_credits.count do
table ActingCreditsAdmin.table, collection: movie.acting_credits.includes(:person)
end

tab :crew, badge: movie.crew_credits.count do
table CrewCreditsAdmin.table, collection: movie.crew_credits.includes(:person)
end

tab :media, partial: "admin/shared/media", badge: movie.media_count
Expand Down
8 changes: 6 additions & 2 deletions app/admin/tv_shows_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@
end
end

tab :acting_credits, badge: tv_show.acting_credits.count do
table CreditsAdmin.table, collection: tv_show.acting_credits.includes(:person)
tab :credits, badge: tv_show.acting_credits.count do
table ActingCreditsAdmin.table, collection: tv_show.acting_credits.includes(:person)
end

tab :crew, badge: tv_show.crew_credits.count do
table CrewCreditsAdmin.table, collection: tv_show.crew_credits.includes(:person)
end

tab :seasons, badge: tv_show.seasons.count do
Expand Down
4 changes: 2 additions & 2 deletions app/importers/credits_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def initialize(base)

def import(tmdbs)
tmdbs.each do |tmdb|
actor = Actor.where(tmdb_id: tmdb.id).first_or_create!(name: tmdb.name, gender: tmdb.gender, profile_path: tmdb.profile_path)
@base.credits.create!(actor: actor, order: tmdb.order, character: tmdb.character)
person = Person.where(tmdb_id: tmdb.id).first_or_create!(name: tmdb.name, gender: tmdb.gender, profile_path: tmdb.profile_path)
@base.acting_credits.create!(person: person, order: tmdb.order, character: tmdb.character)
end
end
end
12 changes: 12 additions & 0 deletions app/importers/crew_importer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CrewImporter
def initialize(base)
@base = base
end

def import(tmdbs)
tmdbs.each do |tmdb|
person = Person.where(tmdb_id: tmdb.id).first_or_create!(name: tmdb.name, gender: tmdb.gender, profile_path: tmdb.profile_path)
@base.crew_credits.create!(person: person, job: tmdb.job)
end
end
end
5 changes: 5 additions & 0 deletions app/importers/tmdb_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def import
CreditsImporter.new(instance).import(credits)
}

threads << Thread.new {
crew = throttle { @scope.crew(stub.id) }
CrewImporter.new(instance).import(crew)
}

threads << Thread.new {
videos = throttle { @scope.videos(stub.id, language: "en") }
VideosImporter.new(instance).import(videos)
Expand Down
2 changes: 0 additions & 2 deletions app/models/actor.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/concerns/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Media

included do
has_many :acting_credits, -> { actors.ordered }, as: :media
has_many :crew_credits, -> { crew.ordered }, as: :media

has_many :videos, as: :media
has_many :images, as: :media
Expand Down
2 changes: 2 additions & 0 deletions app/models/credit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ class Credit < ApplicationRecord
belongs_to :person

scope :ordered, -> { order(order: :asc) }

scope :actors, -> { where(type: "ActingCredit") }
scope :crew, -> { where(type: "CrewCredit") }

delegate :name, :initials, :gender, :profile?, :profile_url, :profile_path, to: :person, allow_nil: true
end
3 changes: 3 additions & 0 deletions app/models/crew_credit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CrewCredit < Credit
alias_attribute :job, :role
end
5 changes: 5 additions & 0 deletions db/migrate/20210514120638_remove_type_column_from_people.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveTypeColumnFromPeople < ActiveRecord::Migration[5.2]
def change
remove_column :people, :type
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_05_14_114729) do
ActiveRecord::Schema.define(version: 2021_05_14_120638) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -105,7 +105,6 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.tsvector "tsv"
t.string "type"
t.index ["name"], name: "index_people_on_name"
t.index ["tsv"], name: "index_people_on_tsv", using: :gin
end
Expand Down

0 comments on commit 13518de

Please sign in to comment.