WIP - created methods for breaking on existing media

This commit is contained in:
Kieran Eglin 2025-01-02 11:48:59 -08:00
parent 09d1653f4b
commit 7bd1464987
No known key found for this signature in database
GPG key ID: 193984967FCF432D
2 changed files with 30 additions and 2 deletions

View file

@ -5,6 +5,8 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
Many of these methods are made to be kickoff or be consumed by workers. Many of these methods are made to be kickoff or be consumed by workers.
""" """
use Pinchflat.Media.MediaQuery
require Logger require Logger
alias Pinchflat.Repo alias Pinchflat.Repo
@ -14,6 +16,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
alias Pinchflat.Sources.Source alias Pinchflat.Sources.Source
alias Pinchflat.Media.MediaItem alias Pinchflat.Media.MediaItem
alias Pinchflat.YtDlp.MediaCollection alias Pinchflat.YtDlp.MediaCollection
alias Pinchflat.Utils.FilesystemUtils
alias Pinchflat.Downloading.DownloadingHelpers alias Pinchflat.Downloading.DownloadingHelpers
alias Pinchflat.SlowIndexing.FileFollowerServer alias Pinchflat.SlowIndexing.FileFollowerServer
alias Pinchflat.Downloading.DownloadOptionBuilder alias Pinchflat.Downloading.DownloadOptionBuilder
@ -96,6 +99,22 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
result result
end end
# TODO: test
def create_download_archive_file(%Source{} = source) do
tmpfile = FilesystemUtils.generate_metadata_tmpfile(:txt)
archive_contents =
source
|> get_media_items_for_download_archive()
|> Enum.map(fn media_item -> "youtube #{media_item.media_id}" end)
|> Enum.join("\n")
case File.write(tmpfile, archive_contents) do
:ok -> tmpfile
err -> err
end
end
# The file follower is a GenServer that watches a file for new lines and # The file follower is a GenServer that watches a file for new lines and
# processes them. This works well, but we have to be resilliant to partially-written # processes them. This works well, but we have to be resilliant to partially-written
# lines (ie: you should gracefully fail if you can't parse a line). # lines (ie: you should gracefully fail if you can't parse a line).
@ -166,4 +185,14 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
max(0, index_frequency_seconds - offset_seconds) max(0, index_frequency_seconds - offset_seconds)
end end
# TODO: document
defp get_media_items_for_download_archive(source) do
MediaQuery.new()
|> where(^MediaQuery.for_source(source))
|> order_by(desc: :uploaded_at)
|> limit(20)
|> offset(20)
|> Repo.all()
end
end end

View file

@ -23,7 +23,6 @@ defmodule Pinchflat.YtDlp.MediaCollection do
Returns {:ok, [map()]} | {:error, any, ...}. Returns {:ok, [map()]} | {:error, any, ...}.
""" """
def get_media_attributes_for_collection(url, command_opts \\ [], 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 # `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 # 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 # available formats since we're just getting the media details
@ -39,7 +38,7 @@ defmodule Pinchflat.YtDlp.MediaCollection do
file_listener_handler.(output_filepath) file_listener_handler.(output_filepath)
end end
case runner.run(url, action, all_command_opts, output_template, runner_opts) do case backend_runner().run(url, action, all_command_opts, output_template, runner_opts) do
{:ok, output} -> {:ok, output} ->
parsed_lines = parsed_lines =
output output