Skip to content

Commit

Permalink
Updated video downloader to use full URL; improved docs (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieraneglin authored Feb 22, 2024
1 parent ebebbf7 commit 2ca395a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
28 changes: 15 additions & 13 deletions lib/pinchflat/media/media_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ defmodule Pinchflat.Media.MediaItem do
alias Pinchflat.Media.MediaMetadata
alias Pinchflat.Media.MediaItemSearchIndex

@allowed_fields ~w(
title
media_id
description
original_url
livestream
media_downloaded_at
media_filepath
subtitle_filepaths
thumbnail_filepath
metadata_filepath
source_id
)a
@allowed_fields [
# these fields are captured on indexing
:title,
:media_id,
:description,
:original_url,
:livestream,
:source_id,
# these fields are captured on download
:media_downloaded_at,
:media_filepath,
:subtitle_filepaths,
:thumbnail_filepath,
:metadata_filepath
]
@required_fields ~w(title original_url livestream media_id source_id)a

schema "media_items" do
Expand Down
2 changes: 1 addition & 1 deletion lib/pinchflat/media_client/video_downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Pinchflat.MediaClient.VideoDownloader do
item_with_preloads = Repo.preload(media_item, [:metadata, source: :media_profile])
media_profile = item_with_preloads.source.media_profile

case download_for_media_profile(media_item.media_id, media_profile, backend) do
case download_for_media_profile(media_item.original_url, media_profile, backend) do
{:ok, parsed_json} ->
parser = metadata_parser(backend)

Expand Down
3 changes: 2 additions & 1 deletion test/pinchflat/media_client/video_downloader_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule Pinchflat.MediaClient.VideoDownloaderTest do

describe "download_for_media_item/3" do
test "it calls the backend runner", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, fn _url, _opts, ot ->
expect(YtDlpRunnerMock, :run, fn url, _opts, ot ->
assert url == media_item.original_url
assert ot == "after_move:%()j"

{:ok, render_metadata(:media_metadata)}
Expand Down
6 changes: 4 additions & 2 deletions test/support/fixtures/media_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ defmodule Pinchflat.MediaFixtures do
Generate a media_item.
"""
def media_item_fixture(attrs \\ %{}) do
media_id = Faker.String.base64(12)

{:ok, media_item} =
attrs
|> Enum.into(%{
media_id: Faker.String.base64(12),
media_id: media_id,
title: Faker.Commerce.product_name(),
original_url: "https://www.youtube.com/channel/#{Faker.String.base64(12)}",
original_url: "https://www.youtube.com/watch?v=#{media_id}",
livestream: false,
media_filepath: "/video/#{Faker.File.file_name(:video)}",
source_id: SourcesFixtures.source_fixture().id
Expand Down

0 comments on commit 2ca395a

Please sign in to comment.