-
Notifications
You must be signed in to change notification settings - Fork 11
/
mpdl.py
1287 lines (1117 loc) · 54 KB
/
mpdl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import base64
import datetime
import config
import util
import initext
import os.path
import sys
import re
import shutil
from subprocess import Popen, PIPE
import ffmpeg
import uuid
import requests
import yt_dlp
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import Qt, pyqtSignal, QObject, QRunnable, pyqtSlot, QThreadPool, QSize
from PyQt5.QtGui import QFont, QPixmap
from PyQt5.QtWidgets import QAbstractItemView, QMessageBox, QFileDialog, QProgressBar, QLabel, QSizePolicy
from seleniumwire import webdriver
from sys import platform
from pathlib import Path
# Config
# Selenium Version 3.4.1
VERSION = "3.1.1"
app = QtWidgets.QApplication(sys.argv)
driverType = None
headermap = {}
def getHeaders(url):
try:
return headermap[url]
except Exception:
return None
def writeHeaders(headers, url):
with open("headers.py", 'w') as file:
file.write("import requests\n")
file.write("headers = {\n")
file.write(headers if headers is not None else "")
file.write("\n}\n")
file.write(f"response = requests.post('{url}', headers=headers)\n")
def getKeys(pssh, lic_url):
import headers
from data.pywidevine.L3.cdm import deviceconfig
from data.pywidevine.L3.decrypt.wvdecryptcustom import WvDecrypt
try:
wvdecrypt = WvDecrypt(init_data_b64=pssh, cert_data_b64=None, device=deviceconfig.device_android_generic)
challenge = wvdecrypt.get_challenge()
if challenge is None:
return None
widevine_license = requests.post(url=lic_url, data=challenge, headers=headers.headers)
license_b64 = base64.b64encode(widevine_license.content)
if not wvdecrypt.update_license(license_b64):
return None
return wvdecrypt.start_process()
except Exception:
return None
def checkcdm(self) -> bool:
path = "data/pywidevine/L3/cdm/devices/android_generic/"
if not os.path.exists(path + "device_client_id_blob") or not os.path.exists(path + "device_private_key"):
errorDialog(self, 'No Content Decryption Module found.\n'
'Please select the following\n'
'files in the Settings Menu:\n'
'device_client_id_blob, device_private_key')
return False
else:
return True
def errorDialog(self, desc):
QMessageBox.critical(
self,
"MPDL/Error",
desc,
buttons=QMessageBox.Ok,
defaultButton=QMessageBox.Ok,
)
def getMp4Decrypt() -> str:
c = config.parser
mp4decrypt = "mp4decrypt"
if not c.getboolean("MAIN", "mp4decryptfrompath"):
mp4decrypt = c.get("MAIN", "mp4decryptpath")
return mp4decrypt
class Signals(QObject):
started = pyqtSignal(list)
completed = pyqtSignal(str)
progress = pyqtSignal(list)
error = pyqtSignal(str)
class BrowserSignals(QObject):
started = pyqtSignal()
ended = pyqtSignal()
links = pyqtSignal(list)
error = pyqtSignal(str)
class Worker(QRunnable):
def __init__(self, source, pssh, lic, wid):
super().__init__()
print(f"Worker(\n{source}, \n{pssh}, \n{lic}, \n{wid})")
self.keys = None
self.d = False
if isinstance(source, list):
self.d = True
self.src = source
self.source = (source[0] if source[0] is not None else "No Video") + ", " + (source[1] if source[1] is not None else "No Audio")
else:
self.source = source
self.src = [None, None]
self.pssh = pssh
self.lic = lic
self.uuid = wid
self.videosize = ''
self.audiosize = ''
self.signals = Signals()
self.typ = 'video'
@pyqtSlot()
def run(self):
def log(d):
status = None
if 'status' in d:
statusT = d['status']
if statusT is not None:
status = statusT
name = None
if 'filename' in d:
nameT = d['filename']
if nameT is not None:
name = nameT
perc = '0'
if 'total_bytes_estimate' in d and 'downloaded_bytes' in d:
tbeT, tbT = d['total_bytes_estimate'], d['downloaded_bytes']
if tbeT is not None and tbT is not None:
perc = str(tbT / tbeT * 100)
size = '0'
if 'total_bytes_estimate' in d:
tbeT = d['total_bytes_estimate']
if tbeT is not None:
size = str(int(tbeT / 1000000))
eta = 'N/A'
if 'eta' in d:
etaT = d['eta']
if etaT is not None:
m, s = divmod(etaT, 60)
h, m = divmod(m, 60)
eta = ('{}h {}m {}s'.format(int(h), int(m), int(s)))
speed = '0.0'
if 'speed' in d:
sT = d['speed']
if sT is not None:
speed = str(int(sT / 1000))
if perc == '0' and status == 'finished':
to = f"{self.uuid}.{self.typ}.{name.split('.')[len(name.split('.')) - 1]}"
try:
os.replace(name, to)
except Exception as ex:
self.signals.error.emit(str(ex))
# TODO: improve this
if self.typ == 'video':
self.src[0] = to
self.videosize = size
elif self.typ == 'audio':
self.src[1] = to
self.audiosize = size
self.typ = 'audio'
self.signals.progress.emit(
[self.uuid, f"{status.capitalize()} ({self.typ.capitalize()})", f"{size} MB", perc, eta, f"{speed} KB/s", self.source])
try:
self.signals.started.emit([self.uuid, self.source])
# get keys
self.signals.progress.emit(
[self.uuid, f"Obtaining Keys", '', '0', '', '', self.source])
writeHeaders(getHeaders(self.lic), self.lic)
self.keys = getKeys(self.pssh, self.lic)
if self.keys is None:
self.signals.error.emit("Unable to obtain decryption keys.")
return
print(f"Keys => {self.keys}")
self.signals.progress.emit([self.uuid, f"Obtaining Keys", '', '100', '', '', self.source])
# download data
if not self.d:
ydl_opts = {
'allow_unplayable_formats': True,
'noprogress': True,
'quiet': True,
'fixup': 'never',
'format': 'bv,ba',
'no_warnings': True,
'outtmpl': {'default': self.uuid + '.f%(format_id)s.%(ext)s'},
'progress_hooks': [log]
}
yt_dlp.YoutubeDL(ydl_opts).download(self.source)
else:
self.videosize = 0 if self.src[0] is None else int(int(os.path.getsize(self.src[0]))/1_000_000)
self.audiosize = 0 if self.src[1] is None else int(int(os.path.getsize(self.src[1]))/1_000_000)
# TODO: improve this
# decrypt
for i in range(2):
s = self.src[i]
if s is None:
continue
size = self.videosize if i == 0 else self.audiosize
typ = 'video' if i == 0 else 'audio'
out = self.uuid + "." + typ + "_decrypted." + s.split(".")[len(s.split(".")) - 1]
self.signals.progress.emit([self.uuid, f"Decrypting ({typ.capitalize()})", str(size) + " MB", '0', '', '', self.source])
command = getMp4Decrypt() + " --key " + " --key ".join(self.keys) + ' ' + s + ' ' + out
process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
self.signals.progress.emit(
[self.uuid, f"Decrypting ({typ.capitalize()})", str(size) + " MB", '100', '', '', self.source])
if stderr.decode('utf-8'):
self.signals.error.emit("Failed decrypting " + s + ": " + stderr.decode('utf-8'))
return
self.src[i] = out
if os.path.exists(s) and not self.d:
os.remove(s)
# combine
totalsize = str(int(float(self.videosize) + float(self.audiosize)))
self.signals.progress.emit([self.uuid, f"Combining", totalsize + " MB", '0', '', '', self.source])
t = datetime.datetime.now()
out = (self.uuid + '.{}-{}-{}_{}-{}-{}'.format(t.day, t.month, t.year, t.hour, t.minute, t.second) + '.mkv')
if len(self.src) == 2:
v = ffmpeg.input(self.src[0])
a = ffmpeg.input(self.src[1])
c = config.parser
if c.getboolean("MAIN", "ffmpegfrompath"):
ffmpeg.output(v, a, out, vcodec='copy', acodec='copy').run(quiet=True, overwrite_output=True,
cmd=c.get("MAIN", "ffmpegpath"))
else:
ffmpeg.output(v, a, out, vcodec='copy', acodec='copy').run(quiet=True, overwrite_output=True)
if os.path.exists(self.src[0]):
os.remove(self.src[0])
if os.path.exists(self.src[1]):
os.remove(self.src[1])
self.signals.progress.emit([self.uuid, f"Combining", totalsize + " MB", '100', '', '', self.source])
# time.sleep(1)
self.signals.progress.emit([self.uuid, f"Finished", totalsize + " MB", '100', '', '', self.source])
if config.parser.getboolean("MAIN", "downloadfrompath"):
try:
shutil.move(out, config.parser.get("MAIN", "downloadpath"))
except Exception as ex:
errorDialog("Unable to save file: " + str(ex))
self.signals.completed.emit(self.uuid)
except Exception as ex:
self.signals.error.emit(str(ex))
def close(self):
self.setWindowTitle("MPDL/Main - Closing ...")
self.hide()
self.sniffer.hide()
self.downloads.hide()
app.closeAllWindows()
try:
if driverType is not None:
driverType.quit()
except Exception:
pass
sys.exit(0)
class Browser(QRunnable):
def __init__(self, main):
super().__init__()
self.main = main
self.signals = BrowserSignals()
@pyqtSlot()
def run(self):
options = webdriver.FirefoxOptions()
if config.parser.getboolean("BROWSER", "drmenabled"):
profile = webdriver.FirefoxProfile('data/firefox')
else:
profile = webdriver.FirefoxProfile()
options.profile = profile
driver = webdriver.Firefox(options=options)
for addon in util.getAddons(config.parser):
try:
driver.install_addon(addon, temporary=True)
except Exception as ex:
self.signals.error.emit(f"Unable to install addon:\n{addon}\nCheck the Addons section in Settings for "
f"incorrect paths.\n\n{str(ex)}")
driver.close()
self.signals.ended.emit()
return
driver.get(config.parser.get("BROWSER", "startpage"))
global driverType
driverType = driver
logs = []
curr = ''
self.signals.started.emit()
while True:
try:
driver.window_handles
except Exception:
self.signals.ended.emit()
break
try:
if curr != driver.current_url:
logs = []
curr = driver.current_url
log = driver.requests
for x in log:
if x.url not in logs:
logs.append(x.url)
headermap[str(x.url)] = util.formatCURL(str(x.headers))
if x.url.startswith('http') and len(re.findall("mpd|manifest|ism", x.url)) >= 1:
self.signals.links.emit([0, x.url])
# elif x.url.startswith('http') and len(re.findall("license|widevine|cenc|pssh|bitmovin", x.url)) >= 1:
elif x.method == 'POST':
self.signals.links.emit([1, x.url])
except Exception:
pass
class Advanced(QtWidgets.QWidget):
def choose(self, text, lineEdit):
dialog = QFileDialog(self)
dialog.setWindowTitle(text)
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setViewMode(QFileDialog.Detail)
dialog.setDirectory(str(Path.home()).replace("\\", "/"))
if dialog.exec_():
selected = dialog.selectedFiles()
if len(selected) == 1:
lineEdit.setText(selected[0].replace("\\", "/"))
else:
errorDialog(self, "Only one file can be selected.")
# TODO: i don't know any other way to do this
def choose1(self):
self.choose("Choose Local Encrypted Video File", self.lineEdit)
def choose2(self):
self.choose("Choose Local Encrypted Audio File", self.lineEdit_2)
def choose3(self):
self.choose("Choose Local MPD File", self.lineEdit_3)
def choose4(self):
self.choose("Choose Local MPD File", self.lineEdit_4)
def choose5(self):
self.choose("Choose Local init.mp4 File", self.lineEdit_5)
def __init__(self, main):
super().__init__()
self.main = main
self.setWindowTitle("MPDL/Advanced Mode")
self.resize(346, 420)
self.setFixedSize(346, 420)
self.setWindowIcon(util.getIcon())
self.label = QtWidgets.QLabel("Advanced Mode", self)
self.label.setGeometry(QtCore.QRect(87, 0, 171, 31))
self.label.setFont(util.getFont(17, False, True))
self.groupBox = QtWidgets.QGroupBox(" Content Source ", self)
self.groupBox.setGeometry(QtCore.QRect(10, 33, 326, 161))
self.groupBox_2 = QtWidgets.QGroupBox(" ", self.groupBox)
self.groupBox_2.setGeometry(QtCore.QRect(10, 76, 306, 75))
self.radioButton = QtWidgets.QRadioButton("Local Encrypted Video/Audio Files", self.groupBox_2)
self.radioButton.setGeometry(QtCore.QRect(13, -14, 191, 41))
self.radioButton.clicked.connect(self.radioButtonChecked)
self.lineEdit = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit.setGeometry(QtCore.QRect(10, 21, 261, 20))
self.lineEdit.setPlaceholderText("Encrypted Video File")
self.lineEdit.setEnabled(False)
self.lineEdit_2 = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit_2.setGeometry(QtCore.QRect(10, 45, 261, 20))
self.lineEdit_2.setPlaceholderText("Encrypted Audio File")
self.lineEdit_2.setEnabled(False)
self.toolButton = QtWidgets.QPushButton("...", self.groupBox_2)
self.toolButton.setGeometry(QtCore.QRect(273, 21, 25, 20))
self.toolButton.setEnabled(False)
self.toolButton.clicked.connect(self.choose1)
self.toolButton_2 = QtWidgets.QPushButton("...", self.groupBox_2)
self.toolButton_2.setGeometry(QtCore.QRect(273, 45, 25, 20))
self.toolButton_2.setEnabled(False)
self.toolButton_2.clicked.connect(self.choose2)
self.groupBox_3 = QtWidgets.QGroupBox(" ", self.groupBox)
self.groupBox_3.setGeometry(QtCore.QRect(10, 20, 306, 51))
self.lineEdit_3 = QtWidgets.QLineEdit(self.groupBox_3)
self.lineEdit_3.setGeometry(QtCore.QRect(10, 21, 261, 20))
self.lineEdit_3.setPlaceholderText("URL / Local File")
self.toolButton_3 = QtWidgets.QPushButton("...", self.groupBox_3)
self.toolButton_3.setGeometry(QtCore.QRect(273, 21, 25, 20))
self.toolButton_3.clicked.connect(self.choose3)
self.radioButton_2 = QtWidgets.QRadioButton("MPD", self.groupBox_3)
self.radioButton_2.setGeometry(QtCore.QRect(13, -2, 82, 17))
self.radioButton_2.setChecked(True)
self.radioButton_2.clicked.connect(self.radioButtonChecked2)
self.groupBox_4 = QtWidgets.QGroupBox(" PSSH Source ", self)
self.groupBox_4.setGeometry(QtCore.QRect(10, 200, 326, 101))
self.radioButton_3 = QtWidgets.QRadioButton(self.groupBox_4)
self.radioButton_3.setGeometry(QtCore.QRect(10, 22, 82, 17))
self.radioButton_3.setText("")
self.radioButton_3.setChecked(True)
self.radioButton_3.clicked.connect(self.radioButtonChecked3)
self.radioButton_4 = QtWidgets.QRadioButton(self.groupBox_4)
self.radioButton_4.setGeometry(QtCore.QRect(10, 46, 82, 17))
self.radioButton_4.setText("")
self.radioButton_4.clicked.connect(self.radioButtonChecked4)
self.radioButton_5 = QtWidgets.QRadioButton(self.groupBox_4)
self.radioButton_5.setGeometry(QtCore.QRect(10, 70, 82, 17))
self.radioButton_5.setText("")
self.radioButton_5.clicked.connect(self.radioButtonChecked5)
self.lineEdit_4 = QtWidgets.QLineEdit(self.groupBox_4)
self.lineEdit_4.setGeometry(QtCore.QRect(30, 20, 258, 20))
self.lineEdit_4.setPlaceholderText(".mpd URL / Local File")
self.lineEdit_5 = QtWidgets.QLineEdit(self.groupBox_4)
self.lineEdit_5.setGeometry(QtCore.QRect(30, 44, 258, 20))
self.lineEdit_5.setPlaceholderText("init.mp4 URL / Local File")
self.lineEdit_5.setEnabled(False)
self.lineEdit_6 = QtWidgets.QLineEdit(self.groupBox_4)
self.lineEdit_6.setGeometry(QtCore.QRect(30, 68, 285, 20))
self.lineEdit_6.setPlaceholderText("PSSH")
self.lineEdit_6.setEnabled(False)
self.toolButton_4 = QtWidgets.QPushButton("...", self.groupBox_4)
self.toolButton_4.setGeometry(QtCore.QRect(291, 20, 25, 20))
self.toolButton_4.clicked.connect(self.choose4)
self.toolButton_5 = QtWidgets.QPushButton("...", self.groupBox_4)
self.toolButton_5.setGeometry(QtCore.QRect(291, 44, 25, 20))
self.toolButton_5.setEnabled(False)
self.toolButton_5.clicked.connect(self.choose5)
self.groupBox_5 = QtWidgets.QGroupBox(" License Server ", self)
self.groupBox_5.setGeometry(QtCore.QRect(10, 310, 326, 51))
self.lineEdit_7 = QtWidgets.QLineEdit(self.groupBox_5)
self.lineEdit_7.setGeometry(QtCore.QRect(10, 20, 301, 20))
self.lineEdit_7.setPlaceholderText("License URL")
self.pushButton = QtWidgets.QPushButton("Download", self)
self.pushButton.setGeometry(QtCore.QRect(10, 390, 231, 23))
self.pushButton.clicked.connect(self.download)
self.checkBox = QtWidgets.QCheckBox("Clear Fields", self)
self.checkBox.setGeometry(QtCore.QRect(260, 393, 81, 17))
self.label_2 = QtWidgets.QLabel("Use the internal browser if you wish to use auto header copy.", self)
self.label_2.setGeometry(QtCore.QRect(12, 363, 321, 16))
def download(self):
from headers import headers
# Checks
if self.radioButton_2.isChecked() and not self.lineEdit_3.text():
errorDialog(self, "Please fill out the MPD field.")
return
if self.radioButton.isChecked() and not self.lineEdit.text() and not self.lineEdit_2.text():
errorDialog(self, "Please fill out at least one local file field.")
return
if self.radioButton_3.isChecked() and not self.lineEdit_4.text():
errorDialog(self, "Please fill out the mpd field.")
return
if self.radioButton_4.isChecked() and not self.lineEdit_5.text():
errorDialog(self, "Please fill out the init.mp4 field.")
return
if self.radioButton_5.isChecked() and not self.lineEdit_6.text():
errorDialog(self, "Please fill out the PSSH field.")
return
if not self.lineEdit_7.text():
errorDialog(self, "Please fill out the license url field.")
return
source = None
pssh = None
lic = self.lineEdit_7.text()
wid = str(uuid.uuid4())
if self.radioButton_2.isChecked():
source = self.lineEdit_3.text()
elif self.radioButton.isChecked():
source = [self.lineEdit.text() if self.lineEdit.text() else None,
self.lineEdit_2.text() if self.lineEdit_2.text() else None]
if self.radioButton_3.isChecked():
# mpd url/file
if not self.lineEdit_4.text().startswith("http"):
# local
if not os.path.exists(self.lineEdit_4.text()):
errorDialog(self, "MPD file does not exist.")
return
pssh = util.getPSSH(self.lineEdit_4.text())
if pssh is None:
errorDialog(self, "No PSSH found in MPD.")
return
else:
# url
writeHeaders(getHeaders(lic), lic)
try:
response = requests.get(url=self.lineEdit_4.text(), headers=headers)
except Exception as ex:
errorDialog(self, f"Unable to download mpd file:\n{ex}")
return
if not response.ok:
errorDialog(self, f"Network error occurred ({response.status_code}) while downloading mpd")
return
mpd = f"{wid}.mpd"
with open(mpd, mode="wb") as file:
file.write(response.content)
pssh = util.getPSSH(mpd)
if pssh is None:
errorDialog(self, "No PSSH found in MPD.")
return
os.remove(mpd)
elif self.radioButton_4.isChecked():
if not self.lineEdit_5.text().startswith("http"):
# local
if not os.path.exists(self.lineEdit_5.text()):
errorDialog(self, "init.mp4 file does not exist.")
return
rs = initext.ext(self.lineEdit_5.text().replace('"', ''))
if len(rs) == 0:
errorDialog(self, "No valid pssh found in init.mp4 file.")
return
pssh = min(rs, key=len)
else:
# url
writeHeaders(getHeaders(lic), lic)
try:
response = requests.get(url=self.lineEdit_5.text(), headers=headers.headers)
except Exception as ex:
errorDialog(self, f"Unable to download init.mp4 file:\n{ex}")
return
if not response.ok:
errorDialog(self, f"Network error occurred ({response.status_code}) while downloading init.mp4")
return
init = f"{wid}-init.mp4"
with open(init, mode="wb") as file:
file.write(response.content)
rs = initext.ext(init)
if len(rs) == 0:
errorDialog(self, "No valid pssh found in init.mp4 file.")
return
pssh = min(rs, key=len)
os.remove(init)
elif self.radioButton_5.isChecked():
pssh = self.lineEdit_6.text()
if pssh is None:
errorDialog(self, "No PSSH found.")
return
if source is None:
errorDialog(self, "No source available.")
return
pool = QThreadPool.globalInstance()
worker = Worker(source, pssh, lic, wid)
worker.signals.completed.connect(self.main.complete)
worker.signals.started.connect(self.main.start)
worker.signals.progress.connect(self.main.progress)
worker.signals.error.connect(self.main.error)
pool.start(worker)
if self.checkBox.isChecked():
self.lineEdit.clear()
self.lineEdit_2.clear()
self.lineEdit_3.clear()
self.lineEdit_4.clear()
self.lineEdit_5.clear()
self.lineEdit_6.clear()
self.lineEdit_7.clear()
def radioButtonChecked3(self):
self.lineEdit_4.setEnabled(True)
self.toolButton_4.setEnabled(True)
self.lineEdit_5.setEnabled(False)
self.toolButton_5.setEnabled(False)
self.lineEdit_6.setEnabled(False)
def radioButtonChecked4(self):
self.lineEdit_4.setEnabled(False)
self.toolButton_4.setEnabled(False)
self.lineEdit_5.setEnabled(True)
self.toolButton_5.setEnabled(True)
self.lineEdit_6.setEnabled(False)
def radioButtonChecked5(self):
self.lineEdit_4.setEnabled(False)
self.toolButton_4.setEnabled(False)
self.lineEdit_5.setEnabled(False)
self.toolButton_5.setEnabled(False)
self.lineEdit_6.setEnabled(True)
def radioButtonChecked(self): # local
if self.radioButton.isChecked():
self.radioButton_2.setChecked(False)
self.lineEdit.setEnabled(True)
self.lineEdit_2.setEnabled(True)
self.toolButton.setEnabled(True)
self.toolButton_2.setEnabled(True)
self.lineEdit_3.setEnabled(False)
self.toolButton_3.setEnabled(False)
else:
self.radioButton.setChecked(True)
def radioButtonChecked2(self): # mpd
if self.radioButton_2.isChecked():
self.radioButton.setChecked(False)
self.lineEdit_3.setEnabled(True)
self.toolButton_3.setEnabled(True)
self.lineEdit.setEnabled(False)
self.lineEdit_2.setEnabled(False)
self.toolButton.setEnabled(False)
self.toolButton_2.setEnabled(False)
else:
self.radioButton_2.setChecked(True)
def closeEvent(self, event):
self.main.pushButton_6.setEnabled(True)
class About(QtWidgets.QWidget):
def __init__(self, main):
super().__init__()
self.main = main
self.setWindowTitle("MPDL/About")
self.resize(380, 120)
self.setFixedSize(380, 120)
self.setWindowIcon(util.getIcon())
self.image = QLabel(self)
self.image.setPixmap(QPixmap("icon.png"))
self.image.setGeometry(10, 10, 100, 100)
self.image.setScaledContents(True)
self.image.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
self.image.show()
self.label = QLabel("MPDL", self)
self.label.setGeometry(QtCore.QRect(127, 10, 150, 40))
self.label.setFont(util.getFont(36, True, True))
self.version = QLabel("v" + VERSION, self)
self.version.setGeometry(QtCore.QRect(130, 39, 150, 40))
self.description = QLabel("MPD Downloader for DRM Protected content.\ngithub.com/DevLARLEY/mpdl", self)
self.description.setGeometry(QtCore.QRect(130, 40, 370, 100))
def closeEvent(self, event):
self.main.pushButton_5.setEnabled(True)
class Settings(QtWidgets.QWidget):
def __init__(self, main):
super().__init__()
self.main = main
self.setWindowTitle("MPDL/Settings")
self.resize(440, 323)
self.setFixedSize(440, 323)
self.setWindowIcon(util.getIcon())
self.label = QtWidgets.QLabel("Settings", self)
self.label.setGeometry(QtCore.QRect(20, 10, 151, 31))
self.label.setFont(util.getFont(17, False, True))
self.okbutton = QtWidgets.QPushButton("Apply", self)
self.okbutton.setGeometry(QtCore.QRect(355, 14, 75, 31))
self.okbutton.clicked.connect(self.okbuttonclicked)
self.listWidget = QtWidgets.QListWidget(self)
self.listWidget.setGeometry(QtCore.QRect(10, 54, 80, 260))
item = QtWidgets.QListWidgetItem("Main")
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.listWidget.addItem(item)
item = QtWidgets.QListWidgetItem("Browser")
self.listWidget.addItem(item)
self.listWidget.itemSelectionChanged.connect(self.itemselection)
# Main
self.groupBox_3 = QtWidgets.QGroupBox("External Programs", self)
self.groupBox_3.setGeometry(QtCore.QRect(100, 135, 330, 180))
self.groupBox = QtWidgets.QGroupBox("ffmpeg", self.groupBox_3)
self.groupBox.setGeometry(QtCore.QRect(10, 20, 310, 71))
self.radioButton = QtWidgets.QRadioButton("From PATH", self.groupBox)
self.radioButton.setGeometry(QtCore.QRect(10, 20, 82, 17))
self.radioButton.setChecked(True)
self.radioButton_2 = QtWidgets.QRadioButton("", self.groupBox)
self.radioButton_2.setGeometry(QtCore.QRect(10, 42, 82, 17))
self.textEdit = QtWidgets.QLineEdit(self.groupBox)
self.textEdit.setGeometry(QtCore.QRect(30, 40, 221, 21))
self.toolButton = QtWidgets.QToolButton(self.groupBox)
self.toolButton.setGeometry(QtCore.QRect(254, 42, 25, 19))
self.toolButton.setText("...")
self.toolButton.clicked.connect(self.chooseffmpeg)
self.groupBox_2 = QtWidgets.QGroupBox("mp4decrypt", self.groupBox_3)
self.groupBox_2.setGeometry(QtCore.QRect(10, 100, 310, 71))
self.radioButton_3 = QtWidgets.QRadioButton("From PATH", self.groupBox_2)
self.radioButton_3.setGeometry(QtCore.QRect(10, 20, 82, 17))
self.radioButton_3.setChecked(True)
self.radioButton_4 = QtWidgets.QRadioButton("", self.groupBox_2)
self.radioButton_4.setGeometry(QtCore.QRect(10, 42, 82, 17))
self.textEdit_2 = QtWidgets.QLineEdit(self.groupBox_2)
self.textEdit_2.setGeometry(QtCore.QRect(30, 40, 221, 21))
self.toolButton_2 = QtWidgets.QToolButton(self.groupBox_2)
self.toolButton_2.setGeometry(QtCore.QRect(254, 42, 25, 19))
self.toolButton_2.setText("...")
self.toolButton_2.clicked.connect(self.choosemp4decrypt)
self.groupBox_4 = QtWidgets.QGroupBox("General", self)
self.groupBox_4.setGeometry(QtCore.QRect(100, 50, 330, 78))
self.groupBox_7 = QtWidgets.QGroupBox(" " * 39, self.groupBox_4)
self.groupBox_7.setGeometry(QtCore.QRect(10, 20, 200, 50))
self.groupBox_8 = QtWidgets.QGroupBox("CDM", self.groupBox_4)
self.groupBox_8.setGeometry(QtCore.QRect(220, 20, 100, 50))
self.downloadpathenabled = QtWidgets.QCheckBox("Download Directory", self.groupBox_7)
self.downloadpathenabled.setGeometry(QtCore.QRect(12, -3, 200, 20))
self.downloadpathenabled.clicked.connect(self.enableDownloadDirectory)
self.downloadpath = QtWidgets.QLineEdit(self.groupBox_7)
self.downloadpath.setGeometry(QtCore.QRect(10, 20, 150, 21))
self.toolButton_4 = QtWidgets.QToolButton(self.groupBox_7)
self.toolButton_4.setGeometry(QtCore.QRect(165, 22, 25, 19))
self.toolButton_4.setText("...")
self.toolButton_4.clicked.connect(self.chooseOutputDirectory)
self.toolButton_3 = QtWidgets.QPushButton(self.groupBox_8)
self.toolButton_3.setGeometry(QtCore.QRect(10, 18, 80, 23))
self.toolButton_3.setText("Select")
self.toolButton_3.clicked.connect(self.choosecdm)
# Browser
self.groupBox_5 = QtWidgets.QGroupBox("General", self)
self.groupBox_5.setGeometry(QtCore.QRect(100, 50, 330, 265))
self.label_3 = QtWidgets.QLabel("Start Page (Full Link):", self.groupBox_5)
self.label_3.setGeometry(QtCore.QRect(17, 20, 120, 16))
self.textEdit_3 = QtWidgets.QLineEdit(self.groupBox_5)
self.textEdit_3.setGeometry(QtCore.QRect(12, 40, 301, 20))
self.textEdit_3.setText("https://duckduckgo.com/")
self.groupBox_6 = QtWidgets.QGroupBox("Addons", self.groupBox_5)
self.groupBox_6.setGeometry(QtCore.QRect(10, 100, 311, 156))
self.listWidget_2 = QtWidgets.QListWidget(self.groupBox_6)
self.listWidget_2.setGeometry(QtCore.QRect(10, 50, 291, 97))
self.pushButton = QtWidgets.QPushButton("+", self.groupBox_6)
self.pushButton.setGeometry(QtCore.QRect(10, 20, 23, 23))
self.pushButton.clicked.connect(self.addAddon)
self.pushButton_2 = QtWidgets.QPushButton("-", self.groupBox_6)
self.pushButton_2.setGeometry(QtCore.QRect(40, 20, 23, 23))
self.pushButton_2.clicked.connect(self.removeAddon)
self.checkBox_2 = QtWidgets.QCheckBox("Enable DRM", self.groupBox_5)
self.checkBox_2.setGeometry(QtCore.QRect(16, 70, 81, 17))
self.checkBox_2.setChecked(True)
c = config.parser
# Main
self.downloadpath.setText(c.get("MAIN", "downloadpath"))
self.downloadpath.setEnabled(c.getboolean("MAIN", "downloadfrompath"))
self.toolButton_4.setEnabled(c.getboolean("MAIN", "downloadfrompath"))
self.downloadpathenabled.setChecked(c.getboolean("MAIN", "downloadfrompath"))
self.radioButton.setChecked(c.getboolean("MAIN", "ffmpegfrompath"))
self.radioButton_2.setChecked(not c.getboolean("MAIN", "ffmpegfrompath"))
self.textEdit.setText(c.get("MAIN", "ffmpegpath"))
self.radioButton_3.setChecked(c.getboolean("MAIN", "mp4decryptfrompath"))
self.radioButton_4.setChecked(not c.getboolean("MAIN", "mp4decryptfrompath"))
self.textEdit_2.setText(c.get("MAIN", "mp4decryptpath"))
if c.getboolean("MAIN", "cdmselected"):
self.toolButton_3.setText("Change")
else:
self.toolButton_3.setText("Select")
# Browser
self.textEdit_3.setText(c.get("BROWSER", "startpage"))
self.checkBox_2.setChecked(c.getboolean("BROWSER", "drmenabled"))
self.listWidget_2.addItems(util.getAddons(c))
def enableDownloadDirectory(self):
self.downloadpath.setEnabled(self.downloadpathenabled.isChecked())
self.toolButton_4.setEnabled(self.downloadpathenabled.isChecked())
def removeAddon(self):
self.listWidget_2.takeItem(self.listWidget_2.currentRow())
def addAddon(self):
dialog = QFileDialog(self)
dialog.setWindowTitle("Add Addon(s):")
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setViewMode(QFileDialog.Detail)
dialog.setDirectory(str(Path.home()).replace("\\", "/"))
if dialog.exec_():
selected = dialog.selectedFiles()
if len(selected) > 0:
self.listWidget_2.addItems(selected)
else:
errorDialog(self, "At least one file must be selected.")
def chooseOutputDirectory(self):
dialog = QFileDialog(self)
dialog.setWindowTitle("Select output directory:")
dialog.setFileMode(QFileDialog.FileMode.DirectoryOnly)
dialog.setViewMode(QFileDialog.Detail)
dialog.setDirectory(str(Path.home()).replace("\\", "/"))
if dialog.exec_():
selected = dialog.selectedFiles()
if len(selected) == 1:
self.downloadpath.setText(selected[0].replace("\\", "/"))
else:
errorDialog(self, "Only one directory can be selected.")
def chooseffmpeg(self):
dialog = QFileDialog(self)
dialog.setWindowTitle("Select ffmpeg:")
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setViewMode(QFileDialog.Detail)
dialog.setDirectory(str(Path.home()).replace("\\", "/"))
if dialog.exec_():
selected = dialog.selectedFiles()
if len(selected) == 1:
self.textEdit.setText(selected[0].replace("\\", "/"))
self.radioButton.setChecked(False)
self.radioButton_2.setChecked(True)
else:
errorDialog(self, "Only one file can be selected.")
def choosemp4decrypt(self):
dialog = QFileDialog(self)
dialog.setWindowTitle("Select mp4decrypt:")
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setViewMode(QFileDialog.Detail)
dialog.setDirectory(str(Path.home()).replace("\\", "/"))
if dialog.exec_():
selected = dialog.selectedFiles()
if len(selected) == 1:
self.textEdit_2.setText(selected[0].replace("\\", "/"))
self.radioButton_3.setChecked(False)
self.radioButton_4.setChecked(True)
else:
errorDialog(self, "Only one file can be selected.")
def choosecdm(self):
path = "data/pywidevine/L3/cdm/devices/android_generic/"
dialog = QFileDialog(self)
dialog.setWindowTitle("Select Content Decryption Module:")
dialog.setFileMode(QFileDialog.FileMode.ExistingFiles)
dialog.setViewMode(QFileDialog.Detail)
dialog.setDirectory(str(Path.home()).replace("\\", "/"))
if dialog.exec_():
selected = dialog.selectedFiles()
if len(selected) == 2:
if any("device_client_id_blob" in item for item in selected) and any(
"device_private_key" in item for item in selected):
shutil.copy(selected[0], path)
shutil.copy(selected[1], path)
self.toolButton_3.setText("Change")
else:
errorDialog(self, "Invalid file names.")
else:
errorDialog(self, "Please select two files.")
def okbuttonclicked(self):
c = config.parser
if not os.path.isfile(self.textEdit.text()) and self.radioButton_2.isChecked():
errorDialog(self, "ffmpeg path is invalid.")
return
if not os.path.isfile(self.textEdit_2.text()) and self.radioButton_4.isChecked():
errorDialog(self, "mp4decrypt path is invalid.")
return
if not self.textEdit_3.text().startswith("http"):
errorDialog(self, "A full link starting with 'http' must be provided.")
return
c["MAIN"]["downloadpath"] = self.downloadpath.text()
c["MAIN"]["downloadfrompath"] = str(self.downloadpathenabled.isChecked())
c["MAIN"]["ffmpegfrompath"] = str(self.radioButton.isChecked())
c["MAIN"]["ffmpegpath"] = self.textEdit.text()
c["MAIN"]["mp4decryptfrompath"] = str(self.radioButton_3.isChecked())
c["MAIN"]["mp4decryptpath"] = self.textEdit_2.text()
c["MAIN"]["cdmselected"] = str(self.toolButton_3.text() == "Change")
c["BROWSER"]["startpage"] = self.textEdit_3.text()
c["BROWSER"]["drmenabled"] = str(self.checkBox_2.isChecked())
c["BROWSER"]["addons"] = util.setAddons(self.listWidget_2)
config.writeConfig()
QMessageBox.information(self, "MPDL/Settings", "Settings saved successfully.")
self.hide()
self.main.pushButton_4.setEnabled(True)
def itemselection(self):
i = self.listWidget.selectedIndexes()[0].row()
if i == 0:
self.groupBox.show()
self.groupBox_2.show()
self.groupBox_3.show()
self.groupBox_4.show()
self.groupBox_7.show()
self.groupBox_8.show()
self.groupBox_5.hide()
self.groupBox_6.hide()
elif i == 1:
self.groupBox.hide()
self.groupBox_2.hide()
self.groupBox_3.hide()
self.groupBox_4.hide()
self.groupBox_7.hide()
self.groupBox_8.hide()
self.groupBox_5.show()
self.groupBox_6.show()
def closeEvent(self, event):
self.main.pushButton_4.setEnabled(True)
class Downloads(QtWidgets.QWidget):
def getText(self, text):
return QtWidgets.QLabel(text)
def getLine(self):
line = QtWidgets.QFrame(self)
line.setFrameShape(QtWidgets.QFrame.VLine)
return line
def __init__(self, main):
super().__init__()
self.main = main
self.setWindowTitle("MPDL/Downloads")
self.resize(700, 300)
self.setFixedSize(700, 300)
self.setWindowIcon(util.getIcon())
self.label = QtWidgets.QLabel("Downloads", self)
self.label.setGeometry(QtCore.QRect(20, 10, 151, 31))
self.label.setFont(util.getFont(17, False, True))
self.table = QtWidgets.QTableWidget(self)
self.table.setGeometry(QtCore.QRect(10, 50, 680, 240))
self.table.setColumnCount(7)
arr = {"UUID": "0", "Status": "1", "Size": "2", "Progress": "3", "ETA": "4", "Speed": "5", "Source": "6"}
self.table.setHorizontalHeaderLabels(arr.keys())
self.table.setEditTriggers(self.table.NoEditTriggers)
def closeEvent(self, event):
self.main.pushButton_3.setEnabled(True)
# TODO
# add more error handling
# divide size to get MB
# check if sizes have to be added up
# combination type error: str+int at "Decrypting (Video)"
class Sniffer(QtWidgets.QWidget):
def hanldebutton(self):
import headers
i = self.main.sniffer.combobox.currentIndex()
if i == 0:
if len(self.listView.selectedItems()) >= 1: