19
19
import time
20
20
from datetime import datetime
21
21
22
- # the secret configuration specific things
23
- if bool (os .environ .get ("ENV" , False )):
24
- from sample_config import Config
25
- else :
26
- from config import Config
22
+ from anydlbot import (
23
+ DOWNLOAD_LOCATION ,
24
+ TG_MAX_FILE_SIZE ,
25
+ PROCESS_MAX_TIMEOUT ,
26
+ CHUNK_SIZE
27
+ )
27
28
28
29
# the Strings used for this "thing"
29
30
from translation import Translation
30
31
31
32
import pyrogram
32
33
logging .getLogger ("pyrogram" ).setLevel (logging .WARNING )
33
34
34
- from helper_funcs .display_progress import progress_for_pyrogram , humanbytes , TimeFormatter
35
+ from anydlbot . helper_funcs .display_progress import progress_for_pyrogram , humanbytes , TimeFormatter
35
36
from hachoir .metadata import extractMetadata
36
37
from hachoir .parser import createParser
37
38
# https://stackoverflow.com/a/37631799/4723940
@@ -43,7 +44,7 @@ async def ddl_call_back(bot, update):
43
44
cb_data = update .data
44
45
# youtube_dl extractors
45
46
tg_send_type , youtube_dl_format , youtube_dl_ext = cb_data .split ("=" )
46
- thumb_image_path = Config . DOWNLOAD_LOCATION + \
47
+ thumb_image_path = DOWNLOAD_LOCATION + \
47
48
"/" + str (update .from_user .id ) + ".jpg"
48
49
youtube_dl_url = update .message .reply_to_message .text
49
50
custom_file_name = os .path .basename (youtube_dl_url )
@@ -82,7 +83,7 @@ async def ddl_call_back(bot, update):
82
83
chat_id = update .message .chat .id ,
83
84
message_id = update .message .message_id
84
85
)
85
- tmp_directory_for_each_user = Config . DOWNLOAD_LOCATION + "/" + str (update .from_user .id )
86
+ tmp_directory_for_each_user = DOWNLOAD_LOCATION + "/" + str (update .from_user .id )
86
87
if not os .path .isdir (tmp_directory_for_each_user ):
87
88
os .makedirs (tmp_directory_for_each_user )
88
89
download_directory = tmp_directory_for_each_user + "/" + custom_file_name
@@ -113,14 +114,14 @@ async def ddl_call_back(bot, update):
113
114
chat_id = update .message .chat .id ,
114
115
message_id = update .message .message_id
115
116
)
116
- file_size = Config . TG_MAX_FILE_SIZE + 1
117
+ file_size = TG_MAX_FILE_SIZE + 1
117
118
try :
118
119
file_size = os .stat (download_directory ).st_size
119
120
except FileNotFoundError as exc :
120
121
download_directory = os .path .splitext (download_directory )[0 ] + "." + "mkv"
121
122
# https://stackoverflow.com/a/678242/4723940
122
123
file_size = os .stat (download_directory ).st_size
123
- if file_size > Config . TG_MAX_FILE_SIZE :
124
+ if file_size > TG_MAX_FILE_SIZE :
124
125
await bot .edit_message_text (
125
126
chat_id = update .message .chat .id ,
126
127
text = Translation .RCHD_TG_API_LIMIT ,
@@ -261,7 +262,7 @@ async def ddl_call_back(bot, update):
261
262
async def download_coroutine (bot , session , url , file_name , chat_id , message_id , start ):
262
263
downloaded = 0
263
264
display_message = ""
264
- async with session .get (url , timeout = Config . PROCESS_MAX_TIMEOUT ) as response :
265
+ async with session .get (url , timeout = PROCESS_MAX_TIMEOUT ) as response :
265
266
total_length = int (response .headers ["Content-Length" ])
266
267
content_type = response .headers ["Content-Type" ]
267
268
if "text" in content_type and total_length < 500 :
@@ -275,11 +276,11 @@ async def download_coroutine(bot, session, url, file_name, chat_id, message_id,
275
276
)
276
277
with open (file_name , "wb" ) as f_handle :
277
278
while True :
278
- chunk = await response .content .read (Config . CHUNK_SIZE )
279
+ chunk = await response .content .read (CHUNK_SIZE )
279
280
if not chunk :
280
281
break
281
282
f_handle .write (chunk )
282
- downloaded += Config . CHUNK_SIZE
283
+ downloaded += CHUNK_SIZE
283
284
now = time .time ()
284
285
diff = now - start
285
286
if round (diff % 5.00 ) == 0 or downloaded == total_length :
0 commit comments