cargo clippy
This commit is contained in:
parent
6ba3d749a1
commit
d1def859fd
|
@ -15,7 +15,7 @@ pub struct Config {
|
||||||
pub cohost_page: String,
|
pub cohost_page: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
const VAR_PREFIX: &'static str = "SCREENCAP_BOT_";
|
const VAR_PREFIX: &str = "SCREENCAP_BOT_";
|
||||||
|
|
||||||
fn get_var(name: &str) -> Result<String, VarError> {
|
fn get_var(name: &str) -> Result<String, VarError> {
|
||||||
env::var(VAR_PREFIX.to_string() + name)
|
env::var(VAR_PREFIX.to_string() + name)
|
||||||
|
@ -24,19 +24,19 @@ fn get_var(name: &str) -> Result<String, VarError> {
|
||||||
fn parse_var<E: Debug, T: FromStr<Err = E>>(name: &str) -> Result<T, VarError> {
|
fn parse_var<E: Debug, T: FromStr<Err = E>>(name: &str) -> Result<T, VarError> {
|
||||||
get_var(name).map(|s| {
|
get_var(name).map(|s| {
|
||||||
s.parse()
|
s.parse()
|
||||||
.expect(&format!("Failed to parse {}{}", VAR_PREFIX, name))
|
.unwrap_or_else(|e| panic!("Failed to parse {}{}: {:?}", VAR_PREFIX, name, e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect_var(name: &str) -> String {
|
fn expect_var(name: &str) -> String {
|
||||||
get_var(name).expect(&format!("{}{} must be set", VAR_PREFIX, name))
|
get_var(name).unwrap_or_else(|_| panic!("{}{} must be set", VAR_PREFIX, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load() -> Config {
|
pub fn load() -> Config {
|
||||||
Config {
|
Config {
|
||||||
shows_file: parse_var("SHOWS_FILE").unwrap_or(PathBuf::from("./shows.yaml")),
|
shows_file: parse_var("SHOWS_FILE").unwrap_or(PathBuf::from("./shows.yaml")),
|
||||||
global_tags: get_var("GLOBAL_TAGS")
|
global_tags: get_var("GLOBAL_TAGS")
|
||||||
.map(|s| s.split(",").map(String::from).collect())
|
.map(|s| s.split(',').map(String::from).collect())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
post_interval: Duration::from_secs(parse_var("POST_INTERVAL").unwrap_or(6 * 3600)),
|
post_interval: Duration::from_secs(parse_var("POST_INTERVAL").unwrap_or(6 * 3600)),
|
||||||
cohost_email: expect_var("COHOST_EMAIL"),
|
cohost_email: expect_var("COHOST_EMAIL"),
|
||||||
|
|
54
src/video.rs
54
src/video.rs
|
@ -27,33 +27,31 @@ pub fn get_video_info<P: AsRef<Path>>(
|
||||||
|
|
||||||
let duration_secs = ctx.duration() as f64 / f64::from(ffmpeg_next::ffi::AV_TIME_BASE);
|
let duration_secs = ctx.duration() as f64 / f64::from(ffmpeg_next::ffi::AV_TIME_BASE);
|
||||||
|
|
||||||
let subtitle_stream_index = subtitle_lang
|
let subtitle_stream_index = subtitle_lang.and_then(|lang| {
|
||||||
.map(|lang| {
|
ctx.streams()
|
||||||
ctx.streams()
|
.filter(|stream| {
|
||||||
.filter(|stream| {
|
ffmpeg_next::codec::context::Context::from_parameters(stream.parameters())
|
||||||
ffmpeg_next::codec::context::Context::from_parameters(stream.parameters())
|
.map(|c| c.medium())
|
||||||
.map(|c| c.medium())
|
== Ok(Type::Subtitle)
|
||||||
== Ok(Type::Subtitle)
|
})
|
||||||
})
|
.enumerate()
|
||||||
.enumerate()
|
.filter(|(_, stream)| {
|
||||||
.filter(|(_, stream)| {
|
let metadata = stream.metadata();
|
||||||
let metadata = stream.metadata();
|
if metadata.get("language") != Some(lang) {
|
||||||
if metadata.get("language") != Some(lang) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if metadata
|
||||||
if metadata
|
.get("title")
|
||||||
.get("title")
|
.map(|t| SUBTITLE_FORBID_REGEX.is_match(t))
|
||||||
.map(|t| SUBTITLE_FORBID_REGEX.is_match(t))
|
== Some(true)
|
||||||
== Some(true)
|
{
|
||||||
{
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
true
|
||||||
true
|
})
|
||||||
})
|
.min_by_key(|(_, stream)| stream.disposition().contains(Disposition::FORCED))
|
||||||
.min_by_key(|(_, stream)| stream.disposition().contains(Disposition::FORCED))
|
.map(|(idx, _)| idx)
|
||||||
.map(|(idx, _)| idx)
|
});
|
||||||
})
|
|
||||||
.flatten();
|
|
||||||
|
|
||||||
Ok(VideoInfo {
|
Ok(VideoInfo {
|
||||||
duration_secs,
|
duration_secs,
|
||||||
|
@ -66,7 +64,7 @@ pub async fn take_screencap<P: AsRef<Path>>(
|
||||||
timestamp_secs: f64,
|
timestamp_secs: f64,
|
||||||
subtitle_stream_index: Option<usize>,
|
subtitle_stream_index: Option<usize>,
|
||||||
) -> std::io::Result<Vec<u8>> {
|
) -> std::io::Result<Vec<u8>> {
|
||||||
let ext = source.as_ref().extension().map(|s| s.to_str()).flatten();
|
let ext = source.as_ref().extension().and_then(|s| s.to_str());
|
||||||
if ext != Some("mkv") && ext != Some("mp4") {
|
if ext != Some("mkv") && ext != Some("mp4") {
|
||||||
return Err(std::io::Error::new(
|
return Err(std::io::Error::new(
|
||||||
ErrorKind::Other,
|
ErrorKind::Other,
|
||||||
|
|
Loading…
Reference in a new issue