Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: rustg_sound_length() #192

Merged
merged 8 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
185 changes: 185 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ ammonia = { version = "4.0.0", optional = true }
fast_poisson = { version = "0.5.2", optional = true, features = [
"single_precision",
] } # Higher versions have problems with x86 due to 'kiddo'.
symphonia = { version = "0.5.4", optional = true, features = [
"all-codecs",
] }

[features]
default = [
Expand All @@ -79,6 +82,7 @@ default = [
"noise",
"rustls_tls",
"sanitize",
"sound_len",
ZeWaka marked this conversation as resolved.
Show resolved Hide resolved
"sql",
"time",
"toml",
Expand All @@ -98,6 +102,7 @@ all = [
"noise",
"rustls_tls",
"sanitize",
"sound_len",
"sql",
"time",
"toml",
Expand All @@ -123,6 +128,7 @@ http = ["ureq", "serde", "serde_json", "once_cell", "jobs"]
json = ["serde", "serde_json"]
log = ["chrono"]
sanitize = ["ammonia", "serde_json"]
sound_len = ["symphonia"]
Kapu1178 marked this conversation as resolved.
Show resolved Hide resolved
sql = ["mysql", "serde", "serde_json", "once_cell", "dashmap", "jobs"]
time = []
toml = ["serde", "serde_json", "toml-dep"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The default features are:
* json: Function to check JSON validity.
* log: Faster log output.
* noise: 2d Perlin noise.
* sound_len: A mostly codec-agnostic library for reading the duration of an audio file.
* sql: Asynchronous MySQL/MariaDB client library.
* time: High-accuracy time measuring.
* toml: TOML parser.
Expand Down
33 changes: 33 additions & 0 deletions dmsrc/sound_len.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Provided a static RSC file path or a raw text file path, returns the duration of the file in deciseconds as a float.
Kapu1178 marked this conversation as resolved.
Show resolved Hide resolved
/proc/rustg_sound_length(file_path)
Kapu1178 marked this conversation as resolved.
Show resolved Hide resolved
var/static/list/sound_cache
if(isnull(sound_cache))
sound_cache = list()

. = 0

if(!istext(file_path))
if(!isfile(file_path))
CRASH("rustg_sound_length error: Passed non-text object")

if(length("[file_path]"))
file_path = "[file_path]"
Kapu1178 marked this conversation as resolved.
Show resolved Hide resolved
else
CRASH("rustg_sound_length does not support non-static file refs.")

if(!isnull((. = sound_cache[file_path])))
return .
Kapu1178 marked this conversation as resolved.
Show resolved Hide resolved

var/ret = RUSTG_CALL(RUST_G, "sound_len")(file_path)
var/as_num = text2num(ret)
if(isnull(ret))
. = 0
CRASH("rustg_sound_length error: [ret]")

sound_cache[file_path] = as_num
return as_num

#define RUSTG_SOUNDLEN_SUCCESSES "successes"
#define RUSTG_SOUNDLEN_ERRORS "errors"
// Returns a list of lists "successes" and "errors". Successes are file_path : duration. Errors are file_path : error.
Kapu1178 marked this conversation as resolved.
Show resolved Hide resolved
#define rustg_sound_length_list(file_paths) json_decode(RUSTG_CALL(RUST_G, "sound_len_list")(json_encode(file_paths)))
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum Error {
#[cfg(feature = "http")]
#[error(transparent)]
Request(#[from] Box<ureq::Error>),
#[cfg(feature = "sound_len")]
#[error("SoundLen error: {0}")]
SoundLen(String),
#[cfg(feature = "toml")]
#[error(transparent)]
TomlDeserialization(#[from] toml_dep::de::Error),
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub mod redis_pubsub;
pub mod redis_reliablequeue;
#[cfg(feature = "sanitize")]
pub mod sanitize;
#[cfg(feature = "sound_len")]
pub mod sound_len;
#[cfg(feature = "sql")]
pub mod sql;
#[cfg(feature = "time")]
Expand Down
Loading