feat(dolbySound): enable/disable dolby sound in addon settings
[plugin.video.netflix.git] / resources / lib / MSL.py
index 802cf662b7b21e77910832a5bc5293e377e8a8f9..db9d68b4b94d5dfab0ab35a446f10303d07a04ce 100644 (file)
@@ -46,13 +46,11 @@ class MSL:
         'license': 'http://www.netflix.com/api/msl/NFCDCH-LX/cadmium/license'
     }
 
-    def __init__(self, email, password, kodi_helper):
+    def __init__(self, kodi_helper):
         """
         The Constructor checks for already existing crypto Keys.
         If they exist it will load the existing keys
         """
-        self.email = email
-        self.password = password
         self.kodi_helper = kodi_helper
         try:
             os.mkdir(self.kodi_helper.msl_data_path)
@@ -149,8 +147,6 @@ class MSL:
 
                 # Audio
                 'heaac-2-dash',
-                'ddplus-2.0-dash',
-                'ddplus-5.1-dash',
                 'dfxp-ls-sdh',
                 'simplesdh',
                 'nflx-cmisc',
@@ -173,6 +169,12 @@ class MSL:
             'clientVersion': '4.0004.899.011',
             'uiVersion': 'akira'
         }
+
+        # Check if dolby sound is enabled and add to profles
+        if self.kodi_helper.get_dolby_setting():
+            manifest_request_data['profiles'].append('ddplus-2.0-dash')
+            manifest_request_data['profiles'].append('ddplus-5.1-dash')
+
         request_data = self.__generate_msl_request_data(manifest_request_data)
         resp = self.session.post(self.endpoints['manifest'], request_data)
 
@@ -267,6 +269,7 @@ class MSL:
                 pssh = manifest['psshb64'][0]
 
         seconds = manifest['runtime']/1000
+        init_length = seconds / 2 * 12 + 20*1000
         duration = "PT"+str(seconds)+".00S"
 
         root = ET.Element('MPD')
@@ -287,6 +290,10 @@ class MSL:
 
             for downloadable in video_track['downloadables']:
 
+                codec = 'h264'
+                if 'hevc' in downloadable['contentProfile']:
+                    codec = 'hevc'
+
                 hdcp_versions = '0.0'
                 for hdcp in downloadable['hdcpVersions']:
                     if hdcp != 'none':
@@ -298,14 +305,14 @@ class MSL:
                                     bandwidth=str(downloadable['bitrate']*1024),
                                     hdcp=hdcp_versions,
                                     nflxContentProfile=str(downloadable['contentProfile']),
-                                    codecs='h264',
+                                    codecs=codec,
                                     mimeType='video/mp4')
 
                 #BaseURL
                 ET.SubElement(rep, 'BaseURL').text = self.__get_base_url(downloadable['urls'])
                 # Init an Segment block
-                segment_base = ET.SubElement(rep, 'SegmentBase', indexRange="0-60000", indexRangeExact="true")
-                ET.SubElement(segment_base, 'Initialization', range='0-60000')
+                segment_base = ET.SubElement(rep, 'SegmentBase', indexRange="0-"+str(init_length), indexRangeExact="true")
+                ET.SubElement(segment_base, 'Initialization', range='0-'+str(init_length))
 
 
 
@@ -334,8 +341,8 @@ class MSL:
                 #BaseURL
                 ET.SubElement(rep, 'BaseURL').text = self.__get_base_url(downloadable['urls'])
                 # Index range
-                segment_base = ET.SubElement(rep, 'SegmentBase', indexRange="0-60000", indexRangeExact="true")
-                ET.SubElement(segment_base, 'Initialization', range='0-60000')
+                segment_base = ET.SubElement(rep, 'SegmentBase', indexRange="0-"+str(init_length), indexRangeExact="true")
+                ET.SubElement(segment_base, 'Initialization', range='0-'+str(init_length))
 
 
         xml = ET.tostring(root, encoding='utf-8', method='xml')
@@ -454,12 +461,13 @@ class MSL:
             if 'usertoken' in self.tokens:
                 pass
             else:
+                account = self.kodi_helper.get_credentials()
                 # Auth via email and password
                 header_data['userauthdata'] = {
                     'scheme': 'EMAIL_PASSWORD',
                     'authdata': {
-                        'email': self.email,
-                        'password': self.password
+                        'email': account['email'],
+                        'password': account['password']
                     }
                 }