Skip to content

Instantly share code, notes, and snippets.

@Hunter87ff
Last active December 2, 2023 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hunter87ff/c961ff53617d7e2b3b61cc2859f97926 to your computer and use it in GitHub Desktop.
Save Hunter87ff/c961ff53617d7e2b3b61cc2859f97926 to your computer and use it in GitHub Desktop.
import discord
import os
from discord.ext import commands
import bs4
from bs4 import BeautifulSoup
#import youtube_dl
intents = discord.Intents.default()
intents.message_content = True
intents.reactions = True
intents.members = True
intents.voice_states = True
intents.guilds = True
bot = commands.Bot(command_prefix='?', intents=intents)
@bot.event
async def on_ready():
print(bot.user)
import requests
from bs4 import BeautifulSoup
def fetch_audio(url):
data = requests.get(url).content
soup = BeautifulSoup(data, features="html5lib")
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="html5lib")
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)
@bot.command()
async def join(ctx):
await ctx.author.voice.channel.connect()
@bot.command()
async def play(ctx, *, query):
url = fetch_url(query)
if ctx.voice_client:
vc = ctx.voice_client
if ctx.voice_client.is_playing():
ctx.voice_client.stop()
if ctx.voice_client==None:
vc = await ctx.author.voice.channel.connect()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
source = await discord.FFmpegOpusAudio.from_probe(url)
vc.play(source)
bot.run(os.environ["tk"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment