some fixes
This commit is contained in:
parent
baeb7df658
commit
013c211f14
94
bot/song.py
94
bot/song.py
@ -1,31 +1,38 @@
|
|||||||
# Copyright (C) 2021 By VeezMusicProject
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import wget
|
|
||||||
from random import randint
|
from random import randint
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import requests
|
import wget
|
||||||
import youtube_dl
|
import yt_dlp
|
||||||
from yt_dlp import YoutubeDL
|
|
||||||
from pyrogram import Client, filters
|
from pyrogram import Client, filters
|
||||||
from pyrogram.errors import FloodWait, MessageNotModified
|
from pyrogram.errors import FloodWait, MessageNotModified
|
||||||
from pyrogram.types import Message
|
from pyrogram.types import Message
|
||||||
from youtube_search import YoutubeSearch
|
from youtube_search import YoutubeSearch
|
||||||
|
from yt_dlp import YoutubeDL
|
||||||
|
|
||||||
from config import Veez
|
from config import BOT_USERNAME as bn
|
||||||
from helpers.filters import command
|
|
||||||
from helpers.decorators import humanbytes
|
from helpers.decorators import humanbytes
|
||||||
|
from helpers.filters import command
|
||||||
|
|
||||||
|
|
||||||
@Client.on_message(command(["song", f"song@{Veez.BOT_USERNAME}"]) & ~filters.channel)
|
ydl_opts = {
|
||||||
|
'format':'best',
|
||||||
|
'keepvideo':True,
|
||||||
|
'prefer_ffmpeg':False,
|
||||||
|
'geo_bypass':True,
|
||||||
|
'outtmpl':'%(title)s.%(ext)s',
|
||||||
|
'quite':True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Client.on_message(command(["song", f"song@{bn}"]) & ~filters.edited)
|
||||||
def song(_, message):
|
def song(_, message):
|
||||||
query = " ".join(message.command[1:])
|
query = " ".join(message.command[1:])
|
||||||
m = message.reply("🔎 finding song...")
|
m = message.reply("🔎 finding song...")
|
||||||
@ -46,11 +53,11 @@ def song(_, message):
|
|||||||
return
|
return
|
||||||
m.edit("📥 downloading...")
|
m.edit("📥 downloading...")
|
||||||
try:
|
try:
|
||||||
with youtube_dl.YoutubeDL(ydl_ops) as ydl:
|
with yt_dlp.YoutubeDL(ydl_ops) as ydl:
|
||||||
info_dict = ydl.extract_info(link, download=False)
|
info_dict = ydl.extract_info(link, download=False)
|
||||||
audio_file = ydl.prepare_filename(info_dict)
|
audio_file = ydl.prepare_filename(info_dict)
|
||||||
ydl.process_info(info_dict)
|
ydl.process_info(info_dict)
|
||||||
rep = f"**🎧 By @{Veez.BOT_USERNAME}**"
|
rep = f"**🎧 Uploader @{bn}**"
|
||||||
secmul, dur, dur_arr = 1, 0, duration.split(":")
|
secmul, dur, dur_arr = 1, 0, duration.split(":")
|
||||||
for i in range(len(dur_arr) - 1, -1, -1):
|
for i in range(len(dur_arr) - 1, -1, -1):
|
||||||
dur += int(float(dur_arr[i])) * secmul
|
dur += int(float(dur_arr[i])) * secmul
|
||||||
@ -65,7 +72,7 @@ def song(_, message):
|
|||||||
)
|
)
|
||||||
m.delete()
|
m.delete()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
m.edit("❌ error, wait for dev to fix")
|
m.edit("❌ error, wait for bot owner to fix")
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -79,13 +86,13 @@ def get_text(message: Message) -> [None, str]:
|
|||||||
text_to_return = message.text
|
text_to_return = message.text
|
||||||
if message.text is None:
|
if message.text is None:
|
||||||
return None
|
return None
|
||||||
if " " in text_to_return:
|
if " " not in text_to_return:
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return message.text.split(None, 1)[1]
|
return message.text.split(None, 1)[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
async def progress(current, total, message, start, type_of_ps, file_name=None):
|
async def progress(current, total, message, start, type_of_ps, file_name=None):
|
||||||
@ -100,10 +107,11 @@ async def progress(current, total, message, start, type_of_ps, file_name=None):
|
|||||||
time_to_completion = round((total - current) / speed) * 1000
|
time_to_completion = round((total - current) / speed) * 1000
|
||||||
estimated_total_time = elapsed_time + time_to_completion
|
estimated_total_time = elapsed_time + time_to_completion
|
||||||
progress_str = "{0}{1} {2}%\n".format(
|
progress_str = "{0}{1} {2}%\n".format(
|
||||||
"".join(["🔴" for _ in range(math.floor(percentage / 10))]),
|
"".join("🔴" for _ in range(math.floor(percentage / 10))),
|
||||||
"".join(["🔘" for _ in range(10 - math.floor(percentage / 10))]),
|
"".join("🔘" for _ in range(10 - math.floor(percentage / 10))),
|
||||||
round(percentage, 2),
|
round(percentage, 2),
|
||||||
)
|
)
|
||||||
|
|
||||||
tmp = progress_str + "{0} of {1}\nETA: {2}".format(
|
tmp = progress_str + "{0} of {1}\nETA: {2}".format(
|
||||||
humanbytes(current), humanbytes(total), time_formatter(estimated_total_time)
|
humanbytes(current), humanbytes(total), time_formatter(estimated_total_time)
|
||||||
)
|
)
|
||||||
@ -126,15 +134,12 @@ async def progress(current, total, message, start, type_of_ps, file_name=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_user(message: Message, text: str) -> [int, str, None]:
|
def get_user(message: Message, text: str) -> [int, str, None]:
|
||||||
if text is None:
|
asplit = None if text is None else text.split(" ", 1)
|
||||||
asplit = None
|
|
||||||
else:
|
|
||||||
asplit = text.split(" ", 1)
|
|
||||||
user_s = None
|
user_s = None
|
||||||
reason_ = None
|
reason_ = None
|
||||||
if message.reply_to_message:
|
if message.reply_to_message:
|
||||||
user_s = message.reply_to_message.from_user.id
|
user_s = message.reply_to_message.from_user.id
|
||||||
reason_ = text if text else None
|
reason_ = text or None
|
||||||
elif asplit is None:
|
elif asplit is None:
|
||||||
return None, None
|
return None, None
|
||||||
elif len(asplit[0]) > 0:
|
elif len(asplit[0]) > 0:
|
||||||
@ -152,10 +157,7 @@ def get_readable_time(seconds: int) -> str:
|
|||||||
|
|
||||||
while count < 4:
|
while count < 4:
|
||||||
count += 1
|
count += 1
|
||||||
if count < 3:
|
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
|
||||||
remainder, result = divmod(seconds, 60)
|
|
||||||
else:
|
|
||||||
remainder, result = divmod(seconds, 24)
|
|
||||||
if seconds == 0 and remainder == 0:
|
if seconds == 0 and remainder == 0:
|
||||||
break
|
break
|
||||||
time_list.append(int(result))
|
time_list.append(int(result))
|
||||||
@ -187,19 +189,6 @@ def time_formatter(milliseconds: int) -> str:
|
|||||||
return tmp[:-2]
|
return tmp[:-2]
|
||||||
|
|
||||||
|
|
||||||
ydl_opts = {
|
|
||||||
"format": "bestaudio/best",
|
|
||||||
"writethumbnail": True,
|
|
||||||
"postprocessors": [
|
|
||||||
{
|
|
||||||
"key": "FFmpegExtractAudio",
|
|
||||||
"preferredcodec": "mp3",
|
|
||||||
"preferredquality": "192",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_extension_from_url(url):
|
def get_file_extension_from_url(url):
|
||||||
url_path = urlparse(url).path
|
url_path = urlparse(url).path
|
||||||
basename = os.path.basename(url_path)
|
basename = os.path.basename(url_path)
|
||||||
@ -225,15 +214,17 @@ def time_to_seconds(times):
|
|||||||
return sum(int(x) * 60 ** i for i, x in enumerate(reversed(stringt.split(":"))))
|
return sum(int(x) * 60 ** i for i, x in enumerate(reversed(stringt.split(":"))))
|
||||||
|
|
||||||
|
|
||||||
@Client.on_message(command(["vsong", f"vsong@{Veez.BOT_USERNAME}"]) & filters.group & ~filters.edited)
|
@Client.on_message(
|
||||||
|
command(["vsong", f"vsong@{bn}", "video", f"video@{bn}"]) & ~filters.edited
|
||||||
|
)
|
||||||
async def vsong(client, message):
|
async def vsong(client, message):
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format':'best',
|
"format": "best",
|
||||||
'keepvideo':True,
|
"keepvideo": True,
|
||||||
'prefer_ffmpeg':False,
|
"prefer_ffmpeg": False,
|
||||||
'geo_bypass':True,
|
"geo_bypass": True,
|
||||||
'outtmpl':'%(title)s.%(ext)s',
|
"outtmpl": "%(title)s.%(ext)s",
|
||||||
'quite':True
|
"quite": True,
|
||||||
}
|
}
|
||||||
query = " ".join(message.command[1:])
|
query = " ".join(message.command[1:])
|
||||||
try:
|
try:
|
||||||
@ -241,13 +232,13 @@ async def vsong(client, message):
|
|||||||
link = f"https://youtube.com{results[0]['url_suffix']}"
|
link = f"https://youtube.com{results[0]['url_suffix']}"
|
||||||
title = results[0]["title"][:40]
|
title = results[0]["title"][:40]
|
||||||
thumbnail = results[0]["thumbnails"][0]
|
thumbnail = results[0]["thumbnails"][0]
|
||||||
thumb_name = f"thumb{title}.jpg"
|
thumb_name = f"{title}.jpg"
|
||||||
thumb = requests.get(thumbnail, allow_redirects=True)
|
thumb = requests.get(thumbnail, allow_redirects=True)
|
||||||
open(thumb_name, "wb").write(thumb.content)
|
open(thumb_name, "wb").write(thumb.content)
|
||||||
duration = results[0]["duration"]
|
results[0]["duration"]
|
||||||
results[0]["url_suffix"]
|
results[0]["url_suffix"]
|
||||||
results[0]["views"]
|
results[0]["views"]
|
||||||
rby = message.from_user.mention
|
message.from_user.mention
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
try:
|
try:
|
||||||
@ -256,14 +247,15 @@ async def vsong(client, message):
|
|||||||
ytdl_data = ytdl.extract_info(link, download=True)
|
ytdl_data = ytdl.extract_info(link, download=True)
|
||||||
file_name = ytdl.prepare_filename(ytdl_data)
|
file_name = ytdl.prepare_filename(ytdl_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return await msg.edit(f"🚫 **error:** {str(e)}")
|
return await msg.edit(f"🚫 **error:** {e}")
|
||||||
preview = wget.download(thumbnail)
|
preview = wget.download(thumbnail)
|
||||||
await msg.edit("📤 **uploading video...**")
|
await msg.edit("📤 **uploading video...**")
|
||||||
await message.reply_video(
|
await message.reply_video(
|
||||||
file_name,
|
file_name,
|
||||||
duration=int(ytdl_data["duration"]),
|
duration=int(ytdl_data["duration"]),
|
||||||
thumb=preview,
|
thumb=preview,
|
||||||
caption=ytdl_data['title'])
|
caption=ytdl_data["title"],
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
os.remove(file_name)
|
os.remove(file_name)
|
||||||
await msg.delete()
|
await msg.delete()
|
||||||
|
Loading…
Reference in New Issue
Block a user