forked from MaxxRider/Leech-Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.py
83 lines (76 loc) · 3.18 KB
/
download.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) gautamajay52 | Shrimadhav U K
import asyncio
import logging
import math
import os
import re
import subprocess
import time
from datetime import datetime
from pathlib import Path
from pyrogram import Client, filters
from tobrot import DOWNLOAD_LOCATION, LOGGER, TELEGRAM_LEECH_UNZIP_COMMAND
from tobrot.helper_funcs.create_compressed_archive import unzip_me, get_base_name
from tobrot.helper_funcs.display_progress import Progress
from tobrot.helper_funcs.upload_to_tg import upload_to_gdrive
async def down_load_media_f(client, message): # to be removed
user_command = message.command[0]
user_id = message.from_user.id
if message.reply_to_message is not None:
the_real_download_location, mess_age = await download_tg(client, message)
the_real_download_location_g = the_real_download_location
if user_command == TELEGRAM_LEECH_UNZIP_COMMAND.lower():
try:
check_ifi_file = get_base_name(the_real_download_location)
file_up = await unzip_me(the_real_download_location)
if os.path.exists(check_ifi_file):
the_real_download_location_g = file_up
except Exception as ge:
LOGGER.info(ge)
LOGGER.info(
f"Can't extract {os.path.basename(the_real_download_location)}, Uploading the same file"
)
await upload_to_gdrive(the_real_download_location_g, mess_age, message, user_id)
else:
await mess_age.edit_text(
"Reply to a Telegram Media, to upload to the Cloud Drive."
)
async def download_tg(client, message):
user_id = message.from_user.id
LOGGER.info(user_id)
mess_age = await message.reply_text("**DownloadinG...**", quote=True)
if not os.path.isdir(DOWNLOAD_LOCATION):
os.makedirs(DOWNLOAD_LOCATION)
rep_mess = message.reply_to_message
if rep_mess is not None:
file = [rep_mess.document, rep_mess.video, rep_mess.audio]
file_name = [fi for fi in file if fi is not None][0].file_name
start_t = datetime.now()
download_location = str(Path("./").resolve()) + "/"
c_time = time.time()
prog = Progress(user_id, client, mess_age)
try:
the_real_download_location = await client.download_media(
message=message.reply_to_message,
file_name=download_location,
progress=prog.progress_for_pyrogram,
progress_args=(f"**• Downloading :** `{file_name}`", c_time)
)
except Exception as g_e:
await mess_age.edit(str(g_e))
LOGGER.error(g_e)
return
end_t = datetime.now()
ms = (end_t - start_t).seconds
LOGGER.info(the_real_download_location)
await asyncio.sleep(2)
if the_real_download_location:
await mess_age.edit_text(
f"Downloaded to <code>{the_real_download_location}</code> in <u>{ms}</u> seconds"
)
else:
await mess_age.edit_text("😔 Download Cancelled or some error happened")
return None, mess_age
return the_real_download_location, mess_age