Skip to content

Commit 3961779

Browse files
committed
feat: 🎸Add MKGMa source extraction for video downloads
Implements a new method to extract MKGMa encoded sources from HTML. This includes decoding, parsing, and fallback regex search for URLs. Enhances the ability to find direct video links, improving download capabilities.
1 parent 93e6d85 commit 3961779

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

‎dl.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,66 @@ def download(URL):
413413
print("[+] Found base64 encoded HLS (m3u8) URL.")
414414
except Exception as e:
415415
print(f"[!] Failed to decode a168c string: {e}")
416+
417+
# Method 7: Look for MKGMa encoded sources
418+
# https://github.com/p4ul17/voe-dl/issues/33#issuecomment-2807006973
419+
if not source_json:
420+
print("[*] Searching for MKGMa sources...")
421+
422+
MKGMa_pattern = r'MKGMa="(.*?)"'
423+
match = re.search(MKGMa_pattern, html_page.text, re.DOTALL)
424+
425+
if match:
426+
raw_MKGMa = match.group(1)
427+
428+
def rot13_decode(s: str) -> str:
429+
result = []
430+
for c in s:
431+
if 'A' <= c <= 'Z':
432+
result.append(chr((ord(c) - ord('A') + 13) % 26 + ord('A')))
433+
elif 'a' <= c <= 'z':
434+
result.append(chr((ord(c) - ord('a') + 13) % 26 + ord('a')))
435+
else:
436+
result.append(c)
437+
return ''.join(result)
438+
439+
def shift_characters(s: str, offset: int) -> str:
440+
return ''.join(chr(ord(c) - offset) for c in s)
441+
442+
try:
443+
step1 = rot13_decode(raw_MKGMa)
444+
step2 = step1.replace('_', '')
445+
step3 = base64.b64decode(step2).decode('utf-8')
446+
step4 = shift_characters(step3, 3)
447+
step5 = step4[::-1]
448+
449+
decoded = base64.b64decode(step5).decode('utf-8')
450+
451+
try:
452+
parsed_json = json.loads(decoded)
453+
454+
if 'direct_access_url' in parsed_json:
455+
source_json = {"mp4": parsed_json['direct_access_url']}
456+
print("[+] Found direct .mp4 URL in JSON.")
457+
elif 'source' in parsed_json:
458+
source_json = {"hls": parsed_json['source']}
459+
print("[+] Found fallback .m3u8 URL in JSON.")
460+
461+
except json.JSONDecodeError:
462+
print("[-] Decoded string is not valid JSON. Attempting fallback regex search...")
463+
464+
mp4_match = re.search(r'(https?://[^\s"]+\.mp4[^\s"]*)', decoded)
465+
m3u8_match = re.search(r'(https?://[^\s"]+\.m3u8[^\s"]*)', decoded)
466+
467+
if mp4_match:
468+
source_json = {"mp4": mp4_match.group(1)}
469+
print("[+] Found base64 encoded MP4 URL.")
470+
elif m3u8_match:
471+
source_json = {"hls": m3u8_match.group(1)}
472+
print("[+] Found base64 encoded HLS (m3u8) URL.")
473+
474+
except Exception as e:
475+
print(f"[-] Error while decoding MKGMa string: {e}")
416476

417477
# If we still don't have sources, try to find any iframe that might contain the video
418478
if not source_json:

0 commit comments

Comments
 (0)