fmt and mpv conf
This commit is contained in:
parent
473b98b0f3
commit
b3eb220359
|
@ -1,8 +1,8 @@
|
||||||
use std::process::Stdio;
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use tokio::io::{AsyncRead, AsyncBufReadExt, BufReader};
|
|
||||||
use tokio::process::Command;
|
|
||||||
use libmpv::{FileState, Mpv};
|
use libmpv::{FileState, Mpv};
|
||||||
|
use std::process::Stdio;
|
||||||
|
use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader};
|
||||||
|
use tokio::process::Command;
|
||||||
use tokio_stream::wrappers::LinesStream;
|
use tokio_stream::wrappers::LinesStream;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -10,23 +10,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||||
let mut subprocs: Vec<_> = args
|
let mut subprocs: Vec<_> = args
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| Command::new(arg)
|
.map(|arg| {
|
||||||
.stdout(Stdio::piped())
|
Command::new(arg)
|
||||||
.spawn()
|
.stdout(Stdio::piped())
|
||||||
.unwrap_or_else(|e| panic!("couldn't spawn {arg}: {e:?}")))
|
.spawn()
|
||||||
|
.unwrap_or_else(|e| panic!("couldn't spawn {arg}: {e:?}"))
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let stdin_box: Box<dyn AsyncRead + Unpin> = Box::new(tokio::io::stdin());
|
let stdin_box: Box<dyn AsyncRead + Unpin> = Box::new(tokio::io::stdin());
|
||||||
let mut combined = futures::stream::select_all(Some(LinesStream::new(BufReader::new(stdin_box).lines())));
|
let mut combined =
|
||||||
|
futures::stream::select_all(Some(LinesStream::new(BufReader::new(stdin_box).lines())));
|
||||||
for subproc in &mut subprocs {
|
for subproc in &mut subprocs {
|
||||||
let stdout_box: Box<dyn AsyncRead + Unpin> = Box::new(subproc.stdout.take().unwrap());
|
let stdout_box: Box<dyn AsyncRead + Unpin> = Box::new(subproc.stdout.take().unwrap());
|
||||||
combined.push(LinesStream::new(BufReader::new(stdout_box).lines()));
|
combined.push(LinesStream::new(BufReader::new(stdout_box).lines()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mpv = Mpv::new().expect("couldn't create mpv");
|
let mpv = Mpv::new().expect("couldn't create mpv");
|
||||||
while let Some(Ok(line)) = combined.next().await {
|
|
||||||
mpv.playlist_load_files(&[(&line, FileState::AppendPlay, None)]).expect("couldn't load path");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
|
let home = std::env::home_dir().unwrap();
|
||||||
|
mpv.load_config(home.join(".config/mpv/mpv.conf").to_str().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
while let Some(Ok(line)) = combined.next().await {
|
||||||
|
mpv.playlist_load_files(&[(&line, FileState::AppendPlay, None)])
|
||||||
|
.expect("couldn't load path");
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
use std::io::Write;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use matrix_sdk::{Client, config::SyncSettings, ruma::{
|
|
||||||
OwnedRoomId, OwnedUserId,
|
|
||||||
events::room::message::SyncRoomMessageEvent
|
|
||||||
}, Session};
|
|
||||||
use matrix_sdk::ruma::api::client::filter::{FilterDefinition, RoomFilter};
|
use matrix_sdk::ruma::api::client::filter::{FilterDefinition, RoomFilter};
|
||||||
use matrix_sdk::ruma::api::client::sync::sync_events::v3::Filter;
|
use matrix_sdk::ruma::api::client::sync::sync_events::v3::Filter;
|
||||||
use matrix_sdk::ruma::api::client::uiaa;
|
use matrix_sdk::ruma::api::client::uiaa;
|
||||||
|
use matrix_sdk::{
|
||||||
|
config::SyncSettings,
|
||||||
|
ruma::{events::room::message::SyncRoomMessageEvent, OwnedRoomId, OwnedUserId},
|
||||||
|
Client, Session,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct Config {
|
struct Config {
|
||||||
user: OwnedUserId,
|
user: OwnedUserId,
|
||||||
room: OwnedRoomId,
|
room: OwnedRoomId,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
session: Option<Session>
|
session: Option<Session>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -25,10 +26,9 @@ impl Config {
|
||||||
}
|
}
|
||||||
fn read() -> Self {
|
fn read() -> Self {
|
||||||
let path = Self::path();
|
let path = Self::path();
|
||||||
let f = std::fs::File::open(&path)
|
let f =
|
||||||
.unwrap_or_else(|e| panic!("couldn't read {path:?}: {e:?}"));
|
std::fs::File::open(&path).unwrap_or_else(|e| panic!("couldn't read {path:?}: {e:?}"));
|
||||||
serde_json::from_reader(f)
|
serde_json::from_reader(f).unwrap_or_else(|e| panic!("couldn't load config: {e:?}"))
|
||||||
.unwrap_or_else(|e| panic!("couldn't load config: {e:?}"))
|
|
||||||
}
|
}
|
||||||
fn write(&self) {
|
fn write(&self) {
|
||||||
let json = serde_json::to_string_pretty(self).unwrap();
|
let json = serde_json::to_string_pretty(self).unwrap();
|
||||||
|
@ -73,19 +73,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
logged_in = true;
|
logged_in = true;
|
||||||
let devices_to_delete: Vec<_> = client.devices()
|
let devices_to_delete: Vec<_> = client
|
||||||
|
.devices()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.devices
|
.devices
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|d| d.display_name.clone().unwrap_or_default().as_str() == "tubest" && d.device_id != client.device_id().unwrap())
|
.filter(|d| {
|
||||||
|
d.display_name.clone().unwrap_or_default().as_str() == "tubest"
|
||||||
|
&& d.device_id != client.device_id().unwrap()
|
||||||
|
})
|
||||||
.map(|d| d.device_id)
|
.map(|d| d.device_id)
|
||||||
.collect();
|
.collect();
|
||||||
if let Err(e) = client.delete_devices(&devices_to_delete, None).await {
|
if let Err(e) = client.delete_devices(&devices_to_delete, None).await {
|
||||||
if let Some(info) = e.uiaa_response() {
|
if let Some(info) = e.uiaa_response() {
|
||||||
let mut password = uiaa::Password::new(uiaa::UserIdentifier::UserIdOrLocalpart(cfg.user.localpart()), password);
|
let mut password = uiaa::Password::new(
|
||||||
|
uiaa::UserIdentifier::UserIdOrLocalpart(cfg.user.localpart()),
|
||||||
|
password,
|
||||||
|
);
|
||||||
password.session = info.session.as_deref();
|
password.session = info.session.as_deref();
|
||||||
client.delete_devices(&devices_to_delete, Some(uiaa::AuthData::Password(password)))
|
client
|
||||||
|
.delete_devices(
|
||||||
|
&devices_to_delete,
|
||||||
|
Some(uiaa::AuthData::Password(password)),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +108,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
cfg.write();
|
cfg.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
client.add_room_event_handler(cfg.room.as_ref(), |ev: SyncRoomMessageEvent| async {
|
client.add_room_event_handler(cfg.room.as_ref(), |ev: SyncRoomMessageEvent| async {
|
||||||
match ev {
|
match ev {
|
||||||
SyncRoomMessageEvent::Original(orig) => {
|
SyncRoomMessageEvent::Original(orig) => {
|
||||||
|
@ -118,8 +128,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
room_filter.rooms = Some(&room_list);
|
room_filter.rooms = Some(&room_list);
|
||||||
filter_def.room = room_filter;
|
filter_def.room = room_filter;
|
||||||
client
|
client
|
||||||
.sync(SyncSettings::default()
|
.sync(SyncSettings::default().filter(Filter::FilterDefinition(filter_def)))
|
||||||
.filter(Filter::FilterDefinition(filter_def)))
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue