|
2 | 2 |
|
3 | 3 |
|
4 | 4 | import os |
| 5 | +import json |
5 | 6 | import GPUtil |
6 | 7 | import shutil |
7 | 8 | import logging |
|
14 | 15 | from colab_leecher.utility.variables import BOT, MSG, BotTimes, Paths, Messages |
15 | 16 | from colab_leecher.utility.helper import ( |
16 | 17 | getSize, |
| 18 | + fileType, |
17 | 19 | keyboard, |
18 | 20 | multipartArchive, |
19 | 21 | sizeUnit, |
@@ -127,7 +129,12 @@ async def sizeChecker(file_path, remove: bool): |
127 | 129 | ): |
128 | 130 | await splitArchive(file_path, max_size) |
129 | 131 | else: |
130 | | - await archive(file_path, True, remove) |
| 132 | + f_type = fileType(file_path) |
| 133 | + if f_type == "video" and BOT.Options.is_split: |
| 134 | + # TODO: Store the size in a constant variable |
| 135 | + await splitVideo(file_path, 2000, remove) |
| 136 | + else: |
| 137 | + await archive(file_path, True, remove) |
131 | 138 | await sleep(2) |
132 | 139 | return True |
133 | 140 | else: |
@@ -157,18 +164,19 @@ async def archive(path, is_split, remove: bool): |
157 | 164 | else: |
158 | 165 | cmd = f'7z a -mx=0 -tzip -p{BOT.Options.zip_pswd} {split} "{Paths.temp_zpath}/{name}.zip" {path}' |
159 | 166 | proc = subprocess.Popen(cmd, shell=True) |
160 | | - total = sizeUnit(getSize(path)) |
| 167 | + total_size = getSize(path) |
| 168 | + total_in_unit = sizeUnit(total_size) |
161 | 169 | while proc.poll() is None: |
162 | 170 | speed_string, eta, percentage = speedETA( |
163 | | - BotTimes.task_start, getSize(Paths.temp_zpath), getSize(path) |
| 171 | + BotTimes.task_start, getSize(Paths.temp_zpath), total_size |
164 | 172 | ) |
165 | 173 | await status_bar( |
166 | 174 | Messages.status_head, |
167 | 175 | speed_string, |
168 | 176 | percentage, |
169 | 177 | getTime(eta), |
170 | 178 | sizeUnit(getSize(Paths.temp_zpath)), |
171 | | - total, |
| 179 | + total_in_unit, |
172 | 180 | "Xr-Zipp 🔒", |
173 | 181 | ) |
174 | 182 | await sleep(1) |
@@ -286,3 +294,55 @@ async def splitArchive(file_path, max_size): |
286 | 294 | # Get next chunk |
287 | 295 | chunk = f.read(max_size) |
288 | 296 | i += 1 # Increment chunk counter |
| 297 | + |
| 298 | + |
| 299 | +async def splitVideo(file_path, max_size, remove: bool): |
| 300 | + global Paths, BOT, MSG, Messages |
| 301 | + _, filename = ospath.split(file_path) |
| 302 | + just_name, extension = ospath.splitext(filename) |
| 303 | + |
| 304 | + # FFmpeg command to get video information in JSON format |
| 305 | + cmd = ["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", file_path] |
| 306 | + |
| 307 | + bitrate = None |
| 308 | + try: |
| 309 | + # Run the command and get output |
| 310 | + output = subprocess.check_output(cmd) |
| 311 | + video_info = json.loads(output) |
| 312 | + # Get bitrate in bits per second |
| 313 | + bitrate = float(video_info["format"]["bit_rate"]) |
| 314 | + except subprocess.CalledProcessError: |
| 315 | + logging.error("Error: Could not get video bitrate") |
| 316 | + bitrate = 1000 |
| 317 | + |
| 318 | + # Convert target size from MB to bits |
| 319 | + target_size_bits = max_size * 8 * 1024 * 1024 |
| 320 | + |
| 321 | + # Calculate duration in seconds |
| 322 | + duration = int(target_size_bits / bitrate) |
| 323 | + |
| 324 | + cmd = f'ffmpeg -i {file_path} -c copy -f segment -segment_time {duration} -reset_timestamps 1 "{Paths.temp_zpath}/{just_name}.part%03d{extension}"' |
| 325 | + |
| 326 | + Messages.status_head = f"<b>✂️ SPLITTING » </b>\n\n<code>{filename}</code>\n" |
| 327 | + BotTimes.task_start = datetime.now() |
| 328 | + |
| 329 | + proc = subprocess.Popen(cmd, shell=True) |
| 330 | + total_size = getSize(file_path) |
| 331 | + total_in_unit = sizeUnit(total_size) |
| 332 | + while proc.poll() is None: |
| 333 | + speed_string, eta, percentage = speedETA( |
| 334 | + BotTimes.task_start, getSize(Paths.temp_zpath), total_size |
| 335 | + ) |
| 336 | + await status_bar( |
| 337 | + Messages.status_head, |
| 338 | + speed_string, |
| 339 | + percentage, |
| 340 | + getTime(eta), |
| 341 | + sizeUnit(getSize(Paths.temp_zpath)), |
| 342 | + total_in_unit, |
| 343 | + "Xr-Split ✂️", |
| 344 | + ) |
| 345 | + await sleep(1) |
| 346 | + |
| 347 | + if remove: |
| 348 | + os.remove(file_path) |
0 commit comments