Skip to content

Commit 59e7655

Browse files
authored
Merge pull request #46 from XronTrix10/preview
Stable update for Video split support
2 parents 3c82170 + 623dbf0 commit 59e7655

File tree

4 files changed

+86
-8
lines changed

4 files changed

+86
-8
lines changed

colab_leecher/__main__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ async def handle_options(client, callback_query):
184184
elif callback_query.data == "video":
185185
keyboard = InlineKeyboardMarkup(
186186
[
187+
[
188+
InlineKeyboardButton("Split Videos", callback_data="split-true"),
189+
InlineKeyboardButton("Zip Videos", callback_data="split-false"),
190+
],
187191
[
188192
InlineKeyboardButton("Convert", callback_data="convert-true"),
189193
InlineKeyboardButton(
@@ -202,7 +206,7 @@ async def handle_options(client, callback_query):
202206
]
203207
)
204208
await callback_query.message.edit_text(
205-
f"CHOOSE YOUR DESIRED OPTION ⚙️ »\n\n╭⌬ CONVERT » <code>{BOT.Setting.convert_video}</code>\n├⌬ OUTPUT FORMAT » <code>{BOT.Options.video_out}</code>\n╰⌬ OUTPUT QUALITY » <code>{BOT.Setting.convert_quality}</code>",
209+
f"CHOOSE YOUR DESIRED OPTION ⚙️ »\n\n╭⌬ CONVERT » <code>{BOT.Setting.convert_video}</code>\n├⌬ SPLIT » <code>{BOT.Setting.split_video}</code>\n├⌬ OUTPUT FORMAT » <code>{BOT.Options.video_out}</code>\n╰⌬ OUTPUT QUALITY » <code>{BOT.Setting.convert_quality}</code>",
206210
reply_markup=keyboard,
207211
)
208212
elif callback_query.data == "caption":
@@ -269,6 +273,14 @@ async def handle_options(client, callback_query):
269273
await send_settings(
270274
client, callback_query.message, callback_query.message.id, False
271275
)
276+
elif callback_query.data in ["split-true", "split-false"]:
277+
BOT.Options.is_split = True if callback_query.data == "split-true" else False
278+
BOT.Setting.split_video = (
279+
"Split Videos" if callback_query.data == "split-true" else "Zip Videos"
280+
)
281+
await send_settings(
282+
client, callback_query.message, callback_query.message.id, False
283+
)
272284
elif callback_query.data in [
273285
"convert-true",
274286
"convert-false",

colab_leecher/utility/converters.py

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import os
5+
import json
56
import GPUtil
67
import shutil
78
import logging
@@ -14,6 +15,7 @@
1415
from colab_leecher.utility.variables import BOT, MSG, BotTimes, Paths, Messages
1516
from colab_leecher.utility.helper import (
1617
getSize,
18+
fileType,
1719
keyboard,
1820
multipartArchive,
1921
sizeUnit,
@@ -127,7 +129,12 @@ async def sizeChecker(file_path, remove: bool):
127129
):
128130
await splitArchive(file_path, max_size)
129131
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)
131138
await sleep(2)
132139
return True
133140
else:
@@ -157,18 +164,19 @@ async def archive(path, is_split, remove: bool):
157164
else:
158165
cmd = f'7z a -mx=0 -tzip -p{BOT.Options.zip_pswd} {split} "{Paths.temp_zpath}/{name}.zip" {path}'
159166
proc = subprocess.Popen(cmd, shell=True)
160-
total = sizeUnit(getSize(path))
167+
total_size = getSize(path)
168+
total_in_unit = sizeUnit(total_size)
161169
while proc.poll() is None:
162170
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
164172
)
165173
await status_bar(
166174
Messages.status_head,
167175
speed_string,
168176
percentage,
169177
getTime(eta),
170178
sizeUnit(getSize(Paths.temp_zpath)),
171-
total,
179+
total_in_unit,
172180
"Xr-Zipp 🔒",
173181
)
174182
await sleep(1)
@@ -286,3 +294,55 @@ async def splitArchive(file_path, max_size):
286294
# Get next chunk
287295
chunk = f.read(max_size)
288296
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)

colab_leecher/utility/helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def fileType(file_path: str):
103103
".ts": "video",
104104
".m3u8": "video",
105105
".webm": "video",
106+
".mpg": "video",
107+
".mpeg": "video",
108+
".mpeg4": "video",
106109
".vob": "video",
107110
".m4v": "video",
108111
".mp3": "audio",
@@ -341,7 +344,7 @@ async def send_settings(client, message, msg_id, command: bool):
341344
InlineKeyboardButton(
342345
f"Set {up_mode.capitalize()}", callback_data=up_mode
343346
),
344-
InlineKeyboardButton("Video Convert", callback_data="video"),
347+
InlineKeyboardButton("Video Settings", callback_data="video"),
345348
],
346349
[
347350
InlineKeyboardButton("Caption Font", callback_data="caption"),
@@ -356,6 +359,7 @@ async def send_settings(client, message, msg_id, command: bool):
356359
)
357360
text = "**CURRENT BOT SETTINGS ⚙️ »**"
358361
text += f"\n\n╭⌬ UPLOAD » <i>{BOT.Setting.stream_upload}</i>"
362+
text += f"\n├⌬ SPLIT » <i>{BOT.Setting.split_video}</i>"
359363
text += f"\n├⌬ CONVERT » <i>{BOT.Setting.convert_video}</i>"
360364
text += f"\n├⌬ CAPTION » <i>{BOT.Setting.caption}</i>"
361365
pr = "None" if BOT.Setting.prefix == "" else "Exists"

colab_leecher/utility/variables.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ class BOT:
1212
class Setting:
1313
stream_upload = "Media"
1414
convert_video = "Yes"
15-
convert_quality = "High"
15+
convert_quality = "Low"
1616
caption = "Monospace"
17+
split_video = "Split Videos"
1718
prefix = ""
1819
suffix = ""
1920
thumbnail = False
2021

2122
class Options:
2223
stream_upload = True
2324
convert_video = True
24-
convert_quality = True
25+
convert_quality = False
26+
is_split = True
2527
caption = "code"
2628
video_out = "mp4"
2729
custom_name = ""

0 commit comments

Comments
 (0)