Skip to content

Commit

Permalink
yt-dlp support
Browse files Browse the repository at this point in the history
  • Loading branch information
gmanley committed Mar 20, 2023
1 parent 4f7bbab commit 366cd40
Show file tree
Hide file tree
Showing 9 changed files with 724 additions and 34 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ repository = "https://github.com/HoloArchivists/hoshinova"
homepage = "https://github.com/HoloArchivists/hoshinova"

[dependencies]
json = "0.12"

# Async
async-trait = "0.1"
futures = "0.3"
Expand Down
14 changes: 14 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ts_rs::TS;
#[ts(export, export_to = "web/src/bindings/")]
pub struct Config {
pub ytarchive: YtarchiveConfig,
pub ytdlp: YtdlpConfig,
pub scraper: ScraperConfig,
pub notifier: Option<NotifierConfig>,
pub webserver: Option<WebserverConfig>,
Expand Down Expand Up @@ -34,6 +35,19 @@ fn default_delay_start() -> std::time::Duration {
std::time::Duration::from_secs(1)
}

#[derive(Clone, TS, Serialize, Deserialize, Debug)]
#[ts(export, export_to = "web/src/bindings/")]
pub struct YtdlpConfig {
pub executable_path: String,
pub working_directory: String,
pub args: Vec<String>,
pub quality: String,
#[serde(with = "humantime_serde")]
#[serde(default = "default_delay_start")]
#[ts(type = "string")]
pub delay_start: std::time::Duration,
}

#[derive(Clone, TS, Serialize, Deserialize, Debug)]
#[ts(export, export_to = "web/src/bindings/")]
pub struct ScraperConfig {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[macro_use]
extern crate log;
extern crate json;
use crate::module::Module;
use crate::msgbus::MessageBus;
use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -116,7 +117,7 @@ async fn main() -> Result<()> {

let config = Arc::new(RwLock::new(config));
let h_scraper = run_module!(bus, module::scraper::RSS::new(config.clone()));
let h_recorder = run_module!(bus, module::recorder::YTArchive::new(config.clone()));
let h_recorder = run_module!(bus, module::recorder::ytarchive::YTArchive::new(config.clone()));
let h_notifier = run_module!(bus, module::notifier::Discord::new(config.clone()));
let h_webserver = run_module!(bus, module::web::WebServer::new(config.clone()));

Expand Down
4 changes: 2 additions & 2 deletions src/module/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use self::recorder::YTAStatus;
use self::recorder::ytarchive::YTAStatus;
use crate::{config::Config, msgbus::BusTx};
use anyhow::Result;
use async_trait::async_trait;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct Notification {
#[ts(export, export_to = "web/src/bindings/")]
pub struct RecordingStatus {
pub task: Task,
pub status: YTAStatus,
pub status: YTStatus,
}

#[derive(Debug, Clone, PartialEq, TS)]
Expand Down
38 changes: 38 additions & 0 deletions src/module/recorder/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pub mod ytarchive;
pub mod ytdlp;

/// The current state of ytarchive.
#[derive(Debug, Clone, TS, Serialize)]
#[ts(export, export_to = "web/src/bindings/")]
pub struct YTStatus {
version: Option<String>,
state: YTState,
last_output: Option<String>,
last_update: chrono::DateTime<chrono::Utc>,
video_fragments: Option<u32>,
audio_fragments: Option<u32>,
total_size: Option<String>,
video_quality: Option<String>,
output_file: Option<String>,
}

#[derive(Debug, Clone, PartialEq, TS, Serialize)]
#[ts(export, export_to = "web/src/bindings/")]
pub enum YTState {
Idle,
Waiting(Option<DateTime<Utc>>),
Recording,
Muxing,
Finished,
AlreadyProcessed,
Ended,
Interrupted,
Errored,
}

#[async_trait]
pub trait Recorder<T: Debug + Clone + Sync = Message> {
async fn record(cfg: Config, task: Task, bus: &mut BusTx<Message>) -> Result<()>
fn new(config: Arc<RwLock<Config>>) -> Self;
async fn run(&self, tx: &BusTx<T>, rx: &mut mpsc::Receiver<T>) -> Result<()>;
}
32 changes: 2 additions & 30 deletions src/module/recorder.rs → src/module/recorder/ytarchive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Message, Module, Notification, Task, TaskStatus};
use super::super::{Message, Module, Notification, Task, TaskStatus};
use crate::msgbus::BusTx;
use crate::{config::Config, module::RecordingStatus};
use anyhow::{anyhow, Context, Result};
Expand All @@ -23,6 +23,7 @@ use tokio::{
};
use ts_rs::TS;


pub struct YTArchive {
config: Arc<RwLock<Config>>,
active_ids: Arc<RwLock<HashSet<String>>>,
Expand Down Expand Up @@ -376,35 +377,6 @@ impl Module for YTArchive {
}
}

/// The current state of ytarchive.
#[derive(Debug, Clone, TS, Serialize)]
#[ts(export, export_to = "web/src/bindings/")]
pub struct YTAStatus {
version: Option<String>,
state: YTAState,
last_output: Option<String>,
last_update: chrono::DateTime<chrono::Utc>,
video_fragments: Option<u32>,
audio_fragments: Option<u32>,
total_size: Option<String>,
video_quality: Option<String>,
output_file: Option<String>,
}

#[derive(Debug, Clone, PartialEq, TS, Serialize)]
#[ts(export, export_to = "web/src/bindings/")]
pub enum YTAState {
Idle,
Waiting(Option<DateTime<Utc>>),
Recording,
Muxing,
Finished,
AlreadyProcessed,
Ended,
Interrupted,
Errored,
}

fn strip_ansi(s: &str) -> String {
lazy_static! {
static ref RE: Regex = Regex::new(concat!(
Expand Down
Loading

0 comments on commit 366cd40

Please sign in to comment.