This commit is contained in:
widevinedump
2021-12-25 10:43:24 +05:30
parent 98dd671f16
commit 4297654052
41 changed files with 9534 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
import re
from unidecode import unidecode
def get_release_tag(default_filename, vcodec, video_height, acodec, channels, bitrate, module, tag, isDual):
video_codec = ''
if 'avc' in vcodec:
video_codec = 'x264'
if 'hvc' in vcodec:
video_codec = 'x265'
elif 'dvh' in vcodec:
video_codec = 'HDR'
if isDual==True:
video_codec = video_codec + '.DUAL'
audio_codec = ''
if 'mp4a' in acodec:
audio_codec = 'AAC'
if acodec == 'ac-3':
audio_codec = 'DD'
if acodec == 'ec-3':
audio_codec = 'DDP'
elif acodec == 'ec-3' and bitrate > 700000:
audio_codec = 'Atmos'
audio_channels = ''
if channels == '2':
audio_channels = '2.0'
elif channels == '6':
audio_channels = '5.1'
audio_format = audio_codec + audio_channels
#if isDual==True:
# audio_format = audio_codec + '.DUAL'
default_filename = default_filename.replace('&', '.and.')
default_filename = re.sub(r'[]!"#$%\'()*+,:;<=>?@\\^_`{|}~[-]', '', default_filename)
default_filename = default_filename.replace(' ', '.')
default_filename = re.sub(r'\.{2,}', '.', default_filename)
default_filename = unidecode(default_filename)
output_name = '{}.{}p.{}.WEB-DL.{}.{}-{}'.format(default_filename, video_height, str(module), audio_format, video_codec, tag)
return output_name

View File

@@ -0,0 +1,35 @@
from shutil import which
from os.path import dirname, realpath, join
from os import pathsep, environ
SCRIPT_PATH = dirname(realpath('paramountplus'))
BINARIES_FOLDER = join(SCRIPT_PATH, 'binaries')
MP4DECRYPT_BINARY = 'mp4decrypt'
MEDIAINFO_BINARY = 'mediainfo'
MP4DUMP_BINARY = 'mp4dump'
MKVMERGE_BINARY = 'mkvmerge'
FFMPEG_BINARY = 'ffmpeg'
FFMPEG_BINARY = 'ffmpeg'
ARIA2C_BINARY = 'aria2c'
SUBTITLE_EDIT_BINARY = 'subtitleedit'
# Add binaries folder to PATH as the first item
environ['PATH'] = pathsep.join([BINARIES_FOLDER, environ['PATH']])
MP4DECRYPT = which(MP4DECRYPT_BINARY)
MEDIAINFO = which(MEDIAINFO_BINARY)
MP4DUMP = which(MP4DUMP_BINARY)
MKVMERGE = which(MKVMERGE_BINARY)
FFMPEG = which(FFMPEG_BINARY)
ARIA2C = which(ARIA2C_BINARY)
SUBTITLE_EDIT = which(SUBTITLE_EDIT_BINARY)
class WvDownloaderConfig(object):
def __init__(self, xml, base_url, output_file, track_id, format_id):
self.xml = xml
self.base_url = base_url
self.output_file = output_file
self.track_id = track_id
self.format_id = format_id

View File

@@ -0,0 +1,116 @@
import requests, pathlib
import math, subprocess
import os, sys, shutil
class WvDownloader(object):
def __init__(self, config):
self.xml = config.xml
self.output_file = config.output_file
self.config = config
def download_track(self, aria2c_infile, file_name):
aria2c_opts = [
'aria2c',
'--enable-color=false',
'--allow-overwrite=true',
'--summary-interval=0',
'--download-result=hide',
'--async-dns=false',
'--check-certificate=false',
'--auto-file-renaming=false',
'--file-allocation=none',
'--console-log-level=warn',
'-x16', '-s16', '-j16',
'-i', aria2c_infile]
subprocess.run(aria2c_opts)
source_files = pathlib.Path(temp_folder).rglob(r'./*.mp4')
with open(file_name, mode='wb') as (destination):
for file in source_files:
with open(file, mode='rb') as (source):
shutil.copyfileobj(source, destination)
if os.path.exists(temp_folder):
shutil.rmtree(temp_folder)
os.remove(aria2c_infile)
print('\nDone!')
def process_url_templace(self, template, representation_id, bandwidth, time, number):
if representation_id is not None: result = template.replace('$RepresentationID$', representation_id)
if number is not None:
nstart = result.find('$Number')
if nstart >= 0:
nend = result.find('$', nstart+1)
if nend >= 0:
var = result[nstart+1 : nend]
if 'Number%' in var:
value = var[6:] % (int(number))
else:
value = number
result = result.replace('$'+var+'$', value)
if bandwidth is not None: result = result.replace('$Bandwidth$', bandwidth)
if time is not None: result = result.replace('$Time$', time)
result = result.replace('$$', '$').replace('../', '')
return result
def generate_segments(self):
segment_template = self.get_segment_template()
return self.get_segments(segment_template)
def get_segments(self, segment_template):
urls = []
urls.append(self.config.base_url + segment_template['@initialization'].replace('$RepresentationID$', self.config.format_id))
current_number = 1
for seg in self.force_segmentimeline(segment_template):
if '@t' in seg:
current_time = seg['@t']
for i in range(int(seg.get('@r', 0)) + 1):
urls.append(self.config.base_url + self.process_url_templace(segment_template['@media'],
representation_id=self.config.format_id,
bandwidth=None, time=str(current_time), number=str(current_number)))
current_number += 1
current_time += seg['@d']
return urls
def force_segmentimeline(self, segment_timeline):
if isinstance(segment_timeline['SegmentTimeline']['S'], list):
x16 = segment_timeline['SegmentTimeline']['S']
else:
x16 = [segment_timeline['SegmentTimeline']['S']]
return x16
def force_instance(self, x):
if isinstance(x['Representation'], list):
X = x['Representation']
else:
X = [x['Representation']]
return X
def get_segment_template(self):
x = [item for (i, item) in enumerate(self.xml['MPD']['Period']['AdaptationSet']) if self.config.track_id == item["@id"]][0]
segment_level = [item['SegmentTemplate'] for (i, item) in enumerate(self.force_instance(x)) if self.config.format_id == item["@id"]][0]
return segment_level
def run(self):
urls = self.generate_segments()
print('\n' + self.output_file)
global temp_folder
aria2c_infile = 'aria2c_infile.txt'
if os.path.isfile(aria2c_infile):
os.remove(aria2c_infile)
temp_folder = self.output_file.replace('.mp4', '')
if os.path.exists(temp_folder):
shutil.rmtree(temp_folder)
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)
if len(urls) > 1:
num_segments = int(math.log10(len(urls))) + 1
with open(aria2c_infile, 'a', encoding='utf8') as (file):
for (i, url) in enumerate(urls):
file.write(f'{url}\n')
file.write(f'\tout={temp_folder}.{i:0{num_segments}d}.mp4\n')
file.write(f'\tdir={temp_folder}\n')
file.flush()
self.download_track(aria2c_infile, self.output_file)
print('Done!')

View File

@@ -0,0 +1,15 @@
config = {
'proxies': {
'none': None
},
}
class ProxyConfig(object):
def __init__(self, proxies):
self.config = config
self.config['proxies'] = proxies
def get_proxy(self, proxy):
return self.config['proxies'].get(proxy)