-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_telegram_video.py
More file actions
27 lines (22 loc) Β· 947 Bytes
/
fetch_telegram_video.py
File metadata and controls
27 lines (22 loc) Β· 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from telethon.sync import TelegramClient
import os
# Telegram API credentials (get from https://my.telegram.org)
api_id = 24378977 # π Replace with your API ID
api_hash = "fad43dca16d4183c601a2e3e7eec7d44" # π Replace with your API Hash
channel_username = "https://t.me/testingnowdone" # π e.g. "t.me/mychannel"
# Output path
output_folder = "video"
output_file = os.path.join(output_folder, "video.mp4")
def fetch_video():
if not os.path.exists(output_folder):
os.makedirs(output_folder)
with TelegramClient("session", api_id, api_hash) as client:
messages = client.get_messages(channel_username, limit=10)
for msg in messages:
if msg.video:
print("π₯ Found video:", msg.id)
msg.download_media(file=output_file)
print("β
Saved to:", output_file)
return output_file
print("β No video found.")
return None