Skip to content

Commit

Permalink
fix for premium files when they are not direct links
Browse files Browse the repository at this point in the history
  • Loading branch information
NicKoehler committed Apr 25, 2024
1 parent 593b862 commit d53cec4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mediafire_rs"
description = "Downloads files and folders from mediafire"
authors = ["NicKoehler <[email protected]"]
version = "0.1.2"
version = "0.1.3"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
13 changes: 7 additions & 6 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ use crate::utils::{create_directory_if_not_exists, parse_download_link, save_fil
use anyhow::{anyhow, Result};
use colored::*;
use futures::future::join_all;
use reqwest::get;
use reqwest::{get, Client};
use std::path::PathBuf;
use tokio::try_join;

const NORMAL_DOWNLOAD_LINK: &str = "https://www.mediafire.com/file/";

#[async_recursion::async_recursion]
pub async fn download_folder(folder_key: &str, path: PathBuf, chunk: u32) -> Result<()> {
create_directory_if_not_exists(&path).await?;
Expand Down Expand Up @@ -122,9 +120,12 @@ pub async fn download_file(file: &File, path: PathBuf) -> Result<()> {
);

let download_link = {
if file.links.normal_download.starts_with(NORMAL_DOWNLOAD_LINK) {
let body = get(&file.links.normal_download).await?.text().await?;
parse_download_link(&body)
let client = Client::new();
let request = client.head(&file.links.normal_download).build()?;
let body = client.execute(request).await?;

if body.headers().get("content-type").unwrap() == &"text/html; charset=UTF-8" {
parse_download_link(&get(&file.links.normal_download).await?.text().await?)
} else {
Some(file.links.normal_download.clone())
}
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ async fn main() -> Result<()> {
}
} else {
create_directory_if_not_exists(&path).await?;

let response = file::get_info(&key).await;
if let Ok(response) = response {
if let Some(file_info) = response.file_info {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::PathBuf;
use tokio::io::AsyncWriteExt;

pub fn match_mediafire_valid_url(url: &str) -> Option<(String, String)> {
let re = Regex::new(r"mediafire\.com/(file|folder)/(\w+)").unwrap();
let re = Regex::new(r"mediafire\.com/(file|file_premium|folder)/(\w+)").unwrap();
let matches = re.captures(url);

if let Some(captures) = matches {
Expand Down

0 comments on commit d53cec4

Please sign in to comment.