[Enhancement] Capture playlist_index for use with output templates (#315)
* Started capturing playlist_index on indexing pass * Added playlist_index as a media item field * Added playlist index to output variable templates * Improved the way playlist_indexes are rejected on update * Updated docs * Undid unneeded changes
This commit is contained in:
@@ -689,7 +689,24 @@ defmodule Pinchflat.MediaTest do
|
||||
assert {:ok, %MediaItem{} = media_item_2} = Media.create_media_item_from_backend_attrs(source, different_attrs)
|
||||
|
||||
assert media_item_1.id == media_item_2.id
|
||||
assert media_item_2.title == different_attrs.title
|
||||
assert Repo.reload(media_item_2).title == different_attrs.title
|
||||
end
|
||||
|
||||
test "doesn't update fields like playlist_index" do
|
||||
source = source_fixture()
|
||||
|
||||
media_attrs =
|
||||
media_attributes_return_fixture()
|
||||
|> Phoenix.json_library().decode!()
|
||||
|> Map.put("playlist_index", 1)
|
||||
|> YtDlpMedia.response_to_struct()
|
||||
|
||||
different_attrs = %YtDlpMedia{media_attrs | playlist_index: 9999}
|
||||
|
||||
assert {:ok, %MediaItem{} = _media_item_1} = Media.create_media_item_from_backend_attrs(source, media_attrs)
|
||||
assert {:ok, %MediaItem{} = media_item_2} = Media.create_media_item_from_backend_attrs(source, different_attrs)
|
||||
|
||||
assert Repo.reload(media_item_2).playlist_index == media_attrs.playlist_index
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -110,8 +110,10 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
|
||||
describe "indexing_output_template/0" do
|
||||
test "contains all the greatest hits" do
|
||||
assert "%(.{id,title,was_live,webpage_url,description,aspect_ratio,duration,upload_date,timestamp})j" ==
|
||||
Media.indexing_output_template()
|
||||
attrs = ~w(id title was_live webpage_url description aspect_ratio duration upload_date timestamp playlist_index)a
|
||||
formatted_attrs = "%(.{#{Enum.join(attrs, ",")}})j"
|
||||
|
||||
assert formatted_attrs == Media.indexing_output_template()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -126,7 +128,8 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
"aspect_ratio" => 1.0,
|
||||
"duration" => 60,
|
||||
"upload_date" => "20210101",
|
||||
"timestamp" => 1_600_000_000
|
||||
"timestamp" => 1_600_000_000,
|
||||
"playlist_index" => 1
|
||||
}
|
||||
|
||||
assert %Media{
|
||||
@@ -137,7 +140,8 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
livestream: false,
|
||||
short_form_content: false,
|
||||
uploaded_at: ~U[2020-09-13 12:26:40Z],
|
||||
duration_seconds: 60
|
||||
duration_seconds: 60,
|
||||
playlist_index: 1
|
||||
} == Media.response_to_struct(response)
|
||||
end
|
||||
|
||||
@@ -217,6 +221,17 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
|
||||
assert %Media{livestream: false} = Media.response_to_struct(response)
|
||||
end
|
||||
|
||||
test "doesn't blow up if playlist_index is missing" do
|
||||
response = %{
|
||||
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
|
||||
"aspect_ratio" => 1.0,
|
||||
"duration" => nil,
|
||||
"upload_date" => "20210101"
|
||||
}
|
||||
|
||||
assert %Media{playlist_index: 0} = Media.response_to_struct(response)
|
||||
end
|
||||
end
|
||||
|
||||
describe "response_to_struct/1 when testing uploaded_at" do
|
||||
|
||||
Reference in New Issue
Block a user