Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ There is no telemetry. refryt connects to YouTube, [LRCLIB](https://lrclib.net)

The project is before 1.0 and changes quickly. Only the Linux builds see daily use; the Windows builds are cross-compiled with limited testing on real hardware, and the macOS build has been tested by hand. Podcasts are not supported. A change to YouTube's internal API can break playback or a page until a fix is released.

If an assigned YouTube stream host is unreachable, refryt retries alternate nodes listed in the stream URL.

Bugs go to the [issue tracker](https://github.com/gridoe/refryt/issues); [CONTRIBUTING.md](CONTRIBUTING.md) says what to include.

## Build from source
Expand Down
33 changes: 10 additions & 23 deletions crates/refryt-resolve/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct GuestResolver {
visitor: Mutex<Option<String>>,
visitor_file: Option<PathBuf>,
quality: Mutex<GuestQuality>,
/// Ask the stream for its first byte before handing it on; see [`Self::probe`].
/// Ask the stream for its first byte before handing it on; see [`crate::probe_first_byte`].
probe: bool,
}

Expand Down Expand Up @@ -128,26 +128,6 @@ impl GuestResolver {
}
}

/// Ask the stream for its first byte, as the proxy will ask for its ranges. The media server
/// now and then refuses a URL `player` has just handed out; found here, the chain still
/// falls through to yt-dlp, where found in mpv the song would simply fail. The connection it
/// opens is the one the proxy's first range then reuses, as for the `player` request.
async fn probe(&self, url: &Url) -> Result<()> {
let response = self
.http
.get(url.as_str())
.header("Range", "bytes=0-0")
.header("User-Agent", GUEST_USER_AGENT)
.timeout(Duration::from_secs(10))
.send()
.await
.context("the stream did not answer")?;
match response.status().as_u16() {
200 | 206 => Ok(()),
status => bail!("the stream answered {status}"),
}
}

async fn player(&self, id: &VideoId, visitor: Option<&str>) -> Result<Value> {
let mut request = self
.http
Expand Down Expand Up @@ -213,10 +193,17 @@ impl StreamResolver for GuestResolver {
);
}
let quality = self.quality.lock().map(|q| *q).unwrap_or_default();
let stream =
let mut stream =
pick(&response, quality).with_context(|| format!("no direct audio stream for {id}"))?;
if self.probe {
self.probe(&stream.url)
// The media server now and then hands out a URL its own host will not serve, or
// on a node this machine cannot reach; found here, the chain still falls through
// to yt-dlp, where found in mpv the song would simply fail. A dead node is
// healed in place by the mirror failover inside the probe — not a resolver
// failure, so the breaker must not hear of it when a mirror answers. The
// connection the probe opens is the one the proxy's first range then reuses, as
// for the `player` request.
crate::probe_first_byte(&self.http, &mut stream.url)
.await
.with_context(|| format!("guest stream for {id}"))?;
}
Expand Down
Loading
Loading