From ae7347e3cf2d56d12aad5a4dbdd90bd3910fc320 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Thu, 7 Nov 2024 11:55:33 -0800 Subject: [PATCH] Added the ability to predict filepath when fast indexing --- lib/pinchflat/fast_indexing/fast_indexing_helpers.ex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex b/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex index 292cfdb..c4a26e8 100644 --- a/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex +++ b/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex @@ -15,6 +15,7 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpers do alias Pinchflat.FastIndexing.YoutubeRss alias Pinchflat.FastIndexing.YoutubeApi alias Pinchflat.Downloading.DownloadingHelpers + alias Pinchflat.Downloading.DownloadOptionBuilder alias Pinchflat.YtDlp.Media, as: YtDlpMedia @@ -27,6 +28,10 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpers do downloaded_. """ def kickoff_download_tasks_from_youtube_rss_feed(%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]) + {:ok, media_ids} = get_recent_media_ids(source) existing_media_items = list_media_items_by_media_id_for(source, media_ids) new_media_ids = media_ids -- Enum.map(existing_media_items, & &1.media_id) @@ -67,8 +72,12 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpers do defp create_media_item_from_media_id(source, media_id) do url = "https://www.youtube.com/watch?v=#{media_id}" + # TODO: test + command_opts = + [output: DownloadOptionBuilder.build_output_path_for(source)] ++ + DownloadOptionBuilder.build_quality_options_for(source) - case YtDlpMedia.get_media_attributes(url, [], use_cookies: source.use_cookies) do + case YtDlpMedia.get_media_attributes(url, command_opts, use_cookies: source.use_cookies) do {:ok, media_attrs} -> Media.create_media_item_from_backend_attrs(source, media_attrs)