Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 16 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ license = "MIT"
argh = "0.1"
config = { version = "0.15", default-features = false, features = ["toml"] }
pretty_env_logger = "0.5"
failure = "0.1"
anyhow = "1.0"
futures = "0.3"
heck = "0.5"
humantime-serde = "1.1"
Expand Down
16 changes: 8 additions & 8 deletions src/handbrake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;

use failure::{Error, format_err};
use anyhow::{Result, anyhow};
use log::info;
use tokio::{
fs,
Expand Down Expand Up @@ -39,7 +39,7 @@ struct Job {
}

impl HandbrakeProcess {
pub fn new(config: Handbrake) -> (HandbrakeProcess, JoinHandle<Result<(), Error>>) {
pub fn new(config: Handbrake) -> (HandbrakeProcess, JoinHandle<Result<()>>) {
let (tx, mut rx) = unbounded_channel();
let jobs = Arc::new(RwLock::new(HashMap::<String, JobStatus>::new()));
let jobs_clone = jobs.clone();
Expand Down Expand Up @@ -85,7 +85,7 @@ impl HandbrakeProcess {
(HandbrakeProcess { tx, jobs }, handle)
}

pub async fn queue(&self, src: PathBuf, dest: PathBuf) -> Result<(), Error> {
pub async fn queue(&self, src: PathBuf, dest: PathBuf) -> Result<()> {
let job_id = format!("{}", uuid::Uuid::new_v4());
let job_status = JobStatus {
id: job_id.clone(),
Expand Down Expand Up @@ -137,7 +137,7 @@ async fn handbrake(
dest: &Path,
job_id: &str,
jobs: &Arc<RwLock<HashMap<String, JobStatus>>>,
) -> Result<(), Error> {
) -> Result<()> {
let disc_meta: DiscMetadata = toml::from_slice(&fs::read(src.join("meta.toml")).await?)?;

let args = match disc_meta.disc_type {
Expand Down Expand Up @@ -165,16 +165,16 @@ async fn handbrake(

let source_file = path
.to_str()
.ok_or_else(|| format_err!("path is not a valid string: {:?}", path))?;
.ok_or_else(|| anyhow!("path is not a valid string: {:?}", path))?;

let dest_file = dest.join(
output_file
.file_name()
.ok_or_else(|| format_err!("path is not a valid string: {:?}", dest))?,
.ok_or_else(|| anyhow!("path is not a valid string: {:?}", dest))?,
);
let dest_file = dest_file
.to_str()
.ok_or_else(|| format_err!("path is not a valid string: {:?}", dest_file))?;
.ok_or_else(|| anyhow!("path is not a valid string: {:?}", dest_file))?;

// Update progress to indicate file processing started
{
Expand Down Expand Up @@ -204,7 +204,7 @@ async fn handbrake(
let status = child.wait().await?;

if !status.success() {
return Err(format_err!(
return Err(anyhow!(
"error code {:?} from handbrake, stopping process",
status.code()
));
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, path::Path};

use argh::FromArgs;
use failure::Error;
use anyhow::Result;
use futures::future::try_join_all;
use log::{error, info, warn};
use tokio::time::sleep;
Expand All @@ -18,7 +18,7 @@ mod makemkv;
mod web;

#[tokio::main]
async fn main() -> Result<(), Error> {
async fn main() -> Result<()> {
if env::var_os("RUST_LOG").is_none() {
// nothing else should be running right now
// so this is as safe as it can be for now
Expand Down Expand Up @@ -51,7 +51,7 @@ async fn main() -> Result<(), Error> {
Ok(())
}

async fn rip(settings: Settings) -> Result<(), Error> {
async fn rip(settings: Settings) -> Result<()> {
let (hb_process, hb_handle) = HandbrakeProcess::new(settings.handbrake.clone());

process_existing_directories(&hb_process, &settings).await?;
Expand Down Expand Up @@ -99,7 +99,7 @@ fn spawn_rip_process(
device: String,
settings: Settings,
hb_process: HandbrakeProcess,
) -> JoinHandle<Result<(), Error>> {
) -> JoinHandle<Result<()>> {
tokio::spawn(async move {
loop {
let device = device.to_owned();
Expand Down Expand Up @@ -139,7 +139,7 @@ fn spawn_rip_process(
async fn process_existing_directories(
hb_process: &HandbrakeProcess,
settings: &Settings,
) -> Result<(), Error> {
) -> Result<()> {
if settings.makemkv.enqueue_existing_jobs {
if !Path::new(&settings.directory.raw).exists() {
return Ok(());
Expand Down
8 changes: 4 additions & 4 deletions src/makemkv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::{
time::SystemTime,
};

use failure::{format_err, Error};
use anyhow::{anyhow, Result};
use tokio::{fs, process::Command};

use crate::config::MakeMKV;
use crate::disc::{Disc, DiscMetadata};

pub async fn rip(config: &MakeMKV, disc: &Disc, target_folder: &Path) -> Result<PathBuf, Error> {
pub async fn rip(config: &MakeMKV, disc: &Disc, target_folder: &Path) -> Result<PathBuf> {
let target_folder = {
let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)?
Expand Down Expand Up @@ -40,8 +40,8 @@ pub async fn rip(config: &MakeMKV, disc: &Disc, target_folder: &Path) -> Result<
let status = child.wait().await?;

if !status.success() {
return Err(format_err!(
"error code {:?} from handbrake, stopping process",
return Err(anyhow!(
"error code {:?} from makemkv, stopping process",
status.code()
));
}
Expand Down
6 changes: 3 additions & 3 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct AppState {
pub async fn run_web_server(
settings: Settings,
handbrake_process: HandbrakeProcess,
) -> Result<(), failure::Error> {
) -> Result<(), anyhow::Error> {
let system_status = Arc::new(RwLock::new(SystemStatus {
drives: Vec::new(),
handbrake_jobs: Vec::new(),
Expand All @@ -76,7 +76,7 @@ pub async fn run_web_server(
info!("Web interface already running on {}", addr);
return Ok(());
}
return Err(failure::format_err!(
return Err(anyhow::anyhow!(
"Failed to bind to address {}: {}",
addr,
e
Expand All @@ -92,7 +92,7 @@ pub async fn run_web_server(

let listener = tokio::net::TcpListener::bind(&addr)
.await
.map_err(|e| failure::format_err!("Failed to bind to address {}: {}", addr, e))?;
.map_err(|e| anyhow::anyhow!("Failed to bind to address {}: {}", addr, e))?;

info!("Web interface available at http://{}", addr);

Expand Down