chore: give better names to track structs

This commit is contained in:
Tal 2025-07-02 19:46:17 +02:00
parent 6fadfe6304
commit 0b15ce8e1b
5 changed files with 19 additions and 15 deletions

View File

@ -71,7 +71,7 @@ pub struct Player {
/// *undecoded* [Track]s. /// *undecoded* [Track]s.
/// ///
/// This is populated specifically by the [Downloader]. /// This is populated specifically by the [Downloader].
tracks: RwLock<VecDeque<tracks::Track>>, tracks: RwLock<VecDeque<tracks::QueuedTrack>>,
/// The actual list of tracks to be played. /// The actual list of tracks to be played.
list: List, list: List,

View File

@ -18,6 +18,8 @@ pub async fn bookmark(path: String, custom: Option<String>) -> eyre::Result<bool
let data_dir = data_dir()?; let data_dir = data_dir()?;
create_dir_all(data_dir.clone()).await?; create_dir_all(data_dir.clone()).await?;
// TODO: Only open and close the file at startup and shutdown, not every single bookmark.
// TODO: Sort of like PersistentVolume, but for bookmarks.
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.create(true) .create(true)
.write(true) .write(true)

View File

@ -10,7 +10,7 @@ use crate::{
impl Player { impl Player {
/// Fetches the next track from the queue, or a random track if the queue is empty. /// Fetches the next track from the queue, or a random track if the queue is empty.
/// This will also set the current track to the fetched track's info. /// This will also set the current track to the fetched track's info.
async fn fetch(&self) -> Result<tracks::Decoded, tracks::TrackError> { async fn fetch(&self) -> Result<tracks::DecodedTrack, tracks::TrackError> {
// TODO: Consider replacing this with `unwrap_or_else` when async closures are stablized. // TODO: Consider replacing this with `unwrap_or_else` when async closures are stablized.
let track = self.tracks.write().await.pop_front(); let track = self.tracks.write().await.pop_front();
let track = if let Some(track) = track { let track = if let Some(track) = track {

View File

@ -8,7 +8,7 @@
//! First Stage, when a track is initially fetched. //! First Stage, when a track is initially fetched.
//! 1. Raw entry selected from track list. //! 1. Raw entry selected from track list.
//! 2. Raw entry split into path & display name. //! 2. Raw entry split into path & display name.
//! 3. Track data fetched, and [`Track`] is created which includes a [`TrackName`] that may be raw. //! 3. Track data fetched, and [`QueuedTrack`] is created which includes a [`TrackName`] that may be raw.
//! //!
//! Second Stage, when a track is played. //! Second Stage, when a track is played.
//! 1. Track data is decoded. //! 1. Track data is decoded.
@ -73,8 +73,10 @@ pub enum TrackName {
Formatted(String), Formatted(String),
} }
/// The main track struct, which only includes data & the track name. /// Tracks which are still waiting in the queue, and can't be played yet.
pub struct Track { ///
/// This means that only the data & track name are included.
pub struct QueuedTrack {
/// Name of the track, which may be raw. /// Name of the track, which may be raw.
pub name: TrackName, pub name: TrackName,
@ -86,12 +88,12 @@ pub struct Track {
pub data: Bytes, pub data: Bytes,
} }
impl Track { impl QueuedTrack {
/// This will actually decode and format the track, /// This will actually decode and format the track,
/// returning a [`DecodedTrack`] which can be played /// returning a [`DecodedTrack`] which can be played
/// and also has a duration & formatted name. /// and also has a duration & formatted name.
pub fn decode(self) -> eyre::Result<Decoded, TrackError> { pub fn decode(self) -> eyre::Result<DecodedTrack, TrackError> {
Decoded::new(self) DecodedTrack::new(self)
} }
} }
@ -198,7 +200,7 @@ impl Info {
/// This struct is seperate from [Track] since it is generated lazily from /// This struct is seperate from [Track] since it is generated lazily from
/// a track, and not when the track is first downloaded. /// a track, and not when the track is first downloaded.
pub struct Decoded { pub struct DecodedTrack {
/// Has both the formatted name and some information from the decoded data. /// Has both the formatted name and some information from the decoded data.
pub info: Info, pub info: Info,
@ -206,10 +208,10 @@ pub struct Decoded {
pub data: DecodedData, pub data: DecodedData,
} }
impl Decoded { impl DecodedTrack {
/// Creates a new track. /// Creates a new track.
/// This is equivalent to [`Track::decode`]. /// This is equivalent to [`QueuedTrack::decode`].
pub fn new(track: Track) -> eyre::Result<Self, TrackError> { pub fn new(track: QueuedTrack) -> eyre::Result<Self, TrackError> {
let data = Decoder::new(Cursor::new(track.data))?; let data = Decoder::new(Cursor::new(track.data))?;
let info = Info::new(track.name, track.full_path, &data)?; let info = Info::new(track.name, track.full_path, &data)?;

View File

@ -9,7 +9,7 @@ use tokio::fs;
use crate::{data_dir, tracks::TrackError}; use crate::{data_dir, tracks::TrackError};
use super::Track; use super::QueuedTrack;
/// Represents a list of tracks that can be played. /// Represents a list of tracks that can be played.
/// ///
@ -93,7 +93,7 @@ impl List {
/// ///
/// The Result's error is a bool, which is true if a timeout error occured, /// The Result's error is a bool, which is true if a timeout error occured,
/// and false otherwise. This tells lowfi if it shouldn't wait to try again. /// and false otherwise. This tells lowfi if it shouldn't wait to try again.
pub async fn random(&self, client: &Client) -> Result<Track, TrackError> { pub async fn random(&self, client: &Client) -> Result<QueuedTrack, TrackError> {
let (path, custom_name) = self.random_path(); let (path, custom_name) = self.random_path();
let (data, full_path) = self.download(&path, client).await?; let (data, full_path) = self.download(&path, client).await?;
@ -101,7 +101,7 @@ impl List {
super::TrackName::Formatted(formatted) super::TrackName::Formatted(formatted)
}); });
Ok(Track { Ok(QueuedTrack {
name, name,
data, data,
full_path, full_path,