remove pyo3

This commit is contained in:
mykola2312 2024-02-19 09:29:43 +02:00
parent eab13de0dc
commit 6c456dcee6
5 changed files with 1 additions and 174 deletions

139
Cargo.lock generated
View file

@ -551,12 +551,6 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "indoc"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8"
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.8.0" version = "2.8.0"
@ -605,16 +599,6 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.20" version = "0.4.20"
@ -627,15 +611,6 @@ version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.17" version = "0.3.17"
@ -678,7 +653,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"dotenv", "dotenv",
"pyo3",
"teloxide", "teloxide",
"tokio", "tokio",
] ]
@ -779,29 +753,6 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.4.1",
"smallvec",
"windows-targets",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.0" version = "2.3.0"
@ -879,67 +830,6 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "pyo3"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a89dc7a5850d0e983be1ec2a463a171d20990487c3cfcd68b5363f1ee3d6fe0"
dependencies = [
"cfg-if",
"indoc",
"libc",
"memoffset",
"parking_lot",
"pyo3-build-config",
"pyo3-ffi",
"pyo3-macros",
"unindent",
]
[[package]]
name = "pyo3-build-config"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07426f0d8fe5a601f26293f300afd1a7b1ed5e78b2a705870c5f30893c5163be"
dependencies = [
"once_cell",
"target-lexicon",
]
[[package]]
name = "pyo3-ffi"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb7dec17e17766b46bca4f1a4215a85006b4c2ecde122076c562dd058da6cf1"
dependencies = [
"libc",
"pyo3-build-config",
]
[[package]]
name = "pyo3-macros"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f738b4e40d50b5711957f142878cfa0f28e054aa0ebdfc3fd137a843f74ed3"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
"quote",
"syn 2.0.37",
]
[[package]]
name = "pyo3-macros-backend"
version = "0.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fc910d4851847827daf9d6cdd4a823fbdaab5b8818325c5e97a86da79e8881f"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.33" version = "1.0.33"
@ -967,15 +857,6 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
] ]
[[package]]
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags 1.3.2",
]
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.22" version = "0.11.22"
@ -1168,12 +1049,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "smallvec"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.4.9" version = "0.4.9"
@ -1255,12 +1130,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20f34339676cdcab560c9a82300c4c2581f68b9369aedf0fae86f2ff9565ff3e" checksum = "20f34339676cdcab560c9a82300c4c2581f68b9369aedf0fae86f2ff9565ff3e"
[[package]]
name = "target-lexicon"
version = "0.12.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae"
[[package]] [[package]]
name = "teloxide" name = "teloxide"
version = "0.12.2" version = "0.12.2"
@ -1335,7 +1204,7 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"fastrand", "fastrand",
"redox_syscall 0.3.5", "redox_syscall",
"rustix", "rustix",
"windows-sys", "windows-sys",
] ]
@ -1501,12 +1370,6 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unindent"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce"
[[package]] [[package]]
name = "url" name = "url"
version = "2.4.1" version = "2.4.1"

View file

@ -10,4 +10,3 @@ anyhow = "1.0.75"
dotenv = "0.15.0" dotenv = "0.15.0"
tokio = { version = "1.32.0", features = ["rt-multi-thread", "macros"] } tokio = { version = "1.32.0", features = ["rt-multi-thread", "macros"] }
teloxide = { version = "0.12.2", git ="https://github.com/teloxide/teloxide", features = ["macros"] } teloxide = { version = "0.12.2", git ="https://github.com/teloxide/teloxide", features = ["macros"] }
pyo3 = { version = "0.20.2", features = ["extension-module", "auto-initialize"] }

View file

@ -1 +0,0 @@
pub mod download;

View file

@ -1,29 +0,0 @@
use pyo3::prelude::*;
use tokio::task::{spawn_blocking, JoinError};
// TODO: Switch to Command::new for true multithreading and async
pub async fn download_url(url: String) -> Result<bool, JoinError> {
spawn_blocking(move || {
let res: PyResult<()> = Python::with_gil(|py| {
let yt_dlp = PyModule::import(py, "yt_dlp")?;
let yt = yt_dlp.getattr("YoutubeDL")?;
let yt_obj = yt.call((), None)?;
yt_obj.call_method0("__enter__")?;
yt_obj.call_method1("download", (url,))?;
yt_obj.call_method0("__exit__")?;
Ok(())
});
match res {
Ok(_) => true,
Err(e) => {
println!("{}", e);
false
}
}
})
.await
}

View file

@ -11,7 +11,6 @@ use teloxide::dispatching::UpdateHandler;
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands}; use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
mod dl; mod dl;
use dl::download::download_url;
type State = (); type State = ();
type MyDialogue = Dialogue<State, InMemStorage<State>>; type MyDialogue = Dialogue<State, InMemStorage<State>>;
@ -88,10 +87,6 @@ async fn test(bot: Bot, msg: Message) -> HandlerResult {
} }
async fn download(bot: Bot, msg: Message, url: String) -> HandlerResult { async fn download(bot: Bot, msg: Message, url: String) -> HandlerResult {
match download_url(url).await {
Ok(_) => bot.send_message(msg.chat.id, "downloaded"),
Err(_) => bot.send_message(msg.chat.id, "failed to download")
}.await?;
Ok(()) Ok(())
} }