* Made method to getting singular media details; Renamed other related method * Takes a fun and flirty digression to remove abstractions around yt-dlp since I'm 100% committed to using it exclusively * Removed commented test code * Lays the groundwork for fast indexing * Added module for working with youtube RSS feed * Added methods to kick off indexing workers from RSS response * Improve short detection (#59) * Made media attribute-related yt-dlp calls return a struct * Added shorts attribute to media items * Added ability to discern a short from yt-dlp response * Updated search to use new shorts attribute * Fast index UI (#63) * Added fast_index field and adds it to source form * Added fast indexing to source changeset operations * Added fast indexing worker and updated other modules to start using it * Handled fast index worker on source update * Add support modals (#65) * Added fast indexing upgrade modal * Improved modal on smaller screens * Updated links to work again * Added donation modal * Reverted source fast index to 15 minutes * Removed unneeded HTML attributes from old alpine approach
67 lines
1.9 KiB
Elixir
67 lines
1.9 KiB
Elixir
defmodule Pinchflat.Metadata.MetadataParser do
|
|
@moduledoc """
|
|
yt-dlp offers a LOT of metadata in its JSON response, some of which
|
|
needs to be extracted and included in various models.
|
|
|
|
For now, also squirrel all of it away in the `media_metadata` table.
|
|
I might revisit this or pare it down later, but I'd rather need it
|
|
and not have it, ya know?
|
|
"""
|
|
|
|
@doc """
|
|
Parses the given JSON response from yt-dlp and returns a map of
|
|
the needful media_item attributes, along with anything needed for
|
|
its associations.
|
|
|
|
Returns map()
|
|
"""
|
|
def parse_for_media_item(metadata) do
|
|
Map.new()
|
|
|> Map.merge(parse_media_metadata(metadata))
|
|
|> Map.merge(parse_subtitle_metadata(metadata))
|
|
|> Map.merge(parse_thumbnail_metadata(metadata))
|
|
|> Map.merge(parse_infojson_metadata(metadata))
|
|
end
|
|
|
|
defp parse_media_metadata(metadata) do
|
|
%{
|
|
media_id: metadata["id"],
|
|
title: metadata["title"],
|
|
original_url: metadata["original_url"],
|
|
description: metadata["description"],
|
|
media_filepath: metadata["filepath"],
|
|
livestream: metadata["was_live"]
|
|
}
|
|
end
|
|
|
|
defp parse_subtitle_metadata(metadata) do
|
|
subtitle_filepaths =
|
|
(metadata["requested_subtitles"] || %{})
|
|
|> Enum.map(fn {lang, attrs} -> [lang, attrs["filepath"]] end)
|
|
|> Enum.sort(fn [lang_a, _], [lang_b, _] -> lang_a < lang_b end)
|
|
|
|
%{
|
|
subtitle_filepaths: subtitle_filepaths
|
|
}
|
|
end
|
|
|
|
defp parse_thumbnail_metadata(metadata) do
|
|
thumbnail_filepath =
|
|
(metadata["thumbnails"] || %{})
|
|
# Reverse so that higher resolution thumbnails come first.
|
|
# This _shouldn't_ matter yet, but I'd rather default to the best
|
|
# in case I'm wrong.
|
|
|> Enum.reverse()
|
|
|> Enum.find_value(fn attrs -> attrs["filepath"] end)
|
|
|
|
%{
|
|
thumbnail_filepath: thumbnail_filepath
|
|
}
|
|
end
|
|
|
|
defp parse_infojson_metadata(metadata) do
|
|
%{
|
|
metadata_filepath: metadata["infojson_filename"]
|
|
}
|
|
end
|
|
end
|