Add IMDB ID to movies
This commit is contained in:
27
slices/admin/commands/movies/create.rb
Normal file
27
slices/admin/commands/movies/create.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require "down"
|
||||
|
||||
module Admin
|
||||
module Commands
|
||||
module Movies
|
||||
class Create
|
||||
|
||||
include Deps["repos.movie_repo"]
|
||||
|
||||
def call(movie)
|
||||
repo = Adamantium::Container["repos.movie_repo"]
|
||||
|
||||
next if repo.by_title_and_year(title: title, year: activity.year)
|
||||
|
||||
page = Down.download(activity.film_link)
|
||||
match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/)
|
||||
imdb_id = match[1]
|
||||
|
||||
movie = movie.merge(imdb_id: imdb_id) if imdb_id
|
||||
|
||||
repo.create(movie)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
slices/admin/repos/movie_repo.rb
Normal file
19
slices/admin/repos/movie_repo.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Admin
|
||||
module Repos
|
||||
class MovieRepo < Adamantium::Repo[:movies]
|
||||
commands :create
|
||||
|
||||
def by_title_and_year(title:, year:)
|
||||
movies.where(title: title, year: year).one
|
||||
end
|
||||
|
||||
def listing
|
||||
movies.order(Sequel.lit("year desc")).to_a
|
||||
end
|
||||
|
||||
def update(id, attrs)
|
||||
movies.where(id: id).update(attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user