Skip to content

Create song.py#5

Open
ramoben200 wants to merge 1 commit intoMehmetAtes21:mainfrom
ramoben200:patch-4
Open

Create song.py#5
ramoben200 wants to merge 1 commit intoMehmetAtes21:mainfrom
ramoben200:patch-4

Conversation

@ramoben200
Copy link

Telegramda yani ben boş işler müdürü :) <> @BOT_RAMO Tarafından düzenlenen ufak çaplı proje.

import os
import requests
import aiohttp
import yt_dlp
import wget

from pyrogram import Client, filters
from youtube_search import YoutubeSearch
from yt_dlp import YoutubeDL

from config import BOT_USERNAME
from helpers.filters import command

def time_to_seconds(time):
stringt = str(time)
return sum(int(x) * 60 ** i for i, x in enumerate(reversed(stringt.split(":"))))

@Client.on_message(command(["bul"]))
def bul(client, message):

user_id = message.from_user.id
user_name = message.from_user.first_name
rpk = "[" + user_name + "](tg://user?id=" + str(user_id) + ")"

query = "".join(" " + str(i) for i in message.command[1:])
print(query)
m = message.reply("•> **Arıyorum...**")
ydl_opts = {"format": "bestaudio[ext=m4a]"}
try:
    results = YoutubeSearch(query, max_results=5).to_dict()
    link = f"https://youtube.com{results[0]['url_suffix']}"
    # print(results)
    title = results[0]["title"][:40]
    thumbnail = results[0]["thumbnails"][0]
    thumb_name = f"thumb{title}.jpg"
    thumb = requests.get(thumbnail, allow_redirects=True)
    open(thumb_name, "wb").write(thumb.content)

    duration = results[0]["duration"]
    url_suffix = results[0]["url_suffix"]
    views = results[0]["views"]

except Exception as e:
    m.edit(
        "•> **Hiçbir şey bulamadım .**"
    )
    print(str(e))
    return
m.edit("•> **Şarkı indiriliyor .**")
try:
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        info_dict = ydl.extract_info(link, download=False)
        audio_file = ydl.prepare_filename(info_dict)
        ydl.process_info(info_dict)
    rep = f"▶️ **Şarkı**: [{title[:35]}]({link})\n⏳ **Süre**: `{duration}`\n•> [Ballas 𝖬𝗎𝗓𝗂𝗄 𝖡𝗈𝗍](https://t.me/Ballasresmi) 𝖳𝖺𝗋𝖺𝖿𝗂𝗇𝖽𝖺𝗇 !"
    secmul, dur, dur_arr = 1, 0, duration.split(":")
    for i in range(len(dur_arr) - 1, -1, -1):
        dur += int(dur_arr[i]) * secmul
        secmul *= 60
    message.reply_audio(
        audio_file,
        caption=rep,
        thumb=thumb_name,
        parse_mode="md",
        title=title,
        duration=dur,
    )
    m.delete()
except Exception as e:
    m.edit("❌ Error")
    print(e)

try:
    os.remove(audio_file)
    os.remove(thumb_name)
except Exception as e:
    print(e)

@Client.on_message(
command(["vbul", "vsong"]) & ~filters.edited
)
async def vsong(client, message):
ydl_opts = {
"format": "best",
"keepvideo": True,
"prefer_ffmpeg": False,
"geo_bypass": True,
"outtmpl": "%(title)s.%(ext)s",
"quite": True,
}
query = " ".join(message.command[1:])
try:
results = YoutubeSearch(query, max_results=1).to_dict()
link = f"https://youtube.com{results[0]['url_suffix']}"
title = results[0]["title"][:40]
thumbnail = results[0]["thumbnails"][0]
thumb_name = f"{title}.jpg"
thumb = requests.get(thumbnail, allow_redirects=True)
open(thumb_name, "wb").write(thumb.content)
results[0]["duration"]
results[0]["url_suffix"]
results[0]["views"]
message.from_user.mention
except Exception as e:
print(e)
try:
msg = await message.reply("•> Video İndiriyorum...")
with YoutubeDL(ydl_opts) as ytdl:
ytdl_data = ytdl.extract_info(link, download=True)
file_name = ytdl.prepare_filename(ytdl_data)
except Exception as e:
return await msg.edit(f"🚫 Hata: {e}")
preview = wget.download(thumbnail)
await msg.edit("•> Video Yüklüyorum...")
await message.reply_video(
file_name,
duration=int(ytdl_data["duration"]),
thumb=preview,
caption=ytdl_data["title"],
)
try:
os.remove(file_name)
await msg.delete()
except Exception as e:
print(e)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant