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: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ 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
8 changes: 7 additions & 1 deletion crates/refryt-resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ fn mirror_url(url: &Url, node: &str) -> Option<Url> {
Some(mirrored)
}

/// How long a stream host gets to send its response headers, connection included, before
/// it counts as unreachable and a mirror is tried: for [`probe_first_byte`] and for each
/// range the proxy fetches. A reachable host answers in well under a second (0.06–0.75 s
/// measured 2026-11-17, cold), and a dead one should cost little more than this.
pub(crate) const STREAM_DEADLINE: Duration = Duration::from_secs(6);

/// Ask a stream host for its first byte, and fail over to a mirror node when it will not
/// take the connection.
///
Expand All @@ -315,7 +321,7 @@ pub async fn probe_first_byte(http: &reqwest::Client, url: &mut Url) -> Result<(
.header("User-Agent", guest::GUEST_USER_AGENT)
// Short, so a dead node costs seconds: the mirrors are tried while the caller
// is still waiting for a URL worth playing.
.timeout(Duration::from_secs(5))
.timeout(STREAM_DEADLINE)
.send()
};
let response = match get(url).await {
Expand Down
12 changes: 9 additions & 3 deletions crates/refryt-resolve/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,19 +427,25 @@ async fn fetch_range(
end: u64,
) -> Result<Vec<u8>> {
// Bound each attempt through response headers, including DNS/TCP/TLS and pooled
// connections. Leave body reads unbounded: a healthy 1 MiB range can take over 5 s.
// connections. Leave body reads unbounded: a healthy 1 MiB range can take longer
// than the deadline.
let get = |url: Url| async move {
Ok::<_, anyhow::Error>(
tokio::time::timeout(
std::time::Duration::from_secs(5),
crate::STREAM_DEADLINE,
http.get(url)
.header("Range", format!("bytes={start}-{end}"))
.header("User-Agent", GUEST_USER_AGENT)
.header("Accept-Encoding", "identity")
.send(),
)
.await
.context("the stream host did not answer within 5 seconds")??,
.with_context(|| {
format!(
"the stream host did not answer within {} seconds",
crate::STREAM_DEADLINE.as_secs()
)
})??,
)
};
let url = entry.url.lock().unwrap().clone();
Expand Down
6 changes: 4 additions & 2 deletions crates/refryt/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ impl Player {
// its own edge. 4 MiB is a few minutes of Opus — plenty for a scrub-back.
init.set_property("demuxer-max-back-bytes", "4MiB")?;
// Bound connection establishment only; body reads keep their normal tolerance
// for buffered proxy streams. Older mpv builds without curl lack this option.
let _ = init.set_property("curl-connect-timeout", "5");
// for buffered proxy streams. Only mpv built with libcurl has this option (0.42
// and later, and the Windows libmpv); its default is 30 s per dead stream host.
// Others ignore it. It only matters for URLs mpv opens itself, not the proxy's.
let _ = init.set_property("curl-connect-timeout", "6");
// We resolve stream URLs ourselves via refryt-resolve, so mpv must not invoke
// yt-dlp for them — direct `googlevideo.com` URLs never match ytdl_hook's
// `youtube.com` patterns, so enabling the hook costs nothing there. The in-app
Expand Down
Loading