Upload button.py
Browse files- plugins/button.py +21 -1
plugins/button.py
CHANGED
@@ -18,7 +18,26 @@ logging.basicConfig(
|
|
18 |
)
|
19 |
logger = logging.getLogger(__name__)
|
20 |
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
async def youtube_dl_call_back(_bot, update):
|
24 |
# Constants
|
@@ -174,6 +193,7 @@ async def youtube_dl_call_back(_bot, update):
|
|
174 |
final_file_path = final_file_match.group(1)
|
175 |
download_directory = final_file_path
|
176 |
logger.info("Final file with subtitles: %s", final_file_path)
|
|
|
177 |
|
178 |
if e_response and AD_STRING_TO_REPLACE in e_response:
|
179 |
error_message = e_response.replace(AD_STRING_TO_REPLACE, "")
|
|
|
18 |
)
|
19 |
logger = logging.getLogger(__name__)
|
20 |
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
21 |
+
def find_first_matching_file_path(full_path_with_incomplete_name):
|
22 |
+
# Split the full path into directory and incomplete filename
|
23 |
+
directory, incomplete_name = os.path.split(full_path_with_incomplete_name)
|
24 |
+
|
25 |
+
# Create a regex pattern that matches the incomplete name followed by any characters
|
26 |
+
pattern = re.compile(f'^{re.escape(incomplete_name)}.*') # ^ asserts the start of the string
|
27 |
+
|
28 |
+
# Check if the directory exists
|
29 |
+
if not os.path.isdir(directory):
|
30 |
+
return None # Return None if the directory doesn't exist
|
31 |
+
|
32 |
+
# Iterate over all files in the specified directory
|
33 |
+
for filename in os.listdir(directory):
|
34 |
+
# Check if the filename matches the regex pattern
|
35 |
+
if pattern.match(filename):
|
36 |
+
# Return the full path of the first matching file
|
37 |
+
return os.path.join(directory, filename)
|
38 |
+
|
39 |
+
# Return None if no matching files are found
|
40 |
+
return None
|
41 |
|
42 |
async def youtube_dl_call_back(_bot, update):
|
43 |
# Constants
|
|
|
193 |
final_file_path = final_file_match.group(1)
|
194 |
download_directory = final_file_path
|
195 |
logger.info("Final file with subtitles: %s", final_file_path)
|
196 |
+
download_directory = find_first_matching_file_path(download_directory)
|
197 |
|
198 |
if e_response and AD_STRING_TO_REPLACE in e_response:
|
199 |
error_message = e_response.replace(AD_STRING_TO_REPLACE, "")
|