Skip to content

Instantly share code, notes, and snippets.

@ImanMousavi
Last active November 2, 2025 11:26
Show Gist options
  • Select an option

  • Save ImanMousavi/390e29a5f498fdd7340db520423001e3 to your computer and use it in GitHub Desktop.

Select an option

Save ImanMousavi/390e29a5f498fdd7340db520423001e3 to your computer and use it in GitHub Desktop.
songsara mp3 downloder
import os
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
from tqdm import tqdm
# pip install requests beautifulsoup4 tqdm
def download(url_id):
# import pdb; pdb.set_trace()
try:
url = f"https://songsara.net/{url_id}/"
response = requests.get(url)
response.raise_for_status()
# Parse the HTML content
soup = BeautifulSoup(response.text, "html.parser")
# Find all tags with data-src containing MP3 links
tags = soup.find_all(attrs={"data-src": True})
mp3_links = [urljoin(url, tag["data-src"]) for tag in tags if tag["data-src"].endswith(".mp3")]
if not mp3_links:
print("No MP3 files found.")
return
mp3_links = list(set(mp3_links))
unique_count = len(mp3_links)
if unique_count > 1:
title = soup.findAll('h2', {'class': 'AL-Si'})
output_folder = title[0].get_text()
if not os.path.exists(output_folder):
os.makedirs(output_folder)
cover_meta = soup.find('meta', property='og:image')
cover_url = cover_meta['content']
if cover_meta:
cover_response = requests.get(cover_url)
cover_file_name = os.path.join(output_folder, 'cover.jpg')
with open(cover_file_name, 'wb') as f:
f.write(cover_response.content)
print(f"Cover image saved as: {cover_file_name}")
else:
output_folder = ''
# Download each MP3 file
for mp3_url in mp3_links:
file_name = os.path.join(output_folder, os.path.basename(mp3_url)).replace(' SONGSARA.NET', '').strip()
# Check if the file already exists
if os.path.exists(file_name):
print(f"File {file_name} already exists. Skipping.")
continue
print(f"Downloading: {file_name}")
mp3_response = requests.get(mp3_url, stream=True)
mp3_response.raise_for_status()
# Get the total size of the file
total_size = int(mp3_response.headers.get("content-length", 0))
# Initialize tqdm progress bar
with open(file_name, "wb") as file, tqdm(
total=total_size, unit="B", unit_scale=True, desc=file_name
) as bar:
for chunk in mp3_response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
bar.update(len(chunk)) # Update the progress bar
print("\nDownload complete.")
print("All downloads finished.")
except requests.exceptions.RequestException as e:
print(f"Error during download: {e}")
if __name__ == '__main__':
album_id= "173853"
download(album_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment