[Enhancement] Track the predicted final filepath for indexed media items (#461)
* Added ability to pass additional yt-dlp options to indexing step * Added predicted_filename to media struct * WIP added ability to predict filepath to source indexing * renamed predicted_filepath * Added the ability to predict filepath when fast indexing * Add predicted_media_filepath to media items table * Addressed TODOs
This commit is contained in:
1 parent
8c0dd0bb6b
commit
83c10b2b00
13 files changed
+134
-21
No files matched your search
@@ -11,7 +11,8 @@ defmodule Pinchflat.YtDlp.Media do
|
||||
:livestream,
|
||||
:short_form_content,
|
||||
:uploaded_at,
|
||||
:duration_seconds
|
||||
:duration_seconds,
|
||||
:predicted_media_filepath
|
||||
]
|
||||
|
||||
defstruct [
|
||||
@@ -23,7 +24,8 @@ defmodule Pinchflat.YtDlp.Media do
|
||||
:short_form_content,
|
||||
:uploaded_at,
|
||||
:duration_seconds,
|
||||
:playlist_index
|
||||
:playlist_index,
|
||||
:predicted_media_filepath
|
||||
]
|
||||
|
||||
alias __MODULE__
|
||||
@@ -63,15 +65,17 @@ defmodule Pinchflat.YtDlp.Media do
|
||||
|
||||
@doc """
|
||||
Returns a map representing the media at the given URL.
|
||||
Optionally takes a list of additional command options to pass to yt-dlp
|
||||
or configuration-related options to pass to the runner.
|
||||
|
||||
Returns {:ok, %Media{}} | {:error, any, ...}.
|
||||
"""
|
||||
def get_media_attributes(url, addl_opts \\ []) do
|
||||
def get_media_attributes(url, command_opts \\ [], addl_opts \\ []) do
|
||||
runner = Application.get_env(:pinchflat, :yt_dlp_runner)
|
||||
command_opts = [:simulate, :skip_download]
|
||||
all_command_opts = [:simulate, :skip_download] ++ command_opts
|
||||
output_template = indexing_output_template()
|
||||
|
||||
case runner.run(url, command_opts, output_template, addl_opts) do
|
||||
case runner.run(url, all_command_opts, output_template, addl_opts) do
|
||||
{:ok, output} ->
|
||||
output
|
||||
|> Phoenix.json_library().decode!()
|
||||
@@ -91,7 +95,7 @@ defmodule Pinchflat.YtDlp.Media do
|
||||
if something is a short via the URL again
|
||||
"""
|
||||
def indexing_output_template do
|
||||
"%(.{id,title,live_status,original_url,description,aspect_ratio,duration,upload_date,timestamp,playlist_index})j"
|
||||
"%(.{id,title,live_status,original_url,description,aspect_ratio,duration,upload_date,timestamp,playlist_index,filename})j"
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -110,7 +114,8 @@ defmodule Pinchflat.YtDlp.Media do
|
||||
duration_seconds: response["duration"] && round(response["duration"]),
|
||||
short_form_content: response["original_url"] && short_form_content?(response),
|
||||
uploaded_at: response["upload_date"] && parse_uploaded_at(response),
|
||||
playlist_index: response["playlist_index"] || 0
|
||||
playlist_index: response["playlist_index"] || 0,
|
||||
predicted_media_filepath: response["filename"]
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -11,20 +11,23 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
||||
|
||||
@doc """
|
||||
Returns a list of maps representing the media in the collection.
|
||||
Optionally takes a list of additional command options to pass to yt-dlp
|
||||
or configuration-related options to pass to the runner.
|
||||
|
||||
Options:
|
||||
Runner Options:
|
||||
- :file_listener_handler - a function that will be called with the path to the
|
||||
file that will be written to when yt-dlp is done. This is useful for
|
||||
setting up a file watcher to know when the file is ready to be read.
|
||||
- :use_cookies - whether or not to use user-provided cookies when fetching the media details
|
||||
|
||||
Returns {:ok, [map()]} | {:error, any, ...}.
|
||||
"""
|
||||
def get_media_attributes_for_collection(url, addl_opts \\ []) do
|
||||
def get_media_attributes_for_collection(url, command_opts \\ [], addl_opts \\ []) do
|
||||
runner = Application.get_env(:pinchflat, :yt_dlp_runner)
|
||||
# `ignore_no_formats_error` is necessary because yt-dlp will error out if
|
||||
# the first video has not released yet (ie: is a premier). We don't care about
|
||||
# available formats since we're just getting the media details
|
||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||
all_command_opts = [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings] ++ command_opts
|
||||
use_cookies = Keyword.get(addl_opts, :use_cookies, false)
|
||||
output_template = YtDlpMedia.indexing_output_template()
|
||||
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
||||
@@ -35,7 +38,7 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
||||
file_listener_handler.(output_filepath)
|
||||
end
|
||||
|
||||
case runner.run(url, command_opts, output_template, runner_opts) do
|
||||
case runner.run(url, all_command_opts, output_template, runner_opts) do
|
||||
{:ok, output} ->
|
||||
parsed_lines =
|
||||
output
|
||||
|
||||
Reference in new issue
Block a user