From 07ad59ea81c68c3cc20df1f906e0c9fbdd92dfb0 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 7 Nov 2024 11:51:42 -0800 Subject: [PATCH] WIP added ability to predict filepath to source indexing --- .../downloading/download_option_builder.ex | 15 +++++++++++++-- .../slow_indexing/slow_indexing_helpers.ex | 12 +++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/pinchflat/downloading/download_option_builder.ex b/lib/pinchflat/downloading/download_option_builder.ex index 333d1d5..b6a71df 100644 --- a/lib/pinchflat/downloading/download_option_builder.ex +++ b/lib/pinchflat/downloading/download_option_builder.ex @@ -41,14 +41,25 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do Returns binary() """ + def build_output_path_for(%Source{} = source_with_preloads) do + build_output_path_for(%MediaItem{source: source_with_preloads}) + end + def build_output_path_for(%MediaItem{} = media_item_with_preloads) do output_path_template = Sources.output_path_template(media_item_with_preloads.source) build_output_path(output_path_template, media_item_with_preloads) end - def build_output_path_for(%Source{} = source_with_preloads) do - build_output_path_for(%MediaItem{source: source_with_preloads}) + # TODO: test + def build_quality_options_for(%Source{} = source_with_preloads) do + build_quality_options_for(%MediaItem{source: source_with_preloads}) + end + + def build_quality_options_for(%MediaItem{} = media_item_with_preloads) do + media_profile = media_item_with_preloads.source.media_profile + + quality_options(media_profile) end defp default_options(override_opts) do diff --git a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex index b2b4432..06d84d0 100644 --- a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex +++ b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex @@ -16,6 +16,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do alias Pinchflat.YtDlp.MediaCollection alias Pinchflat.Downloading.DownloadingHelpers alias Pinchflat.SlowIndexing.FileFollowerServer + alias Pinchflat.Downloading.DownloadOptionBuilder alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker alias Pinchflat.YtDlp.Media, as: YtDlpMedia @@ -56,6 +57,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do Returns [%MediaItem{} | %Ecto.Changeset{}] """ def index_and_enqueue_download_for_media_items(%Source{} = source) do + # The media_profile is needed to determine the quality options to _then_ determine a more + # accurate predicted filepath + source = Repo.preload(source, [:media_profile]) # See the method definition below for more info on how file watchers work # (important reading if you're not familiar with it) {:ok, media_attributes} = setup_file_watcher_and_kickoff_indexing(source) @@ -94,8 +98,14 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do {:ok, pid} = FileFollowerServer.start_link() handler = fn filepath -> setup_file_follower_watcher(pid, filepath, source) end + + # TODO: test + command_opts = + [output: DownloadOptionBuilder.build_output_path_for(source)] ++ + DownloadOptionBuilder.build_quality_options_for(source) + runner_opts = [file_listener_handler: handler, use_cookies: source.use_cookies] - result = MediaCollection.get_media_attributes_for_collection(source.original_url, [], runner_opts) + result = MediaCollection.get_media_attributes_for_collection(source.original_url, command_opts, runner_opts) FileFollowerServer.stop(pid)