1
+ use crate :: log;
1
2
use crate :: { media_type, settings:: get_settings, types:: Channel } ;
2
3
use anyhow:: { bail, Context , Result } ;
3
4
use chrono:: Local ;
@@ -19,14 +20,17 @@ const ARG_CACHE: &str = "--cache";
19
20
const ARG_RECORD : & str = "--stream-record=" ;
20
21
const ARG_TITLE : & str = "--title=" ;
21
22
const ARG_MSG_LEVEL : & str = "--msg-level=all=error" ;
23
+ const ARG_YTDLP_PATH : & str = "--script-opts=ytdl_hook-ytdl_path=" ;
22
24
const MPV_BIN_NAME : & str = "mpv" ;
25
+ const YTDLP_BIN_NAME : & str = "yt-dlp" ;
23
26
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
27
30
] ;
28
31
29
32
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 ( ) ) ) ;
30
34
31
35
pub async fn play ( channel : Channel , record : bool ) -> Result < ( ) > {
32
36
println ! ( "{} playing" , channel. url. as_ref( ) . unwrap( ) ) ;
@@ -53,8 +57,7 @@ pub async fn play(channel: Channel, record: bool) -> Result<()> {
53
57
}
54
58
if error != "" {
55
59
bail ! ( error) ;
56
- }
57
- else {
60
+ } else {
58
61
bail ! ( "Mpv encountered an unknown error" ) ;
59
62
}
60
63
}
@@ -66,7 +69,7 @@ fn get_mpv_path() -> String {
66
69
if OS == "linux" || which ( "mpv" ) . is_ok ( ) {
67
70
return MPV_BIN_NAME . to_string ( ) ;
68
71
} else if OS == "macos" {
69
- return get_mpv_path_mac ( ) ;
72
+ return find_macos_bin ( MPV_BIN_NAME . to_string ( ) ) ;
70
73
}
71
74
return get_mpv_path_win ( ) ;
72
75
}
@@ -79,14 +82,21 @@ fn get_mpv_path_win() -> String {
79
82
return path. to_string_lossy ( ) . to_string ( ) ;
80
83
}
81
84
82
- fn get_mpv_path_mac ( ) -> String {
85
+ fn find_macos_bin ( bin : String ) -> String {
83
86
return MACOS_POTENTIAL_PATHS
84
87
. 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 ( ) )
87
97
. 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 ;
90
100
} ) ;
91
101
}
92
102
@@ -108,6 +118,9 @@ fn get_play_args(channel: Channel, record: bool) -> Result<Vec<String>> {
108
118
} ;
109
119
args. push ( format ! ( "{ARG_RECORD}{record_path}" ) ) ;
110
120
}
121
+ if OS == "macos" && * MPV_PATH != MPV_BIN_NAME {
122
+ args. push ( format ! ( "{}{}" , ARG_YTDLP_PATH , * YTDLP_PATH ) ) ;
123
+ }
111
124
args. push ( format ! ( "{}{}" , ARG_TITLE , channel. name) ) ;
112
125
args. push ( ARG_MSG_LEVEL . to_string ( ) ) ;
113
126
if let Some ( mpv_params) = settings. mpv_params {
0 commit comments