Skip to content

Commit

Permalink
Ignore paths in the scanner with .ignore or .plexignore files (#574)
Browse files Browse the repository at this point in the history
* ignore::WalkBuilder to support .plexignore semantics

* fixup rebase conflicts
  • Loading branch information
niamu authored Nov 12, 2023
1 parent 45308f8 commit 9cc3704
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 13 deletions.
54 changes: 47 additions & 7 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 dim-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ futures = "0.3.14"
fuzzy-matcher = "0.3.7"
http = "^0.2.3"
hyper = "0.14.20"
ignore = "0.4.20"
image = "0.24.3"
itertools = "0.10.3"
lazy_static = "1.4.0"
Expand Down Expand Up @@ -77,7 +78,6 @@ tracing-subscriber = { version = "^0.3.10", features = [
] }
url = "2.2.2"
uuid = { version = "1.2.2", features = ["v4"] }
walkdir = "2.3.1"
warp = { version = "0.3.3", features = ["tls", "tokio-rustls"] }
xmlwriter = "0.1.0"
xtra = { version = "0.5.1", features = ["tokio", "with-tokio-1"] }
Expand Down
64 changes: 60 additions & 4 deletions dim-core/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use dim_extern_api::filename::TorrentMetadata;
use dim_extern_api::ExternalQueryIntoShow;

use futures::FutureExt;
use ignore::WalkBuilder;
use itertools::Itertools;

use std::ffi::OsStr;
Expand All @@ -41,11 +42,65 @@ use tracing::error;
use tracing::info;
use tracing::instrument;
use tracing::warn;
use walkdir::WalkDir;

pub use error::Error;

pub(super) static SUPPORTED_EXTS: &[&str] = &["mp4", "mkv", "avi", "webm"];
pub(super) static SUPPORTED_EXTS: &[&str] = &[
"001",
"3g2",
"3gp",
"amv",
"asf",
"asx",
"avi",
"bin",
"bivx",
"divx",
"dv",
"dvr-ms",
"f4v",
"fli",
"flv",
"ifo",
"img",
"iso",
"m2t",
"m2ts",
"m2v",
"m4v",
"mkv",
"mk3d",
"mov",
"mp4",
"mpe",
"mpeg",
"mpg",
"mts",
"mxf",
"nrg",
"nsv",
"nuv",
"ogg",
"ogm",
"ogv",
"pva",
"qt",
"rec",
"rm",
"rmvb",
"strm",
"svq3",
"tp",
"ts",
"ty",
"viv",
"vob",
"vp3",
"webm",
"wmv",
"wtv",
"xvid"
];

/// Function recursively walks the paths passed and returns all files in those directories.
/// FIXME: THIS IS NOT ASYNC-SAFE!!!
Expand All @@ -55,10 +110,11 @@ pub(super) static SUPPORTED_EXTS: &[&str] = &["mp4", "mkv", "avi", "webm"];
pub fn get_subfiles(paths: impl Iterator<Item = impl AsRef<Path>>) -> Vec<PathBuf> {
let mut files = Vec::with_capacity(2048);
for path in paths {
let mut subfiles: Vec<PathBuf> = WalkDir::new(path)
let mut subfiles = WalkBuilder::new(path)
// we want to follow all symlinks in case of complex dir structures
.follow_links(true)
.into_iter()
.add_custom_ignore_filename(".plexignore")
.build()
.filter_map(Result::ok)
// ignore all hidden files.
.filter(|f| {
Expand Down
2 changes: 1 addition & 1 deletion dim-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct AppState {
fn library_routes(app: AppState) -> Router<AppState> {
Router::new()
.route(
"api/v1/library",
"/api/v1/library",
post(routes::library::library_post).get(routes::library::library_get_all),
)
.route(
Expand Down

0 comments on commit 9cc3704

Please sign in to comment.