Files

53 lines
2.6 KiB
Python
Raw Permalink Normal View History

2026-10-27 18:48:30 +01:00
from bs4 import BeautifulSoup
import requests
import sys
import re
import os
import time
import getopt
tmpFolder = "/tmp/murrtubeDL/"+str(int(time.time()))+"/"
direkt = False
outPath = ""
try:
opts, args = getopt.getopt(sys.argv[1:],"hu:o:d",["help", "url=", "output=", "direct"])
except getopt.GetoptError:
print('At least --url=<Video URL> has to be specified!')
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
print('MurrtubeDL.py\n-h, --help This Message\n-u, --url= Murrtube Video URL\n-o, --output= Output folder Path (has to has / at end)\n-d, --direct Use ffmpeg to download the files instead of Downloading them Seperately (slower)')
sys.exit()
elif opt in ("-o", "--output"):
outPath = arg
elif opt in ("-u", "--url"):
murrl = arg
elif opt in ("-d", "--direct"):
direkt = True
#murrl = str(sys.argv[1]) # Get URL that was passed as argument
mainRip = requests.get(murrl) # get webpage behind passed URL
Soup = BeautifulSoup(mainRip.text, "html.parser") # Parse the Webpage
metaURL = Soup.find("meta", attrs={'name':'og:image'}) # Get the URL path for the Storage location
title = Soup.find("meta", attrs={'name':'og:title'}) # Get the Video title to name our downloaded mp4 after
storageSector = metaURL.get('content')[:-13] # cut a bit of the storage Path to get the finished URL instead of the thumbmail
indexRip = requests.get(storageSector+"index.m3u8") # Load the index.m3u8 file
fileList = indexRip.text[indexRip.text.find("high"):indexRip.text.find("m3u8")+4] # Find the name of the high-definition m3u8 file
if direkt:
# Download the entire contents of the high-definition m3u8 file and convert to mp4
os.system("ffmpeg -i \""+storageSector+fileList+"\" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 "+str(outPath)+title.get('content').replace(" ", "\ ")+".mp4")
sys.exit()
else:
os.system("mkdir -p "+tmpFolder)
partsRip = requests.get(storageSector+fileList) # Load the high-definition .m3u8 file
open(tmpFolder+"index.m3u8", 'wb').write(partsRip.content)
partsStart = [m.start() for m in re.finditer('high', partsRip.text)]
partsEnd = [m.start() for m in re.finditer('ts', partsRip.text)] # needs another +2 later in the delimiter
for i in range(len(partsStart)):
videoPart = requests.get(storageSector+partsRip.text[partsStart[i]:partsEnd[i]+2])
open(tmpFolder+partsRip.text[partsStart[i]:partsEnd[i]+2], 'wb').write(videoPart.content)
print("("+str(i+1)+"/"+str(len(partsStart))+")")
os.system("ffmpeg -i \""+tmpFolder+"index.m3u8"+"\" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 "+str(outPath)+title.get('content').replace(" ", "\ ")+".mp4")