Skip to content

Commit

Permalink
enable scanning daemon and scan library on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarleanu committed Sep 21, 2022
1 parent a7f7e03 commit 41a3b87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
30 changes: 23 additions & 7 deletions dim/src/core.rs
@@ -1,10 +1,14 @@
use crate::balanced_or_tree;
use crate::external::tmdb::TMDBMetadataProvider;
use crate::logger::RequestLogger;
use crate::routes;
use crate::routes::*;
use crate::scanner;
use crate::stream_tracking::StreamTracking;
use crate::websocket;

use database::library::MediaType;

use once_cell::sync::OnceCell;

use tokio::sync::mpsc::UnboundedReceiver;
Expand All @@ -14,7 +18,7 @@ use tracing::{info, instrument};
use warp::http::status::StatusCode;
use warp::Filter;

use crate::routes::*;
use std::sync::Arc;

pub type StateManager = nightfall::StateManager;
pub type DbConnection = database::DbConnection;
Expand All @@ -23,7 +27,6 @@ pub type EventTx = UnboundedSender<String>;
/// Path to where metadata is stored and should be fetched to.
pub static METADATA_PATH: OnceCell<String> = OnceCell::new();

/*
/// Function dumps a list of all libraries in the database and starts a scanner for each which
/// monitors for new files using fsnotify. It also scans all orphans on boot.
///
Expand All @@ -33,7 +36,6 @@ pub static METADATA_PATH: OnceCell<String> = OnceCell::new();
/// dispatched to clients.
#[instrument(skip_all)]
pub async fn run_scanners(tx: EventTx) {
/*
if let Ok(conn) = database::get_conn_logged().await {
if let Ok(mut db_tx) = conn.read().begin().await {
let mut libs = database::library::Library::get_all(&mut db_tx).await;
Expand All @@ -44,14 +46,30 @@ pub async fn run_scanners(tx: EventTx) {
let library_id = lib.id;
let tx_clone = tx.clone();
let media_type = lib.media_type;
let watcher = scanner::scanner_daemon::FsWatcher::new(

let provider = TMDBMetadataProvider::new("38c372f5bc572c8aadde7a802638534e");

let provider = match media_type {
MediaType::Movie => Arc::new(provider.movies()) as Arc<_>,
MediaType::Tv => Arc::new(provider.tv_shows()) as Arc<_>,
_ => unreachable!(),
};

let mut watcher = scanner::daemon::FsWatcher::new(
conn.clone(),
library_id,
media_type,
tx_clone.clone(),
Arc::clone(&provider),
);

tokio::spawn(scanners::start(conn.clone(), library_id, tx_clone.clone()));
let conn_clone = conn.clone();

tokio::spawn(async move {
let mut conn = conn_clone;
scanner::start(&mut conn, library_id, tx_clone.clone(), provider).await
});

tokio::spawn(async move {
watcher
.start_daemon()
Expand All @@ -61,9 +79,7 @@ pub async fn run_scanners(tx: EventTx) {
}
}
}
*/
}
*/

#[instrument(skip(stream_manager, event_tx, rt, event_rx))]
pub async fn warp_core(
Expand Down
2 changes: 1 addition & 1 deletion dim/src/main.rs
Expand Up @@ -107,7 +107,7 @@ fn main() {

if !global_settings.quiet_boot {
info!("Transposing scanners from the netherworld...");
//core::run_scanners(event_tx.clone()).await;
core::run_scanners(event_tx.clone()).await;
}

info!("Summoning Dim v{}...", structopt::clap::crate_version!());
Expand Down
2 changes: 2 additions & 0 deletions dim/src/scanner/daemon.rs
Expand Up @@ -2,6 +2,7 @@ use crate::core::EventTx;
use crate::external::ExternalQuery;

use super::movie;
use super::tv_show;
use super::MediaMatcher;

use std::path::PathBuf;
Expand Down Expand Up @@ -56,6 +57,7 @@ impl FsWatcher {
) -> Self {
let matcher = match media_type {
MediaType::Movie => Arc::new(movie::MovieMatcher) as Arc<dyn MediaMatcher>,
MediaType::Tv => Arc::new(tv_show::TvMatcher) as Arc<dyn MediaMatcher>,
_ => unimplemented!(),
};

Expand Down

0 comments on commit 41a3b87

Please sign in to comment.