some fixes

This commit is contained in:
levina 2021-10-25 18:51:37 +07:00 committed by GitHub
parent 7f7d97aec4
commit aa2a6c8e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
# Copyright (C) 2021 By Veez Music-Project
from __future__ import unicode_literals from __future__ import unicode_literals
import asyncio import asyncio
@ -9,6 +11,7 @@ from urllib.parse import urlparse
import aiofiles import aiofiles
import aiohttp import aiohttp
import requests
import wget import wget
import yt_dlp import yt_dlp
from pyrogram import Client, filters from pyrogram import Client, filters
@ -18,17 +21,17 @@ from youtube_search import YoutubeSearch
from yt_dlp import YoutubeDL from yt_dlp import YoutubeDL
from config import BOT_USERNAME as bn from config import BOT_USERNAME as bn
from helpers.decorators import humanbytes from driver.decorators import humanbytes
from helpers.filters import command from driver.filters import command
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
} }
@ -42,7 +45,7 @@ def song(_, 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"] duration = results[0]["duration"]
@ -51,7 +54,7 @@ def song(_, message):
m.edit("❌ song not found.\n\nplease give a valid song name.") m.edit("❌ song not found.\n\nplease give a valid song name.")
print(str(e)) print(str(e))
return return
m.edit("📥 downloading...") m.edit("📥 downloading file...")
try: try:
with yt_dlp.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)
@ -62,6 +65,7 @@ def song(_, message):
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
secmul *= 60 secmul *= 60
m.edit("📤 uploading file...")
message.reply_audio( message.reply_audio(
audio_file, audio_file,
caption=rep, caption=rep,
@ -113,8 +117,7 @@ async def progress(current, total, message, start, type_of_ps, file_name=None):
) )
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))
)
if file_name: if file_name:
try: try:
await message.edit( await message.edit(
@ -157,7 +160,9 @@ def get_readable_time(seconds: int) -> str:
while count < 4: while count < 4:
count += 1 count += 1
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24) remainder, result = divmod(
seconds, 60) if count < 3 else 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))
@ -206,12 +211,13 @@ async def download_song(url):
return song_name return song_name
is_downloading = False
def time_to_seconds(times): def time_to_seconds(times):
stringt = str(times) stringt = str(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( @Client.on_message(
@ -261,3 +267,20 @@ async def vsong(client, message):
await msg.delete() await msg.delete()
except Exception as e: except Exception as e:
print(e) print(e)
@Client.on_message(command(["lyric", f"lyric@{bn}"]))
async def lyrics(_, message):
try:
if len(message.command) < 2:
await message.reply_text("» **give a lyric name too.**")
return
query = message.text.split(None, 1)[1]
rep = await message.reply_text("🔎 **searching lyrics...**")
resp = requests.get(
f"https://api-tede.herokuapp.com/api/lirik?l={query}"
).json()
result = f"{resp['data']}"
await rep.edit(result)
except Exception:
await rep.edit("❌ **lyrics not found.**\n\n» **please give a valid song name.**")