[Enhancement] Start tracking a media item's duration (#146)
* Added duration field, started importing it during indexing and download * Added duration to RSS feed
This commit is contained in:
@@ -35,7 +35,7 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||
assert {:ok, _} = MediaDownloader.download_for_media_item(media_item)
|
||||
end
|
||||
|
||||
test "it saves the metadata filepatha to the database", %{media_item: media_item} do
|
||||
test "it saves the metadata filepath to the database", %{media_item: media_item} do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
{:ok, render_metadata(:media_metadata)}
|
||||
end)
|
||||
@@ -93,6 +93,12 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||
assert [["de", _], ["en", _] | _rest] = updated_media_item.subtitle_filepaths
|
||||
end
|
||||
|
||||
test "it extracts the duration_seconds", %{media_item: media_item} do
|
||||
assert media_item.duration_seconds == nil
|
||||
assert {:ok, updated_media_item} = MediaDownloader.download_for_media_item(media_item)
|
||||
assert is_integer(updated_media_item.duration_seconds)
|
||||
end
|
||||
|
||||
test "it extracts the thumbnail_filepath", %{media_item: media_item} do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
metadata = render_parsed_metadata(:media_metadata)
|
||||
|
||||
@@ -45,6 +45,12 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
|
||||
|
||||
assert result.livestream == metadata["was_live"]
|
||||
end
|
||||
|
||||
test "it extracts the duration in seconds", %{metadata: metadata} do
|
||||
result = Parser.parse_for_media_item(metadata)
|
||||
|
||||
assert result.duration_seconds == round(metadata["duration"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "parse_for_media_item/1 when testing subtitle metadata" do
|
||||
|
||||
@@ -104,7 +104,8 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
original_url: "https://www.youtube.com/watch?v=TiZPUDkDYbk",
|
||||
livestream: false,
|
||||
short_form_content: false,
|
||||
upload_date: Date.from_iso8601!("2021-01-01")
|
||||
upload_date: Date.from_iso8601!("2021-01-01"),
|
||||
duration_seconds: 60
|
||||
} == Media.response_to_struct(response)
|
||||
end
|
||||
|
||||
@@ -174,5 +175,27 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
|
||||
assert %Media{upload_date: nil} = Media.response_to_struct(response)
|
||||
end
|
||||
|
||||
test "parses the duration" do
|
||||
response = %{
|
||||
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
|
||||
"aspect_ratio" => 1.0,
|
||||
"duration" => 60.4,
|
||||
"upload_date" => "20210101"
|
||||
}
|
||||
|
||||
assert %Media{duration_seconds: 60} = Media.response_to_struct(response)
|
||||
end
|
||||
|
||||
test "doesn't blow up if duration is missing" do
|
||||
response = %{
|
||||
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
|
||||
"aspect_ratio" => 1.0,
|
||||
"duration" => nil,
|
||||
"upload_date" => "20210101"
|
||||
}
|
||||
|
||||
assert %Media{duration_seconds: nil} = Media.response_to_struct(response)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user