[Enhancement] Use cookies on a per-source basis (#354)
* Added 'use_cookies' column to source * Added cookies to the source form * Updated every command to optionally include cookies * LOTS of tests * Made YT cookies off by default
This commit is contained in:
1 parent
23492961d5
commit
fd20ac5d84
26 files changed
+482
-193
No files matched your search
@@ -85,7 +85,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
|
||||
describe "create_source/2" do
|
||||
test "automatically sets the UUID" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -97,7 +97,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "UUID is not writable by the user" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -110,7 +110,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creates a source and adds name + ID from runner response for channels" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -123,7 +123,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creates a source and adds name + ID for playlists" do
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -136,7 +136,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "adds an error if the runner fails" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:error, "some error", 1} end)
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl -> {:error, "some error", 1} end)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -148,7 +148,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "you can specify a custom custom_name" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -162,7 +162,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "friendly name is pulled from collection_name if not specified" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -175,7 +175,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creation enforces uniqueness of collection_id scoped to the media_profile and title regex" do
|
||||
expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot ->
|
||||
expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot, _addl ->
|
||||
{:ok,
|
||||
Phoenix.json_library().encode!(%{
|
||||
channel: "some channel name",
|
||||
@@ -196,7 +196,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creation lets you duplicate collection_ids and profiles as long as the regex is different" do
|
||||
expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot ->
|
||||
expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot, _addl ->
|
||||
{:ok,
|
||||
Phoenix.json_library().encode!(%{
|
||||
channel: "some channel name",
|
||||
@@ -220,7 +220,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creation lets you duplicate collection_ids as long as the media profile is different" do
|
||||
expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot ->
|
||||
expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot, _addl ->
|
||||
{:ok,
|
||||
Phoenix.json_library().encode!(%{
|
||||
channel: "some channel name",
|
||||
@@ -244,8 +244,8 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "collection_type is inferred from source details" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -264,13 +264,13 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creation with invalid data fails fast and does not call the runner" do
|
||||
expect(YtDlpRunnerMock, :run, 0, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, 0, &channel_mock/4)
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} = Sources.create_source(@invalid_source_attrs)
|
||||
end
|
||||
|
||||
test "creation will schedule the indexing task" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -283,7 +283,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creation schedules an index test even if the index frequency is 0" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -297,7 +297,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "fast_index forces the index frequency to be a default value" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -312,7 +312,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "disabling fast index will not change the index frequency" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -327,7 +327,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "creating will kickoff a metadata storage worker" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -344,7 +344,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
|
||||
describe "create_source/2 when testing options" do
|
||||
test "run_post_commit_tasks: false won't enqueue post-commit tasks" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
valid_attrs = %{
|
||||
media_profile_id: media_profile_fixture().id,
|
||||
@@ -368,7 +368,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "updates with invalid data fails fast and does not call the runner" do
|
||||
expect(YtDlpRunnerMock, :run, 0, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, 0, &channel_mock/4)
|
||||
|
||||
source = source_fixture()
|
||||
|
||||
@@ -376,7 +376,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "updating the original_url will re-fetch the source details for channels" do
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &channel_mock/4)
|
||||
|
||||
source = source_fixture()
|
||||
update_attrs = %{original_url: "https://www.youtube.com/channel/abc123"}
|
||||
@@ -387,7 +387,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "updating the original_url will re-fetch the source details for playlists" do
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/4)
|
||||
|
||||
source = source_fixture()
|
||||
update_attrs = %{original_url: "https://www.youtube.com/playlist?list=abc123"}
|
||||
@@ -398,7 +398,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "not updating the original_url will not re-fetch the source details" do
|
||||
expect(YtDlpRunnerMock, :run, 0, &channel_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, 0, &channel_mock/4)
|
||||
|
||||
source = source_fixture()
|
||||
update_attrs = %{name: "some updated name"}
|
||||
@@ -519,7 +519,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
|
||||
test "updating will kickoff a metadata storage worker if the original_url changes" do
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/3)
|
||||
expect(YtDlpRunnerMock, :run, &playlist_mock/4)
|
||||
source = source_fixture()
|
||||
update_attrs = %{original_url: "https://www.youtube.com/channel/cba321"}
|
||||
|
||||
@@ -736,7 +736,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
end
|
||||
end
|
||||
|
||||
defp playlist_mock(_url, _opts, _ot) do
|
||||
defp playlist_mock(_url, _opts, _ot, _addl) do
|
||||
{
|
||||
:ok,
|
||||
Phoenix.json_library().encode!(%{
|
||||
@@ -748,7 +748,7 @@ defmodule Pinchflat.SourcesTest do
|
||||
}
|
||||
end
|
||||
|
||||
defp channel_mock(_url, _opts, _ot) do
|
||||
defp channel_mock(_url, _opts, _ot, _addl) do
|
||||
channel_id = "some_channel_id_#{:rand.uniform(1_000_000)}"
|
||||
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user