fixed video downloader
This commit is contained in:
parent
8e20300b4a
commit
1db42e47a6
103
bot/song.py
103
bot/song.py
@ -4,6 +4,7 @@ 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
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ import aiofiles
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import requests
|
import requests
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
|
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, InlineKeyboardButton, InlineKeyboardMarkup
|
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
@ -225,67 +227,46 @@ def time_to_seconds(times):
|
|||||||
|
|
||||||
|
|
||||||
@Client.on_message(command(["vsong", f"vsong@{Veez.BOT_USERNAME}"]) & filters.group & ~filters.edited)
|
@Client.on_message(command(["vsong", f"vsong@{Veez.BOT_USERNAME}"]) & filters.group & ~filters.edited)
|
||||||
async def vsong(_, message: Message):
|
async def vsong(client, message):
|
||||||
query = ''
|
ydl_opts = {
|
||||||
for i in message.command[1:]:
|
'format':'best',
|
||||||
query += ' ' + str(i)
|
'keepvideo':True,
|
||||||
print(query)
|
'prefer_ffmpeg':False,
|
||||||
k = await message.reply_text("🔎 **searching video...**")
|
'geo_bypass':True,
|
||||||
ydl_ops = {
|
'outtmpl':'%(title)s.%(ext)s',
|
||||||
"format": "best[ext=mp4]",
|
'quite':True
|
||||||
"geo-bypass": True,
|
}
|
||||||
"nocheckcertificate": True,
|
query = message.command[1]
|
||||||
"outtmpl": "downloads/%(id)s.%(ext)s",
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
results = []
|
results = YoutubeSearch(query, max_results=1).to_dict()
|
||||||
count = 0
|
link = f"https://youtube.com{results[0]['url_suffix']}"
|
||||||
while len(results) == 0 and count < 6:
|
title = results[0]["title"][:40]
|
||||||
if count > 0:
|
thumbnail = results[0]["thumbnails"][0]
|
||||||
await asyncio.sleep(1)
|
thumb_name = f"thumb{title}.jpg"
|
||||||
results = YoutubeSearch(query, max_results=1).to_dict()
|
thumb = requests.get(thumbnail, allow_redirects=True)
|
||||||
count += 1
|
open(thumb_name, "wb").write(thumb.content)
|
||||||
try:
|
duration = results[0]["duration"]
|
||||||
link = f"https://youtube.com{results[0]['url_suffix']}"
|
results[0]["url_suffix"]
|
||||||
# print(results)
|
results[0]["views"]
|
||||||
title = results[0]["title"]
|
rby = message.from_user.mention
|
||||||
thumbnail = results[0]["thumbnails"][0]
|
except Exception as e:
|
||||||
duration = int(float(results[0]["duration"]))
|
print(e)
|
||||||
views = results[0]["views"]
|
try:
|
||||||
thumb_name = f'thumb{message.message_id}.jpg'
|
msg = await message.reply("📥 **downloading video...**")
|
||||||
thumb = requests.get(thumbnail, allow_redirects=True)
|
with YoutubeDL(ydl_opts) as ytdl:
|
||||||
open(thumb_name, 'wb').write(thumb.content)
|
ytdl_data = ytdl.extract_info(link, download=True)
|
||||||
except Exception as e:
|
file_name = ytdl.prepare_filename(ytdl_data)
|
||||||
print(e)
|
except Exception as e:
|
||||||
await k.edit(
|
return await msg.edit(f"🚫 **error:** {str(e)}")
|
||||||
'❌ **video not found, please give a valid video name.\n\n» if you think this is an error report to '
|
preview = wget.download(thumbnail)
|
||||||
'@VeezSupportGroup**')
|
await msg.edit("📤 **uploading video...**")
|
||||||
return
|
await message.reply_video(
|
||||||
except Exception as e:
|
file_name,
|
||||||
await k.edit(
|
duration=int(ytdl_data["duration"]),
|
||||||
"💡 **please give a video name too you want to download.**\n\n» for example: `/vsong runaway`"
|
thumb=preview,
|
||||||
)
|
caption=ytdl_data['title'])
|
||||||
print(str(e))
|
try:
|
||||||
return
|
os.remove(file_name)
|
||||||
await k.edit("📥 **downloading file...**")
|
await msg.delete()
|
||||||
try:
|
|
||||||
with youtube_dl.YoutubeDL(ydl_ops) as ydl:
|
|
||||||
info_dict = ydl.extract_info(link, download=False)
|
|
||||||
video_file = ydl.prepare_filename(info_dict)
|
|
||||||
ydl.process_info(info_dict)
|
|
||||||
caption = f"🏷 Name: {title}\n💡 Views: `{views}`\n🎧 Request by: {message.from_user.mention()}\n\n⚡ " \
|
|
||||||
f"__Powered by Veez Music A.I__ "
|
|
||||||
buttons = InlineKeyboardMarkup([[InlineKeyboardButton("🗑 Close", callback_data="cls")]])
|
|
||||||
await k.edit("📤 **uploading file...**")
|
|
||||||
await message.reply_video(video_file, caption=caption, duration=duration, thumb=thumb_name,
|
|
||||||
reply_markup=buttons, supports_streaming=True)
|
|
||||||
await k.delete()
|
|
||||||
except Exception as e:
|
|
||||||
await k.edit(f'❌ **something went wrong !** \n`{e}`')
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
os.remove(video_file)
|
|
||||||
os.remove(thumb_name)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
pass
|
|
||||||
|
Loading…
Reference in New Issue
Block a user