Skip to content

Commit

Permalink
add yt-dlp path to daemon config
Browse files Browse the repository at this point in the history
  • Loading branch information
aschey committed Nov 28, 2024
1 parent 285a154 commit d802a9b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
24 changes: 22 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions libplatune/player/src/resolver/yt_dlp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cmp::Ordering;
use std::collections::HashSet;
use std::env;
use std::num::NonZeroUsize;
use std::time::Duration;

Expand All @@ -16,7 +17,7 @@ use stream_download::storage::temp::TempStorageProvider;
use stream_download::{Settings, StreamDownload};
use tap::TapFallible;
use tokio_util::sync::CancellationToken;
use tracing::{error, info};
use tracing::{error, info, warn};
use youtube_dl::{YoutubeDl, YoutubeDlOutput};

macro_rules! url_regex {
Expand All @@ -42,6 +43,12 @@ fn ytdl_rules() -> Vec<Rule> {
]
}

fn ytdl_exe() -> String {
let path = env::var("YT_DLP_PATH").unwrap_or_else(|_| "yt-dlp".to_string());
info!("Using yt-dlp path: {path:?}");
path
}

pub(crate) struct YtDlpUrlResolver {
rules: Vec<Rule>,
skip_flat_playlist: HashSet<&'static str>,
Expand All @@ -50,6 +57,8 @@ pub(crate) struct YtDlpUrlResolver {
impl YtDlpUrlResolver {
pub(crate) fn new() -> Self {
let mut skip = HashSet::new();
// some sites don't populate urls when using --flat-playlist so we need to explicitly skip
// it
skip.insert("audius.co");
Self {
rules: ytdl_rules(),
Expand All @@ -74,6 +83,7 @@ impl RegistryEntry<Result<Vec<Input>>> for YtDlpUrlResolver {
.skip_flat_playlist
.contains(input.source.clone().into_url().domain().unwrap_or_default());
let mut command = YoutubeDl::new(input.source.clone());
command.youtube_dl_path(ytdl_exe());
if flat_playlist {
// --flat-playlist prevents it from enumerating all videos in the playlist, which could
// take a long time
Expand Down Expand Up @@ -149,9 +159,6 @@ impl RegistryEntry<Result<(Box<dyn Source>, CancellationToken)>> for YtDlpSource
info!("extracting video metadata - this may take a few seconds");
let output = YoutubeDl::new(input.source.clone())
.extract_audio(true)
// --flat-playlist prevents it from enumerating all videos in the playlist, which could
// take a long time
.extra_arg("--flat-playlist")
.run_async()
.await?;
info!("metadata extraction complete");
Expand Down Expand Up @@ -179,11 +186,14 @@ impl RegistryEntry<Result<(Box<dyn Source>, CancellationToken)>> for YtDlpSource
valid_formats.pop()
}
YoutubeDlOutput::Playlist(playlist) => {
info!("found playlist: {:?}", playlist.title);
// This shouldn't happen since we're enumerating playlists in the URL resolver
warn!("found playlist in source resolver: {:?}", playlist.title);
None
}
};
let cmd = YtDlpCommand::new(input.source).extract_audio(true);
let cmd = YtDlpCommand::new(input.source)
.yt_dlp_path(ytdl_exe())
.extract_audio(true);

let params = if let Some(format) = &found_format {
info!("source quality: {:?}", format.quality);
Expand Down
1 change: 1 addition & 0 deletions platuned/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tracing = "0.1.40"
uuid = { version = "1.11.0", features = ["v4"] }
vergen-gix = { version = "1.0.2" }
console = "0.15.8"
which = { version = "7.0.0", features = ["tracing"] }

[features]
default = ["management", "player"]
Expand Down
5 changes: 5 additions & 0 deletions platuned/server/src/bin/platunectl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use daemon_slayer::logging::cli::LoggingCliProvider;
use daemon_slayer::logging::tracing_subscriber::util::SubscriberInitExt;
use daemon_slayer::process::cli::ProcessCliProvider;
use platuned::{build_info, clap_base_command, main_server_port, service_label};
use which::which;

#[tokio::main]
async fn main() -> Result<(), ErrorSink> {
Expand Down Expand Up @@ -66,6 +67,10 @@ async fn run() -> Result<(), BoxedError> {
.with_environment_variable_if_exists("PLATUNE_MTLS_CLIENT_CERT_PATH")
.with_environment_variable_if_exists("PLATUNE_MTLS_CLIENT_KEY_PATH");
}
if let Ok(yt_dlp) = which("yt-dlp") {
manager_builder =
manager_builder.with_environment_variable("YT_DLP_PATH", yt_dlp.to_string_lossy());
}
let manager = manager_builder.build().await.unwrap();
let logger_builder = LoggerBuilder::new(label.clone());

Expand Down

0 comments on commit d802a9b

Please sign in to comment.