Redo indexing mechanism (#16)
* Bumped up the line length because I fear no man * Refactored indexing Previously, indexing worked by collecting the video IDs of only videos that matched indexing criteria. This new model instead stores ALL videos for a given source, but will only _download_ videos that meet that criteria. This lets us backfill without indexing, makes it easier to add in other backends, lets us download one-off videos for a source that don't quite meet criteria, you name it. * Updated media finders to respect format filters; Added credo file
This commit is contained in:
@@ -3,6 +3,7 @@ defmodule Pinchflat.MediaTest do
|
||||
|
||||
import Pinchflat.TasksFixtures
|
||||
import Pinchflat.MediaFixtures
|
||||
import Pinchflat.ProfilesFixtures
|
||||
import Pinchflat.MediaSourceFixtures
|
||||
|
||||
alias Pinchflat.Media
|
||||
@@ -30,7 +31,7 @@ defmodule Pinchflat.MediaTest do
|
||||
end
|
||||
|
||||
describe "list_pending_media_items_for/1" do
|
||||
test "it returns pending media_items for a given source" do
|
||||
test "it returns pending without a filepath for a given source" do
|
||||
source = source_fixture()
|
||||
media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
|
||||
@@ -50,6 +51,138 @@ defmodule Pinchflat.MediaTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_pending_media_items_for/1 when testing shorts" do
|
||||
test "returns shorts and normal media when shorts_behaviour is :include" do
|
||||
source = source_fixture(%{media_profile_id: media_profile_fixture(%{shorts_behaviour: :include}).id})
|
||||
normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [normal, short]
|
||||
end
|
||||
|
||||
test "returns only shorts when shorts_behaviour is :only" do
|
||||
source = source_fixture(%{media_profile_id: media_profile_fixture(%{shorts_behaviour: :only}).id})
|
||||
_normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [short]
|
||||
end
|
||||
|
||||
test "returns only normal media when shorts_behaviour is :exclude" do
|
||||
source = source_fixture(%{media_profile_id: media_profile_fixture(%{shorts_behaviour: :exclude}).id})
|
||||
normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
_short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [normal]
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_pending_media_items_for/1 when testing livestreams" do
|
||||
test "returns livestreams and normal media when livestream_behaviour is :include" do
|
||||
source = source_fixture(%{media_profile_id: media_profile_fixture(%{livestream_behaviour: :include}).id})
|
||||
normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [normal, livestream]
|
||||
end
|
||||
|
||||
test "returns only livestreams when livestream_behaviour is :only" do
|
||||
source = source_fixture(%{media_profile_id: media_profile_fixture(%{livestream_behaviour: :only}).id})
|
||||
_normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [livestream]
|
||||
end
|
||||
|
||||
test "returns only normal media when livestream_behaviour is :exclude" do
|
||||
source = source_fixture(%{media_profile_id: media_profile_fixture(%{livestream_behaviour: :exclude}).id})
|
||||
normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
_livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [normal]
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_pending_media_items_for/1 when testing all format options" do
|
||||
test "returns livestreams, shorts, and normal media when behaviour is :include" do
|
||||
source =
|
||||
source_fixture(%{
|
||||
media_profile_id:
|
||||
media_profile_fixture(%{
|
||||
shorts_behaviour: :include,
|
||||
livestream_behaviour: :include
|
||||
}).id
|
||||
})
|
||||
|
||||
normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [normal, livestream, short]
|
||||
end
|
||||
|
||||
test "returns only livestreams and shorts when behaviour is :only" do
|
||||
source =
|
||||
source_fixture(%{
|
||||
media_profile_id:
|
||||
media_profile_fixture(%{
|
||||
shorts_behaviour: :only,
|
||||
livestream_behaviour: :only
|
||||
}).id
|
||||
})
|
||||
|
||||
_normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [livestream, short]
|
||||
end
|
||||
|
||||
test "returns only normal media when behaviour is :exclude" do
|
||||
source =
|
||||
source_fixture(%{
|
||||
media_profile_id:
|
||||
media_profile_fixture(%{
|
||||
shorts_behaviour: :exclude,
|
||||
livestream_behaviour: :exclude
|
||||
}).id
|
||||
})
|
||||
|
||||
normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
_livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
_short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [normal]
|
||||
end
|
||||
|
||||
test ":only and :exclude return the expected results" do
|
||||
source =
|
||||
source_fixture(%{
|
||||
media_profile_id:
|
||||
media_profile_fixture(%{
|
||||
shorts_behaviour: :only,
|
||||
livestream_behaviour: :exclude
|
||||
}).id
|
||||
})
|
||||
|
||||
_normal = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
_livestream = media_item_fixture(%{source_id: source.id, media_filepath: nil, livestream: true})
|
||||
short = media_item_fixture(%{source_id: source.id, media_filepath: nil, original_url: "/shorts/"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [short]
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_downloaded_media_items_for/1" do
|
||||
test "returns only media items with a media_filepath" do
|
||||
source = source_fixture()
|
||||
_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
media_item = media_item_fixture(%{source_id: source.id, media_filepath: "/video/#{Faker.File.file_name(:video)}"})
|
||||
|
||||
assert Media.list_downloaded_media_items_for(source) == [media_item]
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_media_item!/1" do
|
||||
test "it returns the media_item with given id" do
|
||||
media_item = media_item_fixture()
|
||||
@@ -63,7 +196,8 @@ defmodule Pinchflat.MediaTest do
|
||||
media_id: Faker.String.base64(12),
|
||||
title: Faker.Commerce.product_name(),
|
||||
media_filepath: "/video/#{Faker.File.file_name(:video)}",
|
||||
source_id: source_fixture().id
|
||||
source_id: source_fixture().id,
|
||||
original_url: "https://www.youtube.com/channel/#{Faker.String.base64(12)}"
|
||||
}
|
||||
|
||||
assert {:ok, %MediaItem{} = media_item} = Media.create_media_item(valid_attrs)
|
||||
|
||||
Reference in New Issue
Block a user