Format the code

This commit is contained in:
Zoe Roux 2023-08-01 00:01:10 +09:00
parent e0ee364929
commit 9bb896e84b
5 changed files with 17 additions and 19 deletions

View File

@ -30,9 +30,9 @@ async def main():
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
if len(sys.argv) > 1 and sys.argv[1] == "-vv": if len(sys.argv) > 1 and sys.argv[1] == "-vv":
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logging.getLogger('watchfiles').setLevel(logging.WARNING) logging.getLogger("watchfiles").setLevel(logging.WARNING)
jsons.set_serializer(lambda x, **_: format_date(x), Optional[date | int]) # type: ignore jsons.set_serializer(lambda x, **_: format_date(x), Optional[date | int]) # type: ignore
async with ClientSession( async with ClientSession(
json_serialize=lambda *args, **kwargs: jsons.dumps( json_serialize=lambda *args, **kwargs: jsons.dumps(
*args, key_transformer=jsons.KEY_TRANSFORMER_CAMELCASE, **kwargs *args, key_transformer=jsons.KEY_TRANSFORMER_CAMELCASE, **kwargs

View File

@ -11,7 +11,7 @@ async def monitor(path: str, scanner: Scanner):
if event == Change.added: if event == Change.added:
await scanner.identify(file) await scanner.identify(file)
elif event == Change.deleted: elif event == Change.deleted:
await scanner.delete(file); await scanner.delete(file)
elif event == Change.modified: elif event == Change.modified:
pass pass
else: else:

View File

@ -21,7 +21,9 @@ class Scanner:
self._api_key = api_key self._api_key = api_key
self._url = os.environ.get("KYOO_URL", "http://back:5000") self._url = os.environ.get("KYOO_URL", "http://back:5000")
try: try:
self._ignore_pattern = re.compile(os.environ.get("LIBRARY_IGNORE_PATTERN", "")) self._ignore_pattern = re.compile(
os.environ.get("LIBRARY_IGNORE_PATTERN", "")
)
except Exception as e: except Exception as e:
self._ignore_pattern = re.compile("") self._ignore_pattern = re.compile("")
logging.error(f"Invalid ignore pattern. Ignoring. Error: {e}") logging.error(f"Invalid ignore pattern. Ignoring. Error: {e}")

View File

@ -1,11 +1,11 @@
use json::JsonValue; use json::JsonValue;
use serde::Serialize; use serde::Serialize;
use sha1::{Sha1, Digest}; use sha1::{Digest, Sha1};
use std::{ use std::{
fs, fs, io,
path::PathBuf, path::PathBuf,
process::Stdio, process::Stdio,
str::{self, FromStr}, io, str::{self, FromStr},
}; };
use tokio::process::Command; use tokio::process::Command;
use utoipa::ToSchema; use utoipa::ToSchema;
@ -138,7 +138,6 @@ pub async fn identify(path: String) -> Result<MediaInfo, std::io::Error> {
io::copy(&mut file, &mut hasher)?; io::copy(&mut file, &mut hasher)?;
let sha = format!("{:x}", hasher.finalize()); let sha = format!("{:x}", hasher.finalize());
let general = output["media"]["track"] let general = output["media"]["track"]
.members() .members()
.find(|x| x["@type"] == "General") .find(|x| x["@type"] == "General")

View File

@ -11,7 +11,7 @@ use utoipa::OpenApi;
use crate::{ use crate::{
audio::*, audio::*,
identify::{identify, Chapter, MediaInfo, Video, Audio, Subtitle}, identify::{identify, Audio, Chapter, MediaInfo, Subtitle, Video},
state::Transcoder, state::Transcoder,
video::*, video::*,
}; };
@ -104,16 +104,13 @@ async fn identify_resource(
.await .await
.map_err(|_| ApiError::NotFound)?; .map_err(|_| ApiError::NotFound)?;
identify(path) identify(path).await.map(|info| Json(info)).map_err(|e| {
.await eprintln!(
.map(|info| Json(info)) "Unhandled error occured while identifing the resource: {}",
.map_err(|e| { e
eprintln!( );
"Unhandled error occured while identifing the resource: {}", ApiError::InternalError
e })
);
ApiError::InternalError
})
} }
/// Get attachments /// Get attachments