-
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.
Removed Channel yt-dlp module, instead throwing things in the VideoCo…
…llection module
- Loading branch information
1 parent
2250695
commit 6a31d33
Showing
5 changed files
with
81 additions
and
108 deletions.
There are no files selected for viewing
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 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
45 changes: 0 additions & 45 deletions
45
test/pinchflat/media_client/backends/yt_dlp/channel_test.exs
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