Jaybee18 / sample_focus_downloader

Free mp3 downloader for sample focus
3 stars 2 forks source link

Downloader Not Working #1

Open Moykhaile opened 4 months ago

Moykhaile commented 4 months ago

My guess is SampleFocus found a way to bypass the downloader and thus it's not working. If someone could fix it, it would be awesome!

Jaybee18 commented 4 months ago

Yes, they now have protected resource links

I don't know how to fix it tho :/

Moykhaile commented 4 months ago

I was able to download audio using the direct link located in the

import requests
import sys
from bs4 import BeautifulSoup
import re
import os
from urllib.parse import urlparse

def get_audio_name_from_url(audio_url):
    parsed_url = urlparse(audio_url)
    file_name = os.path.basename(parsed_url.path)

    file_name = file_name.split("?")[0]
    return re.sub(r'[_?\*\\/\"<>:|]', ' ',file_name)

audio_url = sys.argv[1]

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
    'Referer': 'https://samplefocus.com/',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'Connection': 'keep-alive',
}

response = requests.get(audio_url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
if response.status_code == 200:
    with open("downloads/" + get_audio_name_from_url(audio_url), 'wb') as file:
        file.write(response.content)
    print("Download complete")
else:
    print(f"Failed to download the audio file: {response.status_code}")

Then I can just go inside the console:

py samplefocus_dl.py https://d9olupt5igjta.cloudfront.net/samples/sample_files/432658/f4ee5245b2e7e9557ca534be09fc55fbb8d7dc20/mp3/_Untitled_track_29.mp3?1715874104
Jaybee18 commented 4 months ago

That link doesn't work for me.

Can you make sure you can download with that link using e.g. curl <link> -o test.mp3?

Moykhaile commented 4 months ago

that doesn't work but the code works for me

Jaybee18 commented 4 months ago

You're right. I think you can't get the element with bs anymore, because the elements get dynamically created by React. I'll try to work on a solution