mirror of
https://gitlab.com/news-flash/article_scraper.git
synced 2025-07-08 16:40:00 +02:00
special handling for youtube videos
This commit is contained in:
parent
a871d5b82e
commit
82a0a46323
2 changed files with 49 additions and 0 deletions
23
src/lib.rs
23
src/lib.rs
|
@ -1,6 +1,7 @@
|
|||
mod article;
|
||||
mod config;
|
||||
mod error;
|
||||
mod youtube;
|
||||
pub mod images;
|
||||
|
||||
use self::error::{ScraperError, ScraperErrorKind};
|
||||
|
@ -58,6 +59,11 @@ impl ArticleScraper {
|
|||
client: &Client,
|
||||
) -> Result<Article, ScraperError> {
|
||||
info!("Scraping article: '{}'", url.as_str());
|
||||
|
||||
if let Some(article) = youtube::Youtube::handle(&url) {
|
||||
return Ok(article);
|
||||
}
|
||||
|
||||
let response = client
|
||||
.head(url.clone())
|
||||
.send()
|
||||
|
@ -834,4 +840,21 @@ mod tests {
|
|||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(basic_scheduler)]
|
||||
async fn youtube() {
|
||||
let config_path = PathBuf::from(r"./resources/tests/");
|
||||
let url = url::Url::parse(
|
||||
"https://www.youtube.com/watch?v=lHRkYLcmFY8",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let grabber = ArticleScraper::new(config_path);
|
||||
let article = grabber.parse(url, false, &Client::new()).await.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
article.html,
|
||||
Some("<iframe width=\"650\" height=\"350\" frameborder=\"0\" src=\"https://www.youtube-nocookie.com/embed/lHRkYLcmFY8\" allowfullscreen></iframe>".into())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue