Browse Source

Some last cleanups

main
Georg Hopp 11 months ago
parent
commit
503a16354c
Signed by: ghopp GPG Key ID: 4C5D226768784538
  1. 8
      src/client.rs
  2. 0
      src/client/error.rs
  3. 0
      src/client/util.rs
  4. 7
      src/client_actor.rs
  5. 21
      src/client_actor/error.rs
  6. 5
      src/client_actor/message.rs
  7. 7
      src/client_actor/util.rs
  8. 15
      src/m3u8_download.rs
  9. 4
      src/main.rs

8
src/client_new.rs → src/client.rs

@ -8,7 +8,13 @@ use clap::{crate_name, crate_version};
use error::{DownloadError, RequestError};
use futures_util::StreamExt as _;
use http::{
header::{CONTENT_LENGTH, CONTENT_TYPE, ORIGIN, RANGE, USER_AGENT}, request::Builder as RequestBuilder, HeaderMap, HeaderValue, Request, Response, Uri
header::{CONTENT_LENGTH, CONTENT_TYPE, ORIGIN, RANGE, USER_AGENT},
request::Builder as RequestBuilder,
HeaderMap,
HeaderValue,
Request,
Response,
Uri
};
use http_body_util::BodyDataStream;
use log::debug;

0
src/client_new/error.rs → src/client/error.rs

0
src/client_new/util.rs → src/client/util.rs

7
src/client_actor.rs

@ -6,16 +6,15 @@ use std::{collections::HashMap, path::Path};
use error::ClientActorError;
use http::{HeaderMap, Uri};
use message::{ClientActorMessage, ClientActorMessageHandle, DownloadResult};
use message::{ClientActorMessage, ClientActorMessageHandle};
use tokio::{sync::{mpsc, oneshot}, task::JoinSet};
use crate::client_new::DownloadState;
use super::client_new::Client;
use super::client::{Client, DownloadState};
type ActionIndex = u64;
type ClientTaskResult = Result<Option<ClientActorMessageHandle>, ClientActorError>;
type DownloadResult = Result<DownloadState, ClientActorError>;
#[derive(Debug)]

21
src/client_actor/error.rs

@ -3,27 +3,6 @@ use std::{error, fmt};
use super::message::ClientActorMessageHandle;
/*
#[macro_export]
macro_rules! mk_ca_error {
($message:ident, $($err:tt)*) => {{
use $crate::client::error;
error::ClientActorError::new( $message.clone()
, anyhow::anyhow!($($err)*) )
}};
}
#[macro_export]
macro_rules! map_ca_error {
($message:ident) => {{
use $crate::client::error;
|e| error::ClientActorError::new( $message.clone()
, anyhow::anyhow!(format!("{:?}", e)) )
}};
}
*/
#[derive(Debug)]
pub(crate) struct ClientActorError {
pub(super) action: ClientActorMessageHandle,

5
src/client_actor/message.rs

@ -3,13 +3,10 @@ use std::path::PathBuf;
use http::Uri;
use tokio::sync::oneshot;
use crate::client_new::DownloadState;
use super::error::ClientActorError;
use super::{DownloadState, DownloadResult};
type ActionIndex = u64;
pub(super) type DownloadResult = Result<DownloadState, ClientActorError>;
#[derive(Debug)]

7
src/client_actor/util.rs

@ -43,10 +43,8 @@ async fn process_next_result(mut actor: ClientActor, result: ClientTaskResult) -
Download { ref uri, ref state, ref message, .. } => {
info!("Done download: {:?}", uri);
if let Some((_, message)) = actor.actions.remove_entry(message) {
use ClientActorMessage::Download;
match message {
Download { respond_to, .. } => {
ClientActorMessage::Download { respond_to, .. } => {
let _ = respond_to.send(Ok(state.clone()));
},
_ => panic!("Wrong variant ... this should never happen"),
@ -59,9 +57,8 @@ async fn process_next_result(mut actor: ClientActor, result: ClientTaskResult) -
GetData { ref uri, ref buffer, ref message } => {
info!("Done get_data: {:?}", uri);
if let Some((_, message)) = actor.actions.remove_entry(message) {
use ClientActorMessage::GetData;
match message {
GetData { respond_to, .. } => {
ClientActorMessage::GetData { respond_to, .. } => {
let _ = respond_to.send(buffer.clone());
},
_ => panic!("Wrong variant ... this should never happen"),

15
src/m3u8_download.rs

@ -7,7 +7,7 @@ use log::debug;
use m3u8_rs::{MediaPlaylist, MediaSegment, Playlist};
use tokio::{io::AsyncWriteExt as _, fs::File};
use crate::{client_actor::ClientActorHandle, client_new::DownloadState};
use crate::{client_actor::ClientActorHandle, client::DownloadState};
#[derive(Clone, Debug)]
@ -19,26 +19,15 @@ pub(super) enum TsState {
#[derive(Clone, Debug)]
struct TsPart {
#[allow(dead_code)]
filename: PathBuf,
#[allow(dead_code)]
uri: Uri,
#[allow(dead_code)]
state: TsState,
content_type: Option<String>,
}
#[derive(Debug)]
pub(super) struct M3u8Download {
#[allow(dead_code)]
index_uri: Uri,
#[allow(dead_code)]
scheme: Scheme,
#[allow(dead_code)]
auth: Authority,
#[allow(dead_code)]
base_path: String,
#[allow(dead_code)]
ts_parts: Vec<TsPart>,
}
@ -99,7 +88,7 @@ impl M3u8Download {
},
};
Ok(Self {index_uri, scheme, auth, base_path, ts_parts})
Ok(Self {index_uri, ts_parts})
}
pub(super) fn index_uri(&self) -> &Uri {

4
src/main.rs

@ -1,6 +1,6 @@
mod process;
mod m3u8_download;
mod client_new;
mod client;
mod client_actor;
use std::{ffi::OsStr, path::PathBuf, time::Duration};
@ -8,7 +8,7 @@ use std::{ffi::OsStr, path::PathBuf, time::Duration};
use anyhow::anyhow;
use clap::Parser;
use client_actor::ClientActorHandle;
use client_new::Client;
use client::Client;
use env_logger::Env;
use http::Uri;
use m3u8_download::M3u8Download;

Loading…
Cancel
Save