Skip to content

Instantly share code, notes, and snippets.

@Hunter87ff
Created March 8, 2023 15:38
Show Gist options
  • Save Hunter87ff/93ffc5251aecaaabe8d29731baa3e60c to your computer and use it in GitHub Desktop.
Save Hunter87ff/93ffc5251aecaaabe8d29731baa3e60c to your computer and use it in GitHub Desktop.
get mp3 link from search query
import requests
from bs4 import BeautifulSoup
def fetch_audio(url):
data = requests.get(url).content
soup = BeautifulSoup(data,'html')
images = soup.findAll('source')
for image in images:
img_url = image.get('src')
if ".mp3" in str(img_url):
img_url = img_url.replace(" ", "%20")
print(img_url)
return img_url
def fetch_url(name:str):
i = name
nsr = f"https://www.google.com/search?q={i}&sitesearch=www.pagalworld.tv"
if " " in nsr:
nsr = nsr.replace(" ", "+")
print(nsr)
data = requests.get(nsr).content
soup = BeautifulSoup(data,features="lxml")
images = soup.findAll('a')
for image in images:
img_url = image.get('href')
if "download.html" in str(img_url):
st = str(img_url).find("https://www.pagalworld")
en = str(img_url).find(".html") + 5
print(img_url[st:en])
return fetch_audio(url=img_url[st:en])
@bot.command()
async def dn(ctx, *, query):
music = fetch_url(query)
await ctx.send(music)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment