diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-02-16 18:21:02 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-02-16 18:21:02 +0100 |
| commit | 55a94110287ad2b1a55953febac48422a9d3ba89 (patch) | |
| tree | ca57ff2df49383e3f34a31df8c7c7e3d06470ba1 /yt/src | |
| parent | refactor(yt/): Use the new `termsize` and `uu_fmt` crates (diff) | |
| download | yt-55a94110287ad2b1a55953febac48422a9d3ba89.zip | |
style(treewide): Re-format
Diffstat (limited to 'yt/src')
27 files changed, 98 insertions, 86 deletions
diff --git a/yt/src/app.rs b/yt/src/app.rs index 1f82214..b9338af 100644 --- a/yt/src/app.rs +++ b/yt/src/app.rs @@ -9,7 +9,7 @@ // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. use anyhow::{Context, Result}; -use sqlx::{query, sqlite::SqliteConnectOptions, SqlitePool}; +use sqlx::{SqlitePool, query, sqlite::SqliteConnectOptions}; use crate::config::Config; diff --git a/yt/src/cache/mod.rs b/yt/src/cache/mod.rs index dfbc276..e3dfda2 100644 --- a/yt/src/cache/mod.rs +++ b/yt/src/cache/mod.rs @@ -15,8 +15,8 @@ use tokio::fs; use crate::{ app::App, storage::video_database::{ - downloader::set_video_cache_path, getters::get_videos, setters::set_state_change, Video, - VideoStatus, + Video, VideoStatus, downloader::set_video_cache_path, getters::get_videos, + setters::set_state_change, }, }; @@ -91,7 +91,10 @@ pub async fn maintain(app: &App, all: bool) -> Result<()> { } } if vid.status_change { - info!("Video '{}' has it's changing bit set. This is probably the result of an unexpectet exit. Clearing it", vid.title); + info!( + "Video '{}' has it's changing bit set. This is probably the result of an unexpectet exit. Clearing it", + vid.title + ); set_state_change(app, &vid.extractor_hash, false).await?; } } diff --git a/yt/src/comments/mod.rs b/yt/src/comments/mod.rs index afc90de..97b2c24 100644 --- a/yt/src/comments/mod.rs +++ b/yt/src/comments/mod.rs @@ -10,7 +10,7 @@ use std::mem; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use comment::{CommentExt, Comments}; use output::display_fmt_and_less; use regex::Regex; @@ -19,8 +19,8 @@ use yt_dlp::wrapper::info_json::{Comment, InfoJson, Parent}; use crate::{ app::App, storage::video_database::{ - getters::{get_currently_playing_video, get_video_info_json}, Video, + getters::{get_currently_playing_video, get_video_info_json}, }, unreachable::Unreachable, }; diff --git a/yt/src/comments/output.rs b/yt/src/comments/output.rs index c279e9e..9b3d684 100644 --- a/yt/src/comments/output.rs +++ b/yt/src/comments/output.rs @@ -14,7 +14,7 @@ use std::{ }; use anyhow::{Context, Result}; -use uu_fmt::{process_text, FmtOptions}; +use uu_fmt::{FmtOptions, process_text}; use crate::unreachable::Unreachable; diff --git a/yt/src/config/default.rs b/yt/src/config/default.rs index 7c61d6d..9f33001 100644 --- a/yt/src/config/default.rs +++ b/yt/src/config/default.rs @@ -77,7 +77,7 @@ pub(crate) mod paths { use anyhow::Result; - use super::{create_path, get_config_path, get_data_path, get_runtime_path, PREFIX}; + use super::{PREFIX, create_path, get_config_path, get_data_path, get_runtime_path}; // We download to the temp dir to avoid taxing the disk pub(crate) fn download_dir() -> Result<PathBuf> { diff --git a/yt/src/config/file_system.rs b/yt/src/config/file_system.rs index 49e02fe..0755aee 100644 --- a/yt/src/config/file_system.rs +++ b/yt/src/config/file_system.rs @@ -11,8 +11,8 @@ use crate::config::{DownloadConfig, PathsConfig, SelectConfig, WatchConfig}; use super::{ - default::{create_path, download, global, paths, select, update, watch}, Config, GlobalConfig, UpdateConfig, + default::{create_path, download, global, paths, select, update, watch}, }; use std::{fs::read_to_string, path::PathBuf}; diff --git a/yt/src/description/mod.rs b/yt/src/description/mod.rs index 10f0e0c..f31c027 100644 --- a/yt/src/description/mod.rs +++ b/yt/src/description/mod.rs @@ -9,16 +9,16 @@ // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. use crate::{ + App, comments::output::display_fmt_and_less, storage::video_database::{ - getters::{get_currently_playing_video, get_video_info_json}, Video, + getters::{get_currently_playing_video, get_video_info_json}, }, unreachable::Unreachable, - App, }; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use yt_dlp::wrapper::info_json::InfoJson; pub async fn description(app: &App) -> Result<()> { diff --git a/yt/src/download/download_options.rs b/yt/src/download/download_options.rs index bb87214..0d28553 100644 --- a/yt/src/download/download_options.rs +++ b/yt/src/download/download_options.rs @@ -8,7 +8,7 @@ // You should have received a copy of the License along with this program. // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. -use serde_json::{json, Value}; +use serde_json::{Value, json}; use crate::{app::App, storage::video_database::YtDlpOptions}; diff --git a/yt/src/download/mod.rs b/yt/src/download/mod.rs index 8bd8a75..7cfa0b0 100644 --- a/yt/src/download/mod.rs +++ b/yt/src/download/mod.rs @@ -14,17 +14,17 @@ use crate::{ app::App, download::download_options::download_opts, storage::video_database::{ + Video, YtDlpOptions, downloader::{get_next_uncached_video, set_video_cache_path}, extractor_hash::ExtractorHash, getters::get_video_yt_dlp_opts, - Video, YtDlpOptions, }, unreachable::Unreachable, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use bytes::Bytes; -use futures::{future::BoxFuture, FutureExt}; +use futures::{FutureExt, future::BoxFuture}; use log::{debug, error, info, warn}; use tokio::{fs, task::JoinHandle, time}; @@ -126,8 +126,11 @@ impl Downloader { warn!( "Can't download video: '{}' ({}) as it's too large for the cache ({} of {} allocated). \ Waiting for cache size reduction..", - next_video.title, Bytes::new(video_size), &cache_allocation, Bytes::new(max_cache_size) - ); + next_video.title, + Bytes::new(video_size), + &cache_allocation, + Bytes::new(max_cache_size) + ); self.printed_warning = true; // Update this value immediately. @@ -198,8 +201,12 @@ impl Downloader { self.current_download = Some(current_download); } else { info!( - "Noticed, that the next video is not the video being downloaded, replacing it ('{}' vs. '{}')!", - next_video.extractor_hash.into_short_hash(&app).await?, current_download.extractor_hash.into_short_hash(&app).await? + "Noticed, that the next video is not the video being downloaded, replacing it ('{}' vs. '{}')!", + next_video.extractor_hash.into_short_hash(&app).await?, + current_download + .extractor_hash + .into_short_hash(&app) + .await? ); // Replace the currently downloading video diff --git a/yt/src/main.rs b/yt/src/main.rs index 5b5eda4..acc6c7d 100644 --- a/yt/src/main.rs +++ b/yt/src/main.rs @@ -14,7 +14,7 @@ use std::{collections::HashMap, fs, sync::Arc}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use app::App; use bytes::Bytes; use cache::{invalidate, maintain}; @@ -26,7 +26,7 @@ use select::cmds::handle_select_cmd; use storage::video_database::getters::get_video_by_hash; use tokio::{ fs::File, - io::{stdin, BufReader}, + io::{BufReader, stdin}, task::JoinHandle, }; use url::Url; diff --git a/yt/src/select/cmds/add.rs b/yt/src/select/cmds/add.rs index ea39789..7d6da0f 100644 --- a/yt/src/select/cmds/add.rs +++ b/yt/src/select/cmds/add.rs @@ -7,8 +7,8 @@ use crate::{ videos::display::format_video::FormatVideo, }; -use anyhow::{bail, Context, Result}; -use log::warn; +use anyhow::{Context, Result, bail}; +use log::{error, warn}; use serde_json::{Map, Value}; use url::Url; use yt_dlp::wrapper::info_json::InfoType; @@ -50,12 +50,9 @@ pub(super) async fn add( Ok(()) } - let opts = download_opts( - app, - &video_database::YtDlpOptions { - subtitle_langs: String::new(), - }, - ); + let opts = download_opts(app, &video_database::YtDlpOptions { + subtitle_langs: String::new(), + }); let entry = yt_dlp::extract_info(&opts, &url, false, true) .await @@ -65,7 +62,9 @@ pub(super) async fn add( Some(InfoType::Video) => { add_entry(app, entry).await?; if start.is_some() || stop.is_some() { - warn!("You added `start` and `stop` markers for a single /video/! These will be ignored."); + warn!( + "You added `start` and `stop` markers for a single /video/! These will be ignored." + ); } } Some(InfoType::Playlist) => { @@ -73,12 +72,12 @@ pub(super) async fn add( let start = start.unwrap_or(0); let stop = stop.unwrap_or(entries.len() - 1); - let mut respected_entries: Vec<_> = - take_vector(entries, start, stop) - .with_context(|| { - format!( - "Failed to take entries starting at: {start} and ending with {stop}") - })?; + let mut respected_entries: Vec<_> = take_vector(entries, start, stop) + .with_context(|| { + format!( + "Failed to take entries starting at: {start} and ending with {stop}" + ) + })?; if respected_entries.is_empty() { warn!("No entries found, after applying your start/stop limits."); @@ -113,7 +112,9 @@ fn take_vector<T>(vector: Vec<T>, start: usize, stop: usize) -> Result<Vec<T>> { let length = vector.len(); if stop >= length { - bail!("Your stop marker ({stop}) exceeds the possible entries ({length})! Remember that it is zero indexed."); + bail!( + "Your stop marker ({stop}) exceeds the possible entries ({length})! Remember that it is zero indexed." + ); } let end_skip = { diff --git a/yt/src/select/cmds/mod.rs b/yt/src/select/cmds/mod.rs index 105569b..2a8a44f 100644 --- a/yt/src/select/cmds/mod.rs +++ b/yt/src/select/cmds/mod.rs @@ -12,13 +12,13 @@ use crate::{ app::App, cli::{SelectCommand, SharedSelectionCommandArgs}, storage::video_database::{ + VideoOptions, VideoStatus, getters::get_video_by_hash, setters::{set_video_options, set_video_status}, - VideoOptions, VideoStatus, }, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; mod add; diff --git a/yt/src/select/mod.rs b/yt/src/select/mod.rs index ddc8a5e..e7eb460 100644 --- a/yt/src/select/mod.rs +++ b/yt/src/select/mod.rs @@ -19,12 +19,12 @@ use crate::{ app::App, cli::CliArgs, constants::HELP_STR, - storage::video_database::{getters::get_videos, VideoStatus}, + storage::video_database::{VideoStatus, getters::get_videos}, unreachable::Unreachable, videos::display::format_video::FormatVideo, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use clap::Parser; use cmds::handle_select_cmd; use futures::future::join_all; diff --git a/yt/src/status/mod.rs b/yt/src/status/mod.rs index 2f493f7..56d29e6 100644 --- a/yt/src/status/mod.rs +++ b/yt/src/status/mod.rs @@ -20,7 +20,7 @@ use crate::{ download::Downloader, storage::{ subscriptions::get, - video_database::{getters::get_videos, VideoStatus}, + video_database::{VideoStatus, getters::get_videos}, }, }; diff --git a/yt/src/storage/subscriptions.rs b/yt/src/storage/subscriptions.rs index 8e089f0..f819dc6 100644 --- a/yt/src/storage/subscriptions.rs +++ b/yt/src/storage/subscriptions.rs @@ -14,7 +14,7 @@ use std::collections::HashMap; use anyhow::Result; use log::debug; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use sqlx::query; use url::Url; use yt_dlp::wrapper::info_json::InfoType; diff --git a/yt/src/storage/video_database/extractor_hash.rs b/yt/src/storage/video_database/extractor_hash.rs index 3aa3cd2..d080f97 100644 --- a/yt/src/storage/video_database/extractor_hash.rs +++ b/yt/src/storage/video_database/extractor_hash.rs @@ -10,7 +10,7 @@ use std::{collections::HashSet, fmt::Display, str::FromStr}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use blake3::Hash; use log::debug; use tokio::sync::OnceCell; diff --git a/yt/src/storage/video_database/getters.rs b/yt/src/storage/video_database/getters.rs index d8f9a3f..3470442 100644 --- a/yt/src/storage/video_database/getters.rs +++ b/yt/src/storage/video_database/getters.rs @@ -13,10 +13,10 @@ //! performance or convince requires. use std::{fs::File, path::PathBuf}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use blake3::Hash; use log::debug; -use sqlx::{query, QueryBuilder, Row, Sqlite}; +use sqlx::{QueryBuilder, Row, Sqlite, query}; use url::Url; use yt_dlp::wrapper::info_json::InfoJson; @@ -24,7 +24,7 @@ use crate::{ app::App, storage::{ subscriptions::Subscription, - video_database::{extractor_hash::ExtractorHash, Video}, + video_database::{Video, extractor_hash::ExtractorHash}, }, unreachable::Unreachable, }; diff --git a/yt/src/subscribe/mod.rs b/yt/src/subscribe/mod.rs index ef46627..7e5c68f 100644 --- a/yt/src/subscribe/mod.rs +++ b/yt/src/subscribe/mod.rs @@ -10,10 +10,10 @@ use std::str::FromStr; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use futures::FutureExt; use log::warn; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use tokio::io::{AsyncBufRead, AsyncBufReadExt}; use url::Url; use yt_dlp::wrapper::info_json::InfoType; @@ -21,7 +21,7 @@ use yt_dlp::wrapper::info_json::InfoType; use crate::{ app::App, storage::subscriptions::{ - add_subscription, check_url, get, remove_all, remove_subscription, Subscription, + Subscription, add_subscription, check_url, get, remove_all, remove_subscription, }, unreachable::Unreachable, }; @@ -76,7 +76,9 @@ pub async fn subscribe(app: &App, name: Option<String>, url: Url) -> Result<()> || url.as_str().ends_with("shorts/")) && url.as_str().contains("youtube.com") { - warn!("Your youtbe url does not seem like it actually tracks a channels playlist (videos, streams, shorts). Adding subscriptions for each of them..."); + warn!( + "Your youtbe url does not seem like it actually tracks a channels playlist (videos, streams, shorts). Adding subscriptions for each of them..." + ); let url = Url::parse(&(url.as_str().to_owned() + "/")) .unreachable("This was an url, it should stay one"); diff --git a/yt/src/update/mod.rs b/yt/src/update/mod.rs index 730e7c0..9d34498 100644 --- a/yt/src/update/mod.rs +++ b/yt/src/update/mod.rs @@ -21,8 +21,8 @@ use crate::{ storage::{ subscriptions::{self, Subscription}, video_database::{ - extractor_hash::ExtractorHash, getters::get_all_hashes, setters::add_video, Video, - VideoStatus, + Video, VideoStatus, extractor_hash::ExtractorHash, getters::get_all_hashes, + setters::add_video, }, }, videos::display::format_video::FormatVideo, diff --git a/yt/src/update/updater.rs b/yt/src/update/updater.rs index d54def8..70cdecd 100644 --- a/yt/src/update/updater.rs +++ b/yt/src/update/updater.rs @@ -1,13 +1,12 @@ -use std::io::{stderr, Write}; +use std::io::{Write, stderr}; use anyhow::{Context, Result}; use blake3::Hash; use futures::{ - stream::{self}, StreamExt, TryStreamExt, + stream::{self}, }; -use log::{debug, error, info, log_enabled, Level}; -use owo_colors::OwoColorize; +use log::{Level, debug, error, log_enabled}; use serde_json::json; use yt_dlp::{error::YtDlpError, process_ie_result, wrapper::info_json::InfoJson}; diff --git a/yt/src/videos/display/format_video.rs b/yt/src/videos/display/format_video.rs index 5c0320a..26f0f5b 100644 --- a/yt/src/videos/display/format_video.rs +++ b/yt/src/videos/display/format_video.rs @@ -32,7 +32,7 @@ pub trait FormatVideo { #[allow(clippy::type_complexity)] fn to_parts( - &self + &self, ) -> ( Self::Output, Self::Output, diff --git a/yt/src/videos/display/mod.rs b/yt/src/videos/display/mod.rs index 4a32e52..3f03ec0 100644 --- a/yt/src/videos/display/mod.rs +++ b/yt/src/videos/display/mod.rs @@ -18,7 +18,7 @@ use url::Url; use crate::{ app::App, select::selection_file::duration::Duration, - storage::video_database::{getters::get_video_opts, Video}, + storage::video_database::{Video, getters::get_video_opts}, }; use anyhow::{Context, Result}; diff --git a/yt/src/videos/mod.rs b/yt/src/videos/mod.rs index 156d01d..23613f7 100644 --- a/yt/src/videos/mod.rs +++ b/yt/src/videos/mod.rs @@ -9,18 +9,18 @@ // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. use anyhow::Result; -use display::{format_video::FormatVideo, FormattedVideo}; -use futures::{stream::FuturesUnordered, TryStreamExt}; +use display::{FormattedVideo, format_video::FormatVideo}; +use futures::{TryStreamExt, stream::FuturesUnordered}; use nucleo_matcher::{ - pattern::{CaseMatching, Normalization, Pattern}, Matcher, + pattern::{CaseMatching, Normalization, Pattern}, }; pub mod display; use crate::{ app::App, - storage::video_database::{getters::get_videos, VideoStatus}, + storage::video_database::{VideoStatus, getters::get_videos}, }; pub async fn query(app: &App, limit: Option<usize>, search_query: Option<String>) -> Result<()> { diff --git a/yt/src/watch/events/handlers/mod.rs b/yt/src/watch/events/handlers/mod.rs index 3f30812..8d4304b 100644 --- a/yt/src/watch/events/handlers/mod.rs +++ b/yt/src/watch/events/handlers/mod.rs @@ -14,10 +14,10 @@ use crate::{app::App, comments, description, storage::video_database::setters::s use super::MpvEventHandler; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use libmpv2::{ - events::{EndFileEvent, PlaylistEntryId}, Mpv, + events::{EndFileEvent, PlaylistEntryId}, }; use log::info; use tokio::process::Command; diff --git a/yt/src/watch/events/mod.rs b/yt/src/watch/events/mod.rs index 10e8bc8..7a08610 100644 --- a/yt/src/watch/events/mod.rs +++ b/yt/src/watch/events/mod.rs @@ -12,18 +12,18 @@ use std::collections::{HashMap, HashSet}; use anyhow::{Context, Result}; use libmpv2::{ - events::{Event, PlaylistEntryId}, EndFileReason, Mpv, + events::{Event, PlaylistEntryId}, }; use log::{debug, info}; use crate::{ app::App, storage::video_database::{ + VideoStatus, extractor_hash::ExtractorHash, getters::{get_video_by_hash, get_video_mpv_opts, get_videos}, setters::{set_state_change, set_video_watched}, - VideoStatus, }, unreachable::Unreachable, }; @@ -143,7 +143,10 @@ impl MpvEventHandler { let playlist_position = { let raw = mpv.get_property::<i64>("playlist-pos")?; if raw == -1 { - unreachable!("Tried to get the currently playing video hash, but failed to access the mpv 'playlist-pos' property! This is a bug, as this function should only be called, when a current video exists. Current state: '{:#?}'", self); + unreachable!( + "Tried to get the currently playing video hash, but failed to access the mpv 'playlist-pos' property! This is a bug, as this function should only be called, when a current video exists. Current state: '{:#?}'", + self + ); } else { usize::try_from(raw + offset).with_context(|| format!("Failed to calculate playlist position because of usize overflow: '{raw} + {offset}'"))? } diff --git a/yt/src/watch/events/playlist_handler.rs b/yt/src/watch/events/playlist_handler.rs index 232232d..8565ea8 100644 --- a/yt/src/watch/events/playlist_handler.rs +++ b/yt/src/watch/events/playlist_handler.rs @@ -11,7 +11,7 @@ use std::collections::HashMap; use anyhow::Result; -use libmpv2::{events::PlaylistEntryId, mpv_node::MpvNode, Mpv}; +use libmpv2::{Mpv, events::PlaylistEntryId, mpv_node::MpvNode}; use crate::storage::video_database::extractor_hash::ExtractorHash; diff --git a/yt/src/watch/mod.rs b/yt/src/watch/mod.rs index 7247999..630de68 100644 --- a/yt/src/watch/mod.rs +++ b/yt/src/watch/mod.rs @@ -12,14 +12,14 @@ use std::{collections::HashMap, time::Duration}; use anyhow::{Context, Result}; use events::{IdleCheckOutput, MpvEventHandler}; -use libmpv2::{events::EventContext, Mpv}; +use libmpv2::{Mpv, events::EventContext}; use log::{debug, info, trace, warn}; use tokio::time; use crate::{ app::App, cache::maintain, - storage::video_database::{extractor_hash::ExtractorHash, getters::get_videos, VideoStatus}, + storage::video_database::{VideoStatus, extractor_hash::ExtractorHash, getters::get_videos}, unreachable::Unreachable, }; @@ -53,12 +53,9 @@ pub async fn watch(app: &App) -> Result<()> { let config_path = &app.config.paths.mpv_config_path; if config_path.try_exists()? { info!("Found mpv.conf at '{}'!", config_path.display()); - mpv.command( - "load-config-file", - &[config_path - .to_str() - .context("Failed to parse the config path is utf8-stringt")?], - )?; + mpv.command("load-config-file", &[config_path + .to_str() + .context("Failed to parse the config path is utf8-stringt")?])?; } else { warn!( "Did not find a mpv.conf file at '{}'", @@ -69,12 +66,9 @@ pub async fn watch(app: &App) -> Result<()> { let input_path = &app.config.paths.mpv_input_path; if input_path.try_exists()? { info!("Found mpv.input.conf at '{}'!", input_path.display()); - mpv.command( - "load-input-conf", - &[input_path - .to_str() - .context("Failed to parse the input path as utf8 string")?], - )?; + mpv.command("load-input-conf", &[input_path + .to_str() + .context("Failed to parse the input path as utf8 string")?])?; } else { warn!( "Did not find a mpv.input.conf file at '{}'", @@ -126,8 +120,11 @@ pub async fn watch(app: &App) -> Result<()> { have_warned.1 = marked_watched; } } else { - warn!("There is nothing to watch yet, but still {} videos marked as to be watched. \ - Will idle, until they become available", marked_watched); + warn!( + "There is nothing to watch yet, but still {} videos marked as to be watched. \ + Will idle, until they become available", + marked_watched + ); have_warned = (true, marked_watched); } time::sleep(Duration::from_secs(10)).await; |
