From a6c61ccd0d4134ac836d36e83cd220ab89e21d4f Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 20 Aug 2024 09:37:42 -0700 Subject: [PATCH] [Bugfix] Improve livestream detection (#362) * Livestream status is now based off live_status instead of was_live * Updated tests --- lib/pinchflat/yt_dlp/media.ex | 4 ++-- .../fast_indexing/fast_indexing_helpers_test.exs | 2 +- test/pinchflat/metadata/metadata_parser_test.exs | 5 +++-- .../slow_indexing/slow_indexing_helpers_test.exs | 4 ++-- test/pinchflat/yt_dlp/media_test.exs | 8 +++++--- test/support/fixtures/media_fixtures.ex | 2 +- test/support/fixtures/sources_fixtures.ex | 6 +++--- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/pinchflat/yt_dlp/media.ex b/lib/pinchflat/yt_dlp/media.ex index 5cb3fdc..65258ae 100644 --- a/lib/pinchflat/yt_dlp/media.ex +++ b/lib/pinchflat/yt_dlp/media.ex @@ -89,7 +89,7 @@ defmodule Pinchflat.YtDlp.Media do NOTE: playlist_index is really only useful for playlists that will never change their order. """ def indexing_output_template do - "%(.{id,title,was_live,webpage_url,description,aspect_ratio,duration,upload_date,timestamp,playlist_index})j" + "%(.{id,title,live_status,webpage_url,description,aspect_ratio,duration,upload_date,timestamp,playlist_index})j" end @doc """ @@ -104,7 +104,7 @@ defmodule Pinchflat.YtDlp.Media do title: response["title"], description: response["description"], original_url: response["webpage_url"], - livestream: !!response["was_live"], + livestream: !!response["live_status"] && response["live_status"] != "not_live", duration_seconds: response["duration"] && round(response["duration"]), short_form_content: response["webpage_url"] && short_form_content?(response), uploaded_at: response["upload_date"] && parse_uploaded_at(response), diff --git a/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs b/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs index 788173d..3c9aa1f 100644 --- a/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs +++ b/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs @@ -101,7 +101,7 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpersTest do id: "video2", title: "Video 2", webpage_url: "https://example.com/shorts/video2", - was_live: true, + live_status: "is_live", description: "desc2", aspect_ratio: 1.67, duration: 345.67, diff --git a/test/pinchflat/metadata/metadata_parser_test.exs b/test/pinchflat/metadata/metadata_parser_test.exs index 48015b1..c3eca80 100644 --- a/test/pinchflat/metadata/metadata_parser_test.exs +++ b/test/pinchflat/metadata/metadata_parser_test.exs @@ -43,11 +43,12 @@ defmodule Pinchflat.Metadata.MetadataParserTest do test "it extracts the livestream flag", %{metadata: metadata} do result = Parser.parse_for_media_item(metadata) - assert result.livestream == metadata["was_live"] + assert metadata["live_status"] == "not_live" + refute result.livestream end test "the livestream flag defaults to false", %{metadata: metadata} do - metadata = Map.put(metadata, "was_live", nil) + metadata = Map.put(metadata, "live_status", nil) result = Parser.parse_for_media_item(metadata) diff --git a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs index b4391ba..cca56c1 100644 --- a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs +++ b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs @@ -173,7 +173,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do Phoenix.json_library().encode!(%{ id: "video3", title: "Video 3", - was_live: false, + live_status: "not_live", description: "desc3", # Only focusing on these because these are passed to functions that # could fail if they're not present @@ -289,7 +289,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do id: "video2", title: "Video 2", webpage_url: "https://example.com/shorts/video2", - was_live: true, + live_status: "is_live", description: "desc2", aspect_ratio: 1.67, duration: 345.67, diff --git a/test/pinchflat/yt_dlp/media_test.exs b/test/pinchflat/yt_dlp/media_test.exs index e2b51ba..680593c 100644 --- a/test/pinchflat/yt_dlp/media_test.exs +++ b/test/pinchflat/yt_dlp/media_test.exs @@ -138,7 +138,9 @@ defmodule Pinchflat.YtDlp.MediaTest do describe "indexing_output_template/0" do test "contains all the greatest hits" do - attrs = ~w(id title was_live webpage_url description aspect_ratio duration upload_date timestamp playlist_index)a + attrs = + ~w(id title live_status 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() @@ -152,7 +154,7 @@ defmodule Pinchflat.YtDlp.MediaTest do "title" => "Trying to Wheelie Without the Rear Brake", "description" => "I'm not sure what I expected.", "webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk", - "was_live" => false, + "live_status" => "not_live", "aspect_ratio" => 1.0, "duration" => 60, "upload_date" => "20210101", @@ -239,7 +241,7 @@ defmodule Pinchflat.YtDlp.MediaTest do assert %Media{duration_seconds: nil} = Media.response_to_struct(response) end - test "sets livestream to false if the was_live field isn't present" do + test "sets livestream to false if the live_status field isn't present" do response = %{ "webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk", "aspect_ratio" => 1.0, diff --git a/test/support/fixtures/media_fixtures.ex b/test/support/fixtures/media_fixtures.ex index c78a09a..dacddb3 100644 --- a/test/support/fixtures/media_fixtures.ex +++ b/test/support/fixtures/media_fixtures.ex @@ -93,7 +93,7 @@ defmodule Pinchflat.MediaFixtures do id: "video1", title: "Video 1", webpage_url: "https://example.com/video1", - was_live: false, + live_status: "not_live", description: "desc1", aspect_ratio: 1.67, duration: 123.45, diff --git a/test/support/fixtures/sources_fixtures.ex b/test/support/fixtures/sources_fixtures.ex index a06329a..210587f 100644 --- a/test/support/fixtures/sources_fixtures.ex +++ b/test/support/fixtures/sources_fixtures.ex @@ -81,7 +81,7 @@ defmodule Pinchflat.SourcesFixtures do id: "video1", title: "Video 1", webpage_url: "https://example.com/video1", - was_live: false, + live_status: "not_live", description: "desc1", aspect_ratio: 1.67, duration: 12.34, @@ -91,7 +91,7 @@ defmodule Pinchflat.SourcesFixtures do id: "video2", title: "Video 2", webpage_url: "https://example.com/video2", - was_live: true, + live_status: "is_live", description: "desc2", aspect_ratio: 1.67, duration: 345.67, @@ -101,7 +101,7 @@ defmodule Pinchflat.SourcesFixtures do id: "video3", title: "Video 3", webpage_url: "https://example.com/video3", - was_live: false, + live_status: "not_live", description: "desc3", aspect_ratio: 1.0, duration: 678.90,