Mithronn / rusty_ytdl

A Rust library for Youtube video searcher and downloader
https://docs.rs/rusty_ytdl
MIT License
107 stars 20 forks source link

fix downloading in a tokio thread #2

Closed BKSalman closed 1 year ago

BKSalman commented 1 year ago

When trying to download in a new tokio thread it gives this error:


    = help: within `tendril::tendril::NonAtomic`, the trait `Sync` is not implemented for `Cell<usize>`
note: future is not `Send` as this value is used across an await
   --> /home/salman/.cargo/registry/src/github.com-1ecc6299db9ec823/rusty_ytdl-0.4.1/src/info.rs:202:84
    |
133 |         let document = Html::parse_document(&response);
    |             -------- has type `scraper::html::Html` which is not `Send`
...
202 |                 get_functions(get_html5player(response.as_str()).unwrap(), &client).await?,
    |                                                                                    ^^^^^^ await occurs here, with `document` maybe used later
...
208 |     }
    |     - `document` is later dropped here
note: required by a bound in `tokio::spawn`
   --> /home/salman/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.26.0/src/task/spawn.rs:163:21
    |
163 |         T: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`

so the only thing needed was to put the parsed html document in a scope to make sure it drops properly, and satisfy the borrow checker

I also added an example for download :)

feel free to comment on anything

Mithronn commented 1 year ago

thanks for the PR