Skip to content

Commit

Permalink
Update saavn.py
Browse files Browse the repository at this point in the history
  • Loading branch information
New-dev0 authored May 19, 2024
1 parent 094a8c9 commit 06b2f53
Showing 1 changed file with 72 additions and 3 deletions.
75 changes: 72 additions & 3 deletions plugins/saavn.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os

from telethon.tl.types import DocumentAttributeAudio
from utilities.tools import saavn_search
from telethon.tl.types import DocumentAttributeAudio, InputWebDocument as wb

from . import fast_download, ultroid_cmd
from database._core import InlinePlugin
from .. import fetch, fast_download, ultroid_cmd, in_pattern, Button, DocumentAttributeAudio as Audio


@ultroid_cmd(
Expand Down Expand Up @@ -44,3 +44,72 @@ async def siesace(e):
)
await eve.delete()
os.remove(thumb)


async def saavn_search(query: str):
try:
data = await fetch(
url=f"https://saavn-api.vercel.app/search/{query.replace(' ', '%20')}",
re_json=True,
)
except BaseException:
data = None
return data


_savn_cache = {}


@in_pattern("saavn", owner=True)
async def savn_s(event):
try:
query = event.text.split(maxsplit=1)[1].lower()
except IndexError:
return await event.answer(
[], switch_pm="Enter Query to search 🔍", switch_pm_param="start"
)
if query in _savn_cache:
return await event.answer(
_savn_cache[query],
switch_pm=f"Showing Results for {query}",
switch_pm_param="start",
)
results = await saavn_search(query)
swi = "🎵 Saavn Search" if results else "No Results Found!"
res = []
for song in results:
thumb = wb(song["image"], 0, "image/jpeg", [])
text = f"• **Title :** {song['title']}"
text += f"\n• **Year :** {song['year']}"
text += f"\n• **Lang :** {song['language']}"
text += f"\n• **Artist :** {song['artists']}"
text += f"\n• **Release Date :** {song['release_date']}"
res.append(
await event.builder.article(
title=song["title"],
description=song["artists"],
type="audio",
text=text,
include_media=True,
buttons=Button.switch_inline(
"Search Again 🔍", query="saavn", same_peer=True
),
thumb=thumb,
content=wb(
song["url"],
0,
"audio/mp4",
[
Audio(
title=song["title"],
duration=int(song["duration"]),
performer=song["artists"],
)
],
),
)
)
await event.answer(res, switch_pm=swi, switch_pm_param="start")
_savn_cache.update({query: res})

InlinePlugin.update({"Sᴀᴀᴠɴ sᴇᴀʀᴄʜ": "saavn"})

0 comments on commit 06b2f53

Please sign in to comment.