AI • Science • Technology • Future

Side Projects

BufferedTV: A PeerTube Client for Linux Desktop

Image from the original article
Featured image: original publisher image. Via original publisher.

BufferedTV has officially launched a Linux desktop version. The app, originally built for Apple TV, now runs on Linux through a Flatpak package. Version 1.1.1 is the latest release, offering a native experience for Linux users. Source: dev.to.

What PeerTube Is and What BufferedTV Does

PeerTube is a decentralized network of small video hosting sites. These instances communicate using the ActivityPub protocol. This allows videos to be shared across multiple independent servers without relying on a central authority.

BufferedTV connects users to one PeerTube instance. Once signed in, it searches the entire network for content. It plays videos directly from their host, maintains subscription lists, and tracks watch progress. Users can also download videos with subtitles for offline viewing.

Technical Stack and Architecture

The app is built using Rust 2024. It leverages gtk4-rs and libadwaita for the user interface. Media playback uses GStreamer via GstPlay, with video rendered through gtk4paintablesink.

Network operations use tokio and reqwest to interact with the PeerTube API. OAuth authentication includes support for one-time passwords. The app stores tokens securely using oo7, a Rust library that integrates with the system keyring.

For desktop media control, it runs a MPRIS server. This allows keyboard shortcuts and volume controls to work with the system. The entire app is packaged as a Flatpak, built for both amd64 and arm64 architectures.

Concurrency and Thread Safety

GTK widgets operate on a single thread. Network calls must not block this thread. To solve this, the app runs a tokio runtime alongside the GTK main loop.

According to the developer, a small helper function is used to spawn a future on the tokio runtime. Once the future completes, the result is passed back to the main thread via glib::spawn_future_local. This design ensures that the UI remains responsive and that no widget is accessed from an incorrect thread. The code structure remains clean and readable, with no direct threading violations.

Playback and Subtitle Handling

PeerTube serves videos via HLS. The app selects a video quality from a menu. GstPlay plays the master playlist, with a height cap applied based on user choice.

Video frames are sent to a gtk4paintablesink. When a GL context is available, it wraps the sink in a gsinksbin. This allows video to be treated as a standard GTK widget.

Image from the original article
original publisher image. Via original publisher. · Source

Subtitles appear as a label layered over the video. This ensures styling consistency with the app’s design language, as the label uses the same fonts and theming as the rest of the interface.

Key Bugs and Fixes

One issue involved synthetic motion events. In full-screen mode, the controls would hide and then reappear unexpectedly. The developer explains that GTK sends motion events whenever the layout changes under a still pointer. When the controls were hidden, the layout changed, triggering a new motion event and causing the controls to reappear.

After investigation, the fix was implemented to require the pointer to move by more than a few pixels before the controls are considered to have moved. This prevents the synthetic event from being triggered and ensures the controls only reappear when actual movement occurs.

Another issue involved comment rendering. PeerTube uses Markdown, but comments from Mastodon and other fediverse platforms arrive as HTML. When both were rendered as Markdown, raw HTML tags were exposed, which could pose a security risk.

The developer notes that the app now detects HTML content and converts it to Pango markup. Only safe elements—such as HTTP links—are allowed through. This ensures that comments are displayed correctly without exposing potentially harmful code.

Flatpak Design and Security

The Flatpak package requests only essential permissions: network, display, sound, and GPU access. It does not access user files or any other system resources.

Downloads are stored entirely within the app’s own data folder, separate from user files. Every build includes a smoke test that runs inside the sandbox to verify that all required GStreamer plugins are present and functional.

New Features in 1.1.1

  • Picture-in-picture mode: Press ‘P’ to move video to a small window.
  • Side panel folds down to icons (triggered by F9), with state saved between launches.
  • Fediverse comments now display correctly.
  • Full-screen controls hide after inactivity and do not reappear prematurely.
  • Like counts update in real time as users press the like button.

Users can download the app from buffered.tv/linux. The source code is open and licensed under MIT at code.squarecows.com/ric/bufferedtv-linux. Issues and pull requests are welcome.

For developers interested in local-first media tools, see how a local-first editor stays fast. For audio extraction, explore FFmpeg workflows.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source