Skip to content

Commit

Permalink
feat: Upload captions
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Nov 4, 2024
1 parent 7b6e999 commit 5d8b0c5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
14 changes: 14 additions & 0 deletions apps/cf/lib/actions/action_creator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule CF.Actions.ActionCreator do
alias DB.Schema.Speaker
alias DB.Schema.Statement
alias DB.Schema.Comment
alias DB.Schema.VideoCaption
alias CF.Actions.ReputationChange

# Create
Expand Down Expand Up @@ -175,6 +176,19 @@ defmodule CF.Actions.ActionCreator do
)
end

def action_upload_video_captions(user_id, video_id, caption = %VideoCaption{}) do
action(
user_id,
:video_caption,
:upload,
video_id: video_id,
changes: %{
"format" => caption.format,
"parsed" => caption.parsed
}
)
end

def action_revert_vote(user_id, video_id, vote_type, comment = %Comment{})
when vote_type in [:revert_vote_up, :revert_vote_down, :revert_self_vote] do
action(
Expand Down
28 changes: 28 additions & 0 deletions apps/cf_graphql/lib/resolvers/videos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,32 @@ defmodule CF.Graphql.Resolvers.Videos do
CF.LLMs.StatementsCreator.process_video!(video.id)
{:ok, video}
end

def set_captions(_root, %{video_id: video_id, captions: captions_input}, %{
context: %{user: user}
}) do
video = DB.Repo.get!(DB.Schema.Video, video_id)

Multi.new()
|> Multi.insert(
:caption,
VideoCaption.changeset(%VideoCaption{
video_id: video.id,
raw: captions_input,
parsed: captions_input,
format: "user-provided"
})
)
|> Multi.run(
:action,
fn _repo, %{caption: caption} ->
CF.Actions.ActionCreator.action_upload_video_captions(user.id, video.id, caption)
|> DB.Repo.insert!()

{:ok, caption}
end
)

{:ok, video}
end
end
3 changes: 2 additions & 1 deletion apps/cf_graphql/lib/schema/input_objects.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule CF.Graphql.Schema.InputObjects do

import_types(CF.Graphql.Schema.InputObjects.{
VideoFilter,
StatementFilter
StatementFilter,
VideoCaption
})
end
10 changes: 10 additions & 0 deletions apps/cf_graphql/lib/schema/input_objects/video_caption.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule CF.Graphql.Schema.InputObjects.VideoCaption do
use Absinthe.Schema.Notation
use Absinthe.Ecto, repo: DB.Repo

input_object :video_caption_input do
field(:text, non_null(:string))
field(:start, non_null(:float))
field(:duration, :float)
end
end
10 changes: 10 additions & 0 deletions apps/cf_graphql/lib/schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,15 @@ defmodule CF.Graphql.Schema do

resolve(&Resolvers.Videos.start_automatic_statements_extraction/3)
end

field :set_video_captions, :video do
middleware(Middleware.RequireAuthentication)
middleware(Middleware.RequireReputation, 450)

arg(:video_id, non_null(:id))
arg(:captions, non_null(list_of(:video_caption_input)))

resolve(&Resolvers.Videos.set_captions/3)
end
end
end
12 changes: 6 additions & 6 deletions apps/cf_jobs/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ config :cf_jobs, CF.Jobs.Scheduler,
overlap: false
],
# Captions
download_captions: [
# every minute
schedule: "*/1 * * * *",
task: {CF.Jobs.DownloadCaptions, :update, []},
overlap: false
]
# download_captions: [
# # every hour
# schedule: "@hourly",
# task: {CF.Jobs.DownloadCaptions, :update, []},
# overlap: false
# ]
]

# Configure Postgres pool size
Expand Down

0 comments on commit 5d8b0c5

Please sign in to comment.