Skip to content

Commit f3f3d49

Browse files
committed
Code optimization
1 parent 3141d0e commit f3f3d49

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/fetcher.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::data::increment_requests;
1+
use std::sync::Arc;
22
use reqwest::{header, Client};
33
use serde_json::Value;
4+
use crate::database::Database;
5+
use crate::logger::LOGGER;
46

57
// https://github.com/ShaheenJawadi/tiktok-video-downloader
6-
pub async fn parse_tiktok_content(url: &str, id: u64) -> Result<Box<dyn Media>, String> {
8+
pub async fn parse_tiktok_content(url: &str, id: i64, db: &Database) -> Result<Box<dyn Media>, String> {
79
let client = Client::new();
8-
println!("🔍 Fetching video metadata...");
10+
LOGGER.info("Fetching video metadata...");
911

1012
let api_url = format!("https://www.tikwm.com/api/?url={}", url);
1113
let response = client.get(&api_url)
@@ -36,11 +38,11 @@ pub async fn parse_tiktok_content(url: &str, id: u64) -> Result<Box<dyn Media>,
3638
.unwrap_or("https://moosic.my.mail.ru/file/7aa9b68114dfa1a4581ce525a1e793b1.mp3");
3739

3840
// adding +1 to requests_amount on users.json
39-
increment_requests(id).await.unwrap();
41+
db.increment_requests(id).await.unwrap();
4042

4143
if !images_url.is_empty() {
4244

43-
println!("🔍 Fetching has been finished!");
45+
LOGGER.success("Fetching has been finished!");
4446
return Ok(Box::new(
4547
PhotoContent {
4648
title: video_title.to_string(),
@@ -54,7 +56,7 @@ pub async fn parse_tiktok_content(url: &str, id: u64) -> Result<Box<dyn Media>,
5456
.as_str()
5557
.ok_or("Video URL not found in API response".to_string())?;
5658

57-
println!("🔍 Fetching has been finished!");
59+
LOGGER.success("Fetching has been finished!");
5860

5961
Ok(
6062
Box::from(VideoContent {

0 commit comments

Comments
 (0)