Skip to content

Commit

Permalink
Add support for actual hostnames in MPD_HOST
Browse files Browse the repository at this point in the history
  • Loading branch information
Polochon-street committed Jan 24, 2024
1 parent 880d2c5 commit 1eb4588
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## blissify 0.3.9
* Add support for hostnames in MPD_HOST

## blissify 0.3.8
* Bump bliss to fix build on raspberry pis.

Expand Down
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ impl MPDLibrary {
6600
}
};
// TODO maybe we don't need this? Regardless of whether it's an IP or a hostname,
// putting (host|ip):port in a string should be enough to connect
let addr: Option<SocketAddr> = {
let tentative_parse: Option<SocketAddr> = mpd_host.parse().ok();
if tentative_parse.is_none() {
Expand All @@ -163,11 +165,23 @@ impl MPDLibrary {
};

let mut client = {
if let Some(address) = addr {
Client::new(MPDStream::Tcp(TcpStream::connect(address)?))?
} else {
// TODO It is most likely a socket if it starts by "/", but maybe not necessarily?
// find a solution that doesn't depend on a url crate that pulls the entire internet
// with it
if mpd_host.starts_with('/') {
Client::new(MPDStream::Unix(UnixStream::connect(mpd_host)?))?
}
// We managed to parse an IP-address
else if let Some(address) = addr {
Client::new(MPDStream::Tcp(TcpStream::connect(address)?))?
}
// It is a hostname
else {
Client::new(MPDStream::Tcp(TcpStream::connect(format!(
"{}:{}",
mpd_host, mpd_port
))?))?
}
};
if let Some(pw) = password {
client.login(&pw)?;
Expand Down

0 comments on commit 1eb4588

Please sign in to comment.