-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ensure channel detail lookup doesn't download the video - oops * Ran the needful migrations for replacing channels with sources * got media source test back working * channel tasks test * Media indexing worker test * media tests * Got all tests working except controller tests * got all tests working * Renamed Channel struct to Source * renamed ChannelTasks * More renaming; renamed channel details module * Removed Channel yt-dlp module, instead throwing things in the VideoCollection module * Renamed what looks like the last of the outstanding data
- Loading branch information
1 parent
977b69b
commit 366fd80
Showing
46 changed files
with
806 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
59 changes: 39 additions & 20 deletions
59
lib/pinchflat/media_client/backends/yt_dlp/video_collection.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,47 @@ | ||
defmodule Pinchflat.MediaClient.Backends.YtDlp.VideoCollection do | ||
@moduledoc """ | ||
Contains utilities for working with collections of videos (ie: channels, playlists). | ||
Contains utilities for working with collections of | ||
videos (aka: a source [ie: channels, playlists]). | ||
""" | ||
|
||
alias Pinchflat.MediaClient.SourceDetails | ||
|
||
@doc """ | ||
Returns a list of strings representing the video ids in the collection. | ||
Returns {:ok, [binary()]} | {:error, any, ...}. | ||
""" | ||
def get_video_ids(url, command_opts \\ []) do | ||
runner = Application.get_env(:pinchflat, :yt_dlp_runner) | ||
opts = command_opts ++ [:simulate, :skip_download] | ||
|
||
case runner.run(url, opts, "%(id)s") do | ||
{:ok, output} -> {:ok, String.split(output, "\n", trim: true)} | ||
res -> res | ||
end | ||
end | ||
|
||
@doc """ | ||
Gets a source's ID and name from its URL. | ||
Meant to be included in other modules but can be used on its own. Channels and playlists | ||
will have many of their own methods, but also share a lot of methods. This module is for | ||
those shared methods. | ||
yt-dlp does not _really_ have source-specific functions, so | ||
instead we're fetching just the first video (using playlist_end: 1) | ||
and parsing the source ID and name from _its_ metadata | ||
Returns {:ok, %SourceDetails{}} | {:error, any, ...}. | ||
""" | ||
def get_source_details(source_url) do | ||
opts = [:skip_download, playlist_end: 1] | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
@doc """ | ||
Returns a list of strings representing the video ids in the collection. | ||
Returns {:ok, [binary()]} | {:error, any, ...}. | ||
""" | ||
def get_video_ids(url, command_opts \\ []) do | ||
runner = Application.get_env(:pinchflat, :yt_dlp_runner) | ||
opts = command_opts ++ [:simulate, :skip_download] | ||
|
||
case runner.run(url, opts, "%(id)s") do | ||
{:ok, output} -> {:ok, String.split(output, "\n", trim: true)} | ||
res -> res | ||
end | ||
end | ||
with {:ok, output} <- backend_runner().run(source_url, opts, "%(.{channel,channel_id})j"), | ||
{:ok, parsed_json} <- Phoenix.json_library().decode(output) do | ||
{:ok, SourceDetails.new(parsed_json["channel_id"], parsed_json["channel"])} | ||
else | ||
err -> err | ||
end | ||
end | ||
|
||
defp backend_runner do | ||
Application.get_env(:pinchflat, :yt_dlp_runner) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Pinchflat.MediaClient.SourceDetails do | ||
@moduledoc """ | ||
This is the integration layer for actually working with sources. | ||
Technically hardcodes the yt-dlp backend for now, but should leave | ||
it open-ish for future expansion (just in case). | ||
""" | ||
@enforce_keys [:id, :name] | ||
defstruct [:id, :name] | ||
|
||
alias Pinchflat.MediaClient.Backends.YtDlp.VideoCollection, as: YtDlpSource | ||
|
||
@doc false | ||
def new(id, name) do | ||
%__MODULE__{id: id, name: name} | ||
end | ||
|
||
@doc """ | ||
Gets a source's ID and name from its URL, using the given backend. | ||
Returns {:ok, map()} | {:error, any, ...}. | ||
""" | ||
def get_source_details(source_url, backend \\ :yt_dlp) do | ||
source_module(backend).get_source_details(source_url) | ||
end | ||
|
||
@doc """ | ||
Returns a list of video IDs for the given source URL, using the given backend. | ||
Returns {:ok, list(binary())} | {:error, any, ...}. | ||
""" | ||
def get_video_ids(source_url, backend \\ :yt_dlp) do | ||
source_module(backend).get_video_ids(source_url) | ||
end | ||
|
||
defp source_module(backend) do | ||
case backend do | ||
:yt_dlp -> YtDlpSource | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.