about summary refs log tree commit diff stats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-02-16 18:21:02 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-02-16 18:21:02 +0100
commit55a94110287ad2b1a55953febac48422a9d3ba89 (patch)
treeca57ff2df49383e3f34a31df8c7c7e3d06470ba1 /crates
parentrefactor(yt/): Use the new `termsize` and `uu_fmt` crates (diff)
downloadyt-55a94110287ad2b1a55953febac48422a9d3ba89.zip
style(treewide): Re-format
Diffstat (limited to 'crates')
-rw-r--r--crates/libmpv2/examples/events.rs34
-rw-r--r--crates/libmpv2/examples/opengl.rs19
-rw-r--r--crates/libmpv2/src/lib.rs2
-rw-r--r--crates/libmpv2/src/mpv.rs2
-rw-r--r--crates/libmpv2/src/mpv/errors.rs70
-rw-r--r--crates/libmpv2/src/mpv/events.rs2
-rw-r--r--crates/libmpv2/src/mpv/protocol.rs8
-rw-r--r--crates/libmpv2/src/mpv/render.rs4
-rw-r--r--crates/libmpv2/src/tests.rs24
-rw-r--r--crates/termsize/src/nix.rs2
-rw-r--r--crates/termsize/src/win.rs2
-rw-r--r--crates/yt_dlp/src/lib.rs6
-rw-r--r--crates/yt_dlp/src/logging.rs5
-rw-r--r--crates/yt_dlp/src/tests.rs2
-rw-r--r--crates/yt_dlp/src/wrapper/info_json.rs2
-rw-r--r--crates/yt_dlp/src/wrapper/yt_dlp_options.rs2
16 files changed, 112 insertions, 74 deletions
diff --git a/crates/libmpv2/examples/events.rs b/crates/libmpv2/examples/events.rs
index 8f7c79f..e502d5c 100644
--- a/crates/libmpv2/examples/events.rs
+++ b/crates/libmpv2/examples/events.rs
@@ -45,25 +45,27 @@ fn main() -> Result<()> {
             // Trigger `Event::EndFile`.
             mpv.command("playlist-next", &["force"]).unwrap();
         });
-        scope.spawn(move |_| loop {
-            let ev = ev_ctx.wait_event(600.).unwrap_or(Err(Error::Null));
+        scope.spawn(move |_| {
+            loop {
+                let ev = ev_ctx.wait_event(600.).unwrap_or(Err(Error::Null));
 
-            match ev {
-                Ok(Event::EndFile(r)) => {
-                    println!("Exiting! Reason: {:?}", r);
-                    break;
-                }
+                match ev {
+                    Ok(Event::EndFile(r)) => {
+                        println!("Exiting! Reason: {:?}", r);
+                        break;
+                    }
 
-                Ok(Event::PropertyChange {
-                    name: "demuxer-cache-state",
-                    change: PropertyData::Node(mpv_node),
-                    ..
-                }) => {
-                    let ranges = seekable_ranges(mpv_node);
-                    println!("Seekable ranges updated: {:?}", ranges);
+                    Ok(Event::PropertyChange {
+                        name: "demuxer-cache-state",
+                        change: PropertyData::Node(mpv_node),
+                        ..
+                    }) => {
+                        let ranges = seekable_ranges(mpv_node);
+                        println!("Seekable ranges updated: {:?}", ranges);
+                    }
+                    Ok(e) => println!("Event triggered: {:?}", e),
+                    Err(e) => println!("Event errored: {:?}", e),
                 }
-                Ok(e) => println!("Event triggered: {:?}", e),
-                Err(e) => println!("Event errored: {:?}", e),
             }
         });
     })
diff --git a/crates/libmpv2/examples/opengl.rs b/crates/libmpv2/examples/opengl.rs
index 1de307f..8eb9647 100644
--- a/crates/libmpv2/examples/opengl.rs
+++ b/crates/libmpv2/examples/opengl.rs
@@ -9,8 +9,8 @@
 // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 
 use libmpv2::{
-    render::{OpenGLInitParams, RenderContext, RenderParam, RenderParamApiType},
     Mpv,
+    render::{OpenGLInitParams, RenderContext, RenderParam, RenderParamApiType},
 };
 use std::{env, ffi::c_void};
 
@@ -38,16 +38,13 @@ fn main() {
         Ok(())
     })
     .unwrap();
-    let mut render_context = RenderContext::new(
-        unsafe { mpv.ctx.as_mut() },
-        vec![
-            RenderParam::ApiType(RenderParamApiType::OpenGl),
-            RenderParam::InitParams(OpenGLInitParams {
-                get_proc_address,
-                ctx: video,
-            }),
-        ],
-    )
+    let mut render_context = RenderContext::new(unsafe { mpv.ctx.as_mut() }, vec![
+        RenderParam::ApiType(RenderParamApiType::OpenGl),
+        RenderParam::InitParams(OpenGLInitParams {
+            get_proc_address,
+            ctx: video,
+        }),
+    ])
     .expect("Failed creating render context");
 
     event_subsystem
diff --git a/crates/libmpv2/src/lib.rs b/crates/libmpv2/src/lib.rs
index 4d8d18a..d47e620 100644
--- a/crates/libmpv2/src/lib.rs
+++ b/crates/libmpv2/src/lib.rs
@@ -67,8 +67,8 @@ pub mod mpv_error {
     pub use libmpv2_sys::mpv_error_MPV_ERROR_INVALID_PARAMETER as InvalidParameter;
     pub use libmpv2_sys::mpv_error_MPV_ERROR_LOADING_FAILED as LoadingFailed;
     pub use libmpv2_sys::mpv_error_MPV_ERROR_NOMEM as NoMem;
-    pub use libmpv2_sys::mpv_error_MPV_ERROR_NOTHING_TO_PLAY as NothingToPlay;
     pub use libmpv2_sys::mpv_error_MPV_ERROR_NOT_IMPLEMENTED as NotImplemented;
+    pub use libmpv2_sys::mpv_error_MPV_ERROR_NOTHING_TO_PLAY as NothingToPlay;
     pub use libmpv2_sys::mpv_error_MPV_ERROR_OPTION_ERROR as OptionError;
     pub use libmpv2_sys::mpv_error_MPV_ERROR_OPTION_FORMAT as OptionFormat;
     pub use libmpv2_sys::mpv_error_MPV_ERROR_OPTION_NOT_FOUND as OptionNotFound;
diff --git a/crates/libmpv2/src/mpv.rs b/crates/libmpv2/src/mpv.rs
index 6f26d0f..7ac1b43 100644
--- a/crates/libmpv2/src/mpv.rs
+++ b/crates/libmpv2/src/mpv.rs
@@ -184,7 +184,7 @@ pub mod mpv_node {
 
     pub mod sys_node {
         use super::{DropWrapper, MpvNode, MpvNodeArrayIter, MpvNodeMapIter};
-        use crate::{mpv_error, mpv_format, Error, Result};
+        use crate::{Error, Result, mpv_error, mpv_format};
         use std::rc::Rc;
 
         #[derive(Debug, Clone)]
diff --git a/crates/libmpv2/src/mpv/errors.rs b/crates/libmpv2/src/mpv/errors.rs
index 4b28fb3..a2d3dd8 100644
--- a/crates/libmpv2/src/mpv/errors.rs
+++ b/crates/libmpv2/src/mpv/errors.rs
@@ -39,10 +39,17 @@ impl Display for Error {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         match self {
             Error::Loadfile { error } => write!(f, "loading file failed: {error}"),
-            Error::VersionMismatch { linked, loaded } => write!(f, "version mismatch detected! Linked version ({linked}) is unequal to the loaded version ({loaded})"),
+            Error::VersionMismatch { linked, loaded } => write!(
+                f,
+                "version mismatch detected! Linked version ({linked}) is unequal to the loaded version ({loaded})"
+            ),
             Error::InvalidUtf8 => f.write_str("invalid utf8 returned"),
             Error::Null => f.write_str("null pointer returned"),
-            Error::Raw(raw) => write!(f, include_str!("./raw_error_warning.txt"), to_string_mpv_error(*(raw))),
+            Error::Raw(raw) => write!(
+                f,
+                include_str!("./raw_error_warning.txt"),
+                to_string_mpv_error(*(raw))
+            ),
         }
     }
 }
@@ -85,35 +92,70 @@ fn to_string_mpv_error_raw(num: crate::MpvError) -> (&'static str, &'static str)
 
         mpv_error::NoMem => ("Memory allocation failed.", ""),
 
-        mpv_error::Uninitialized => ("The mpv core wasn't configured and initialized yet", " See the notes in mpv_create()."),
+        mpv_error::Uninitialized => (
+            "The mpv core wasn't configured and initialized yet",
+            " See the notes in mpv_create().",
+        ),
 
-        mpv_error::InvalidParameter => ("Generic catch-all error if a parameter is set to an invalid or unsupported value.", "This is used if there is no better error code."),
+        mpv_error::InvalidParameter => (
+            "Generic catch-all error if a parameter is set to an invalid or unsupported value.",
+            "This is used if there is no better error code.",
+        ),
 
         mpv_error::OptionNotFound => ("Trying to set an option that doesn't exist.", ""),
-        mpv_error::OptionFormat => ("Trying to set an option using an unsupported MPV_FORMAT.", ""),
-        mpv_error::OptionError => ("Setting the option failed", " Typically this happens if the provided option value could not be parsed."),
+        mpv_error::OptionFormat => (
+            "Trying to set an option using an unsupported MPV_FORMAT.",
+            "",
+        ),
+        mpv_error::OptionError => (
+            "Setting the option failed",
+            " Typically this happens if the provided option value could not be parsed.",
+        ),
 
         mpv_error::PropertyNotFound => ("The accessed property doesn't exist.", ""),
-        mpv_error::PropertyFormat => ("Trying to set or get a property using an unsupported MPV_FORMAT.", ""),
-        mpv_error::PropertyUnavailable => ("The property exists, but is not available", "This usually happens when the associated subsystem is not active, e.g. querying audio parameters while audio is disabled."),
+        mpv_error::PropertyFormat => (
+            "Trying to set or get a property using an unsupported MPV_FORMAT.",
+            "",
+        ),
+        mpv_error::PropertyUnavailable => (
+            "The property exists, but is not available",
+            "This usually happens when the associated subsystem is not active, e.g. querying audio parameters while audio is disabled.",
+        ),
         mpv_error::PropertyError => ("Error setting or getting a property.", ""),
 
-        mpv_error::Command => ("General error when running a command with mpv_command and similar.", ""),
+        mpv_error::Command => (
+            "General error when running a command with mpv_command and similar.",
+            "",
+        ),
 
-        mpv_error::LoadingFailed => ("Generic error on loading (usually used with mpv_event_end_file.error).", ""),
+        mpv_error::LoadingFailed => (
+            "Generic error on loading (usually used with mpv_event_end_file.error).",
+            "",
+        ),
 
         mpv_error::AoInitFailed => ("Initializing the audio output failed.", ""),
         mpv_error::VoInitFailed => ("Initializing the video output failed.", ""),
 
-        mpv_error::NothingToPlay => ("There was no audio or video data to play", "This also happens if the file was recognized, but did not contain any audio or video streams, or no streams were selected."),
+        mpv_error::NothingToPlay => (
+            "There was no audio or video data to play",
+            "This also happens if the file was recognized, but did not contain any audio or video streams, or no streams were selected.",
+        ),
 
-        mpv_error::UnknownFormat => ("     * When trying to load the file, the file format could not be determined, or the file was too broken to open it.", ""),
+        mpv_error::UnknownFormat => (
+            "     * When trying to load the file, the file format could not be determined, or the file was too broken to open it.",
+            "",
+        ),
 
-        mpv_error::Generic => ("Generic error for signaling that certain system requirements are not fulfilled.", ""),
+        mpv_error::Generic => (
+            "Generic error for signaling that certain system requirements are not fulfilled.",
+            "",
+        ),
         mpv_error::NotImplemented => ("The API function which was called is a stub only", ""),
         mpv_error::Unsupported => ("Unspecified error.", ""),
 
-        mpv_error::Success => unreachable!("This is not an error. It's just here, to ensure that the 0 case marks an success'"),
+        mpv_error::Success => unreachable!(
+            "This is not an error. It's just here, to ensure that the 0 case marks an success'"
+        ),
         _ => unreachable!("Mpv seems to have changed it's constants."),
     }
 }
diff --git a/crates/libmpv2/src/mpv/events.rs b/crates/libmpv2/src/mpv/events.rs
index 6fb4683..ea105d4 100644
--- a/crates/libmpv2/src/mpv/events.rs
+++ b/crates/libmpv2/src/mpv/events.rs
@@ -11,7 +11,7 @@
 use crate::mpv_node::sys_node::SysMpvNode;
 use crate::{mpv::mpv_err, *};
 
-use std::ffi::{c_void, CString};
+use std::ffi::{CString, c_void};
 use std::os::raw as ctype;
 use std::ptr::NonNull;
 use std::slice;
diff --git a/crates/libmpv2/src/mpv/protocol.rs b/crates/libmpv2/src/mpv/protocol.rs
index 31a5933..c4f0e2f 100644
--- a/crates/libmpv2/src/mpv/protocol.rs
+++ b/crates/libmpv2/src/mpv/protocol.rs
@@ -17,7 +17,7 @@ use std::os::raw as ctype;
 use std::panic;
 use std::panic::RefUnwindSafe;
 use std::slice;
-use std::sync::{atomic::Ordering, Mutex};
+use std::sync::{Mutex, atomic::Ordering};
 
 impl Mpv {
     /// Create a context with which custom protocols can be registered.
@@ -101,11 +101,7 @@ where
         let slice = slice::from_raw_parts_mut(buf, nbytes as _);
         ((*data).read_fn)(&mut *(*data).cookie, slice)
     });
-    if let Ok(ret) = ret {
-        ret
-    } else {
-        -1
-    }
+    if let Ok(ret) = ret { ret } else { -1 }
 }
 
 unsafe extern "C" fn seek_wrapper<T, U>(cookie: *mut ctype::c_void, offset: i64) -> i64
diff --git a/crates/libmpv2/src/mpv/render.rs b/crates/libmpv2/src/mpv/render.rs
index c3f2dc9..6457048 100644
--- a/crates/libmpv2/src/mpv/render.rs
+++ b/crates/libmpv2/src/mpv/render.rs
@@ -8,9 +8,9 @@
 // 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 crate::{mpv::mpv_err, Error, Result};
+use crate::{Error, Result, mpv::mpv_err};
 use std::collections::HashMap;
-use std::ffi::{c_void, CStr};
+use std::ffi::{CStr, c_void};
 use std::os::raw::c_int;
 use std::ptr;
 
diff --git a/crates/libmpv2/src/tests.rs b/crates/libmpv2/src/tests.rs
index 68753fc..6106eb2 100644
--- a/crates/libmpv2/src/tests.rs
+++ b/crates/libmpv2/src/tests.rs
@@ -54,10 +54,10 @@ fn properties() {
         0.6,
         f64::round(subg * f64::powi(10.0, 4)) / f64::powi(10.0, 4)
     );
-    mpv.command(
-        "loadfile",
-        &["test-data/speech_12kbps_mb.wav", "append-play"],
-    )
+    mpv.command("loadfile", &[
+        "test-data/speech_12kbps_mb.wav",
+        "append-play",
+    ])
     .unwrap();
     thread::sleep(Duration::from_millis(250));
 
@@ -185,10 +185,10 @@ fn events() {
 fn node_map() {
     let mpv = Mpv::new().unwrap();
 
-    mpv.command(
-        "loadfile",
-        &["test-data/speech_12kbps_mb.wav", "append-play"],
-    )
+    mpv.command("loadfile", &[
+        "test-data/speech_12kbps_mb.wav",
+        "append-play",
+    ])
     .unwrap();
 
     thread::sleep(Duration::from_millis(250));
@@ -217,10 +217,10 @@ fn node_map() {
 fn node_array() -> Result<()> {
     let mpv = Mpv::new()?;
 
-    mpv.command(
-        "loadfile",
-        &["test-data/speech_12kbps_mb.wav", "append-play"],
-    )
+    mpv.command("loadfile", &[
+        "test-data/speech_12kbps_mb.wav",
+        "append-play",
+    ])
     .unwrap();
 
     thread::sleep(Duration::from_millis(250));
diff --git a/crates/termsize/src/nix.rs b/crates/termsize/src/nix.rs
index e35aa6b..d672f54 100644
--- a/crates/termsize/src/nix.rs
+++ b/crates/termsize/src/nix.rs
@@ -11,7 +11,7 @@
 use std::io::IsTerminal;
 
 use self::super::Size;
-use libc::{c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ};
+use libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort, ioctl};
 
 /// A representation of the size of the current terminal
 #[repr(C)]
diff --git a/crates/termsize/src/win.rs b/crates/termsize/src/win.rs
index 666a0fc..72d8433 100644
--- a/crates/termsize/src/win.rs
+++ b/crates/termsize/src/win.rs
@@ -13,7 +13,7 @@ use std::ptr;
 use winapi::um::{
     fileapi::{CreateFileA, OPEN_EXISTING},
     handleapi::INVALID_HANDLE_VALUE,
-    wincon::{GetConsoleScreenBufferInfo, CONSOLE_SCREEN_BUFFER_INFO},
+    wincon::{CONSOLE_SCREEN_BUFFER_INFO, GetConsoleScreenBufferInfo},
     winnt::{FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE},
 };
 
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs
index 129d4db..40610c2 100644
--- a/crates/yt_dlp/src/lib.rs
+++ b/crates/yt_dlp/src/lib.rs
@@ -22,12 +22,12 @@ use crate::{duration::Duration, logging::setup_logging, wrapper::info_json::Info
 
 use bytes::Bytes;
 use error::YtDlpError;
-use log::{debug, info, log_enabled, Level};
+use log::{Level, debug, info, log_enabled};
 use pyo3::types::{PyString, PyTuple, PyTupleMethods};
 use pyo3::{
-    pyfunction,
+    Bound, PyAny, PyResult, Python, pyfunction,
     types::{PyAnyMethods, PyDict, PyDictMethods, PyList, PyListMethods, PyModule},
-    wrap_pyfunction, Bound, PyAny, PyResult, Python,
+    wrap_pyfunction,
 };
 use serde::Serialize;
 use serde_json::{Map, Value};
diff --git a/crates/yt_dlp/src/logging.rs b/crates/yt_dlp/src/logging.rs
index 670fc1c..e731502 100644
--- a/crates/yt_dlp/src/logging.rs
+++ b/crates/yt_dlp/src/logging.rs
@@ -17,10 +17,11 @@
 
 use std::ffi::CString;
 
-use log::{logger, Level, MetadataBuilder, Record};
+use log::{Level, MetadataBuilder, Record, logger};
 use pyo3::{
+    Bound, PyAny, PyResult, Python,
     prelude::{PyAnyMethods, PyListMethods, PyModuleMethods},
-    pyfunction, wrap_pyfunction, Bound, PyAny, PyResult, Python,
+    pyfunction, wrap_pyfunction,
 };
 
 /// Consume a Python `logging.LogRecord` and emit a Rust `Log` instead.
diff --git a/crates/yt_dlp/src/tests.rs b/crates/yt_dlp/src/tests.rs
index b072348..91b6626 100644
--- a/crates/yt_dlp/src/tests.rs
+++ b/crates/yt_dlp/src/tests.rs
@@ -10,7 +10,7 @@
 
 use std::sync::LazyLock;
 
-use serde_json::{json, Value};
+use serde_json::{Value, json};
 use url::Url;
 
 static YT_OPTS: LazyLock<serde_json::Map<String, Value>> = LazyLock::new(|| {
diff --git a/crates/yt_dlp/src/wrapper/info_json.rs b/crates/yt_dlp/src/wrapper/info_json.rs
index 720740c..4b80245 100644
--- a/crates/yt_dlp/src/wrapper/info_json.rs
+++ b/crates/yt_dlp/src/wrapper/info_json.rs
@@ -13,7 +13,7 @@
 
 use std::{collections::HashMap, path::PathBuf};
 
-use pyo3::{types::PyDict, Bound, PyResult, Python};
+use pyo3::{Bound, PyResult, Python, types::PyDict};
 use serde::{Deserialize, Deserializer, Serialize};
 use serde_json::Value;
 use url::Url;
diff --git a/crates/yt_dlp/src/wrapper/yt_dlp_options.rs b/crates/yt_dlp/src/wrapper/yt_dlp_options.rs
index c2a86df..25595b5 100644
--- a/crates/yt_dlp/src/wrapper/yt_dlp_options.rs
+++ b/crates/yt_dlp/src/wrapper/yt_dlp_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 pyo3::{types::PyDict, Bound, PyResult, Python};
+use pyo3::{Bound, PyResult, Python, types::PyDict};
 use serde::Serialize;
 
 use crate::json_loads;