Skip to content

Commit d49567f

Browse files
committed
fix mac os mpv
1 parent 41f0d91 commit d49567f

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src-tauri/src/mpv.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::log;
12
use crate::{media_type, settings::get_settings, types::Channel};
23
use anyhow::{bail, Context, Result};
34
use chrono::Local;
@@ -19,14 +20,17 @@ const ARG_CACHE: &str = "--cache";
1920
const ARG_RECORD: &str = "--stream-record=";
2021
const ARG_TITLE: &str = "--title=";
2122
const ARG_MSG_LEVEL: &str = "--msg-level=all=error";
23+
const ARG_YTDLP_PATH: &str = "--script-opts=ytdl_hook-ytdl_path=";
2224
const MPV_BIN_NAME: &str = "mpv";
25+
const YTDLP_BIN_NAME: &str = "yt-dlp";
2326
const MACOS_POTENTIAL_PATHS: [&str; 3] = [
24-
"/opt/local/bin/mpv", // MacPorts
25-
"/opt/homebrew/bin/mpv", // Homebrew on AARCH64 Mac
26-
"/usr/local/bin/mpv", // Homebrew on AMD64 Mac
27+
"/opt/local/bin", // MacPorts
28+
"/opt/homebrew/bin", // Homebrew on AARCH64 Mac
29+
"/usr/local/bin", // Homebrew on AMD64 Mac
2730
];
2831

2932
static MPV_PATH: LazyLock<String> = LazyLock::new(|| get_mpv_path());
33+
static YTDLP_PATH: LazyLock<String> = LazyLock::new(|| find_macos_bin(YTDLP_BIN_NAME.to_string()));
3034

3135
pub async fn play(channel: Channel, record: bool) -> Result<()> {
3236
println!("{} playing", channel.url.as_ref().unwrap());
@@ -53,8 +57,7 @@ pub async fn play(channel: Channel, record: bool) -> Result<()> {
5357
}
5458
if error != "" {
5559
bail!(error);
56-
}
57-
else {
60+
} else {
5861
bail!("Mpv encountered an unknown error");
5962
}
6063
}
@@ -66,7 +69,7 @@ fn get_mpv_path() -> String {
6669
if OS == "linux" || which("mpv").is_ok() {
6770
return MPV_BIN_NAME.to_string();
6871
} else if OS == "macos" {
69-
return get_mpv_path_mac();
72+
return find_macos_bin(MPV_BIN_NAME.to_string());
7073
}
7174
return get_mpv_path_win();
7275
}
@@ -79,14 +82,21 @@ fn get_mpv_path_win() -> String {
7982
return path.to_string_lossy().to_string();
8083
}
8184

82-
fn get_mpv_path_mac() -> String {
85+
fn find_macos_bin(bin: String) -> String {
8386
return MACOS_POTENTIAL_PATHS
8487
.iter()
85-
.find(|path| Path::new(path).exists())
86-
.map(|s| s.to_string())
88+
.map(|path| {
89+
let mut path = Path::new(path).to_path_buf();
90+
path.push(&bin);
91+
return path;
92+
})
93+
.find(|path| {
94+
path.exists()
95+
})
96+
.map(|s| s.to_string_lossy().to_string())
8797
.unwrap_or_else(|| {
88-
eprintln!("Could not find MPV for MacOS host");
89-
return MPV_BIN_NAME.to_string();
98+
log::log(format!("Could not find {} on MacOS host", bin));
99+
return bin;
90100
});
91101
}
92102

@@ -108,6 +118,9 @@ fn get_play_args(channel: Channel, record: bool) -> Result<Vec<String>> {
108118
};
109119
args.push(format!("{ARG_RECORD}{record_path}"));
110120
}
121+
if OS == "macos" && *MPV_PATH != MPV_BIN_NAME {
122+
args.push(format!("{}{}", ARG_YTDLP_PATH, *YTDLP_PATH));
123+
}
111124
args.push(format!("{}{}", ARG_TITLE, channel.name));
112125
args.push(ARG_MSG_LEVEL.to_string());
113126
if let Some(mpv_params) = settings.mpv_params {

0 commit comments

Comments
 (0)