diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 7c45cf7..a4a334a 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -203,7 +203,7 @@ impl PlayerProxy { let (path, stream) = (path.to_owned(), stream.to_owned()); if path == stream { Command::new("ffmpegthumbnailer") - .args(&["-m", "-cjpeg", "-s0", "-o-", "-i"]) + .args(["-m", "-cjpeg", "-s0", "-o-", "-i"]) .arg(&stream) .output() .or(async { @@ -218,7 +218,7 @@ impl PlayerProxy { 'ytdl: { for cmd in ["yt-dlp", "yt-dlp_x86", "youtube-dl"] { let thumb = Command::new(cmd) - .args(&["--no-warnings", "--get-thumbnail"]) + .args(["--no-warnings", "--get-thumbnail"]) .arg(&path) .output() .or(async { @@ -232,7 +232,7 @@ impl PlayerProxy { .map(|s| s.trim_matches(char::is_whitespace).to_owned()) .ok() }); - if let Some(..) = thumb { + if thumb.is_some() { break 'ytdl thumb; } } diff --git a/src/mpv.rs b/src/mpv.rs index f5588dd..7b1d8cd 100644 --- a/src/mpv.rs +++ b/src/mpv.rs @@ -16,183 +16,155 @@ pub(crate) const REPLY_USERDATA: u64 = u64::from_ne_bytes(*b"mpvmpris"); pub(crate) use capi::mpv_format::*; macro_rules! assert_cstr { - ($s:expr) => { - ({ - let s = $s; - debug_assert_eq!(s.as_bytes()[s.len() - 1], '\0' as u8); - s - }) - }; + ($s:expr) => {{ + let s = $s; + debug_assert_eq!(s.as_bytes()[s.len() - 1], '\0' as u8); + s + }}; } pub(crate) use assert_cstr; macro_rules! command { - ($ctx:expr, $($arg:expr),+ $(,)?) => { - ({ - use $crate::mpv::{assert_cstr,REPLY_USERDATA,capi::mpv_command_async}; - use $crate::ptr; - let (ctx, args) = ($ctx, ptr::from_mut(&mut [$(assert_cstr!($arg).as_ptr()),+, ptr::null()]).cast()); - unsafe { - mpv_command_async(ctx, REPLY_USERDATA, args); - } - }) - }; + ($ctx:expr, $($arg:expr),+ $(,)?) => {{ + use $crate::mpv::{assert_cstr,REPLY_USERDATA,capi::mpv_command_async}; + use $crate::ptr; + let (ctx, args) = ($ctx, ptr::from_mut(&mut [$(assert_cstr!($arg).as_ptr()),+, ptr::null()]).cast()); + unsafe { + mpv_command_async(ctx, REPLY_USERDATA, args); + } + }}; } pub(crate) use command; macro_rules! free { - ($value:expr) => { - ({ - use $crate::mpv::capi::mpv_free; - let value: *const _ = $value; - unsafe { - mpv_free(value.cast_mut().cast()); - } - }) - }; + ($value:expr) => {{ + use $crate::mpv::capi::mpv_free; + let value: *const _ = $value; + unsafe { + mpv_free(value.cast_mut().cast()); + } + }}; } pub(crate) use free; macro_rules! get_property { - ($ctx:expr, $prop:expr, $format:expr, $type:ty) => { - ({ - use $crate::mpv::{assert_cstr, capi::mpv_get_property}; - use $crate::ptr; - let mut rtrn = <$type>::default(); - let (ctx, prop, format, data) = ( - $ctx, - assert_cstr!($prop).as_ptr().cast(), - $format, - ptr::from_mut(&mut rtrn).cast(), - ); - unsafe { - mpv_get_property(ctx, prop, format, data); - } - rtrn - }) - }; + ($ctx:expr, $prop:expr, $format:expr, $type:ty) => {{ + use $crate::mpv::{assert_cstr, capi::mpv_get_property}; + use $crate::ptr; + let mut rtrn = <$type>::default(); + let (ctx, prop, format, data) = ( + $ctx, + assert_cstr!($prop).as_ptr().cast(), + $format, + ptr::from_mut(&mut rtrn).cast(), + ); + unsafe { + mpv_get_property(ctx, prop, format, data); + } + rtrn + }}; } pub(crate) use get_property; macro_rules! get_property_bool { - ($ctx:expr, $prop:expr) => { - ({ - use std::ffi::c_int; - use $crate::mpv::{get_property, MPV_FORMAT_FLAG}; - get_property!($ctx, $prop, MPV_FORMAT_FLAG, c_int) != 0 - }) - }; + ($ctx:expr, $prop:expr) => {{ + use std::ffi::c_int; + use $crate::mpv::{get_property, MPV_FORMAT_FLAG}; + get_property!($ctx, $prop, MPV_FORMAT_FLAG, c_int) != 0 + }}; } pub(crate) use get_property_bool; macro_rules! get_property_int { - ($ctx:expr, $prop:expr) => { - ({ - use $crate::mpv::{get_property, MPV_FORMAT_INT64}; - get_property!($ctx, $prop, MPV_FORMAT_INT64, i64) - }) - }; + ($ctx:expr, $prop:expr) => {{ + use $crate::mpv::{get_property, MPV_FORMAT_INT64}; + get_property!($ctx, $prop, MPV_FORMAT_INT64, i64) + }}; } pub(crate) use get_property_int; macro_rules! get_property_float { - ($ctx:expr, $prop:expr) => { - ({ - use $crate::mpv::{get_property, MPV_FORMAT_DOUBLE}; - get_property!($ctx, $prop, MPV_FORMAT_DOUBLE, f64) - }) - }; + ($ctx:expr, $prop:expr) => {{ + use $crate::mpv::{get_property, MPV_FORMAT_DOUBLE}; + get_property!($ctx, $prop, MPV_FORMAT_DOUBLE, f64) + }}; } pub(crate) use get_property_float; macro_rules! get_property_string { - ($ctx:expr, $prop:expr) => { - ({ - use std::ffi::CStr; - use $crate::mpv::{capi::mpv_get_property_string, free}; - let (ctx, prop) = ($ctx, $prop.as_ptr().cast()); - let cstr = unsafe { mpv_get_property_string(ctx, prop) }; - if cstr.is_null() { - "" - } else { - scopeguard::guard(unsafe { CStr::from_ptr(cstr) }, |v| free!(v.as_ptr())) - .to_str() - .unwrap_or_default() - } - }) - }; + ($ctx:expr, $prop:expr) => {{ + use std::ffi::CStr; + use $crate::mpv::{capi::mpv_get_property_string, free}; + let (ctx, prop) = ($ctx, $prop.as_ptr().cast()); + let cstr = unsafe { mpv_get_property_string(ctx, prop) }; + if cstr.is_null() { + "" + } else { + scopeguard::guard(unsafe { CStr::from_ptr(cstr) }, |v| free!(v.as_ptr())) + .to_str() + .unwrap_or_default() + } + }}; } pub(crate) use get_property_string; macro_rules! set_property { - ($ctx:expr, $prop:expr, $format:expr, $data:expr) => { - ({ - use $crate::mpv::{assert_cstr, capi::mpv_set_property_async, REPLY_USERDATA}; - use $crate::ptr; - let (ctx, prop, format, data) = ( - $ctx, - assert_cstr!($prop).as_ptr().cast(), - $format, - ptr::from_mut(&mut $data).cast(), - ); - unsafe { - mpv_set_property_async(ctx, REPLY_USERDATA, prop, format, data); - } - }) - }; + ($ctx:expr, $prop:expr, $format:expr, $data:expr) => {{ + use $crate::mpv::{assert_cstr, capi::mpv_set_property_async, REPLY_USERDATA}; + use $crate::ptr; + let (ctx, prop, format, data) = ( + $ctx, + assert_cstr!($prop).as_ptr().cast(), + $format, + ptr::from_mut(&mut $data).cast(), + ); + unsafe { + mpv_set_property_async(ctx, REPLY_USERDATA, prop, format, data); + } + }}; } pub(crate) use set_property; macro_rules! set_property_bool { - ($ctx:expr, $prop:expr, $value:expr) => { - ({ - use std::ffi::c_int; - use $crate::mpv::{set_property, MPV_FORMAT_FLAG}; - set_property!($ctx, $prop, MPV_FORMAT_FLAG, $value as c_int) - }) - }; + ($ctx:expr, $prop:expr, $value:expr) => {{ + use std::ffi::c_int; + use $crate::mpv::{set_property, MPV_FORMAT_FLAG}; + set_property!($ctx, $prop, MPV_FORMAT_FLAG, $value as c_int) + }}; } pub(crate) use set_property_bool; macro_rules! set_property_float { - ($ctx:expr, $prop:expr, $data:expr) => { - ({ - use $crate::mpv::{set_property, MPV_FORMAT_DOUBLE}; - set_property!($ctx, $prop, MPV_FORMAT_DOUBLE, $data as f64) - }) - }; + ($ctx:expr, $prop:expr, $data:expr) => {{ + use $crate::mpv::{set_property, MPV_FORMAT_DOUBLE}; + set_property!($ctx, $prop, MPV_FORMAT_DOUBLE, $data as f64) + }}; } pub(crate) use set_property_float; macro_rules! set_property_string { - ($ctx:expr, $prop:expr, $data:expr) => { - ({ - use $crate::mpv::{assert_cstr, set_property, MPV_FORMAT_STRING}; - set_property!($ctx, $prop, MPV_FORMAT_STRING, assert_cstr!($data)) - }) - }; + ($ctx:expr, $prop:expr, $data:expr) => {{ + use $crate::mpv::{assert_cstr, set_property, MPV_FORMAT_STRING}; + set_property!($ctx, $prop, MPV_FORMAT_STRING, assert_cstr!($data)) + }}; } pub(crate) use set_property_string; macro_rules! observe_property_format { - ($ctx:expr, $prop:expr, $format:expr) => { - ({ - use $crate::mpv::{assert_cstr, capi::mpv_observe_property, REPLY_USERDATA}; - let (ctx, prop, format) = ($ctx, assert_cstr!($prop).as_ptr().cast(), $format); - unsafe { - mpv_observe_property(ctx, REPLY_USERDATA, prop, format); - } - }) - }; + ($ctx:expr, $prop:expr, $format:expr) => {{ + use $crate::mpv::{assert_cstr, capi::mpv_observe_property, REPLY_USERDATA}; + let (ctx, prop, format) = ($ctx, assert_cstr!($prop).as_ptr().cast(), $format); + unsafe { + mpv_observe_property(ctx, REPLY_USERDATA, prop, format); + } + }}; } pub(crate) use observe_property_format; macro_rules! observe_properties { - ($ctx:expr, $($prop:expr),+ $(,)?) => { - ({ - use $crate::mpv::{observe_property_format, MPV_FORMAT_NONE}; - $(observe_property_format!($ctx, $prop, MPV_FORMAT_NONE));+ - }) - }; + ($ctx:expr, $($prop:expr),+ $(,)?) => {{ + use $crate::mpv::{observe_property_format, MPV_FORMAT_NONE}; + $(observe_property_format!($ctx, $prop, MPV_FORMAT_NONE));+ + }}; } pub(crate) use observe_properties; diff --git a/src/plugin.rs b/src/plugin.rs index b454dd1..8a17768 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -1,3 +1,5 @@ +#![allow(clippy::not_unsafe_ptr_arg_deref)] // mpv_wait_event + use std::{ ffi::{c_int, CStr}, process,