Spaces:
Paused
Paused
Akash Tiwari
commited on
Commit
·
88c3032
1
Parent(s):
80e4a50
Create downloads.py
Browse files- Powers/plugins/downloads.py +38 -0
Powers/plugins/downloads.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Add instagrapi & pytube in requirements.txt
|
| 2 |
+
from pyrogram import Client, filters
|
| 3 |
+
import urllib.request
|
| 4 |
+
from instagrapi import Client as InstaClient
|
| 5 |
+
from pytube import YouTube
|
| 6 |
+
from Powers.bot_class import Gojo as app
|
| 7 |
+
|
| 8 |
+
insta_client = InstaClient()
|
| 9 |
+
|
| 10 |
+
@app.on_message(filters.command("download"))
|
| 11 |
+
def download_media(client, message):
|
| 12 |
+
chat_id = message.chat.id
|
| 13 |
+
platform = message.text.split()[1]
|
| 14 |
+
client.send_message(chat_id, "Enter your choice 1 for Instagram 2 For YouTube:")
|
| 15 |
+
if platform == "1":
|
| 16 |
+
client.send_message(chat_id, "Please enter the Instagram post or story URL:")
|
| 17 |
+
insta_link = message.text.split()[2]
|
| 18 |
+
|
| 19 |
+
media = insta_client.media_info(insta_link)
|
| 20 |
+
|
| 21 |
+
video_url = media.video_versions[0].url
|
| 22 |
+
urllib.request.urlretrieve(video_url, "video.mp4")
|
| 23 |
+
|
| 24 |
+
client.send_video(chat_id, video="video.mp4")
|
| 25 |
+
|
| 26 |
+
elif platform == "2":
|
| 27 |
+
client.send_message(chat_id, "Please enter the YouTube link:")
|
| 28 |
+
yt_link = message.text.split()[2]
|
| 29 |
+
|
| 30 |
+
yt = YouTube(yt_link)
|
| 31 |
+
stream = yt.streams.get_highest_resolution()
|
| 32 |
+
|
| 33 |
+
stream.download(output_path="./", filename="video.mp4")
|
| 34 |
+
|
| 35 |
+
client.send_video(chat_id, video="video.mp4")
|
| 36 |
+
|
| 37 |
+
else:
|
| 38 |
+
client.send_message(chat_id, "Invalid platform choice. Please enter 1 for Instagram or 2 for YouTube.")
|