fix(msl): Changes mimeType of subtitles to ttml
[plugin.video.netflix.git] / resources / lib / MSL.py
index 7f813d470b33acda3ea7c102751a9f4af4c44cde..0b623f86d57584b1de13befd1df90f40649a4356 100644 (file)
@@ -1,3 +1,8 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Module: MSL
+# Created on: 26.01.2017
+
 import base64
 import gzip
 import json
 import base64
 import gzip
 import json
@@ -46,13 +51,11 @@ class MSL:
         'license': 'http://www.netflix.com/api/msl/NFCDCH-LX/cadmium/license'
     }
 
         '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
         """
         """
         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)
         self.kodi_helper = kodi_helper
         try:
             os.mkdir(self.kodi_helper.msl_data_path)
@@ -149,11 +152,13 @@ class MSL:
 
                 # Audio
                 'heaac-2-dash',
 
                 # Audio
                 'heaac-2-dash',
-                'ddplus-2.0-dash',
-                'ddplus-5.1-dash',
+
+                #subtiltes
                 'dfxp-ls-sdh',
                 'dfxp-ls-sdh',
-                'simplesdh',
-                'nflx-cmisc',
+                #'simplesdh',
+                #'nflx-cmisc',
+
+                #unkown
                 'BIF240',
                 'BIF320'
             ],
                 'BIF240',
                 'BIF320'
             ],
@@ -173,6 +178,12 @@ class MSL:
             'clientVersion': '4.0004.899.011',
             'uiVersion': 'akira'
         }
             '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)
 
         request_data = self.__generate_msl_request_data(manifest_request_data)
         resp = self.session.post(self.endpoints['manifest'], request_data)
 
@@ -342,6 +353,26 @@ class MSL:
                 segment_base = ET.SubElement(rep, 'SegmentBase', indexRange="0-"+str(init_length), indexRangeExact="true")
                 ET.SubElement(segment_base, 'Initialization', range='0-'+str(init_length))
 
                 segment_base = ET.SubElement(rep, 'SegmentBase', indexRange="0-"+str(init_length), indexRangeExact="true")
                 ET.SubElement(segment_base, 'Initialization', range='0-'+str(init_length))
 
+        # Multiple Adaption Set for subtiles
+        for text_track in manifest['textTracks']:
+            print text_track
+            if 'downloadables' not in text_track or text_track['downloadables'] is None:
+                continue
+            subtiles_adaption_set = ET.SubElement(period, 'AdaptationSet',
+                                                  lang=text_track['bcp47'],
+                                                  contentType='text',
+                                                  mimeType='text/ttml')
+            for downloadable in text_track['downloadables']:
+                rep = ET.SubElement(subtiles_adaption_set, 'Representation',
+                                    bandwidth='0',
+                                    nflxProfile=downloadable['contentProfile']
+                                    )
+                print downloadable['urls']
+                ET.SubElement(rep, 'BaseURL').text = self.__get_base_url(downloadable['urls'])
+
+
+
+
 
         xml = ET.tostring(root, encoding='utf-8', method='xml')
         xml = xml.replace('\n', '').replace('\r', '')
 
         xml = ET.tostring(root, encoding='utf-8', method='xml')
         xml = xml.replace('\n', '').replace('\r', '')
@@ -459,12 +490,13 @@ class MSL:
             if 'usertoken' in self.tokens:
                 pass
             else:
             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': {
                 # Auth via email and password
                 header_data['userauthdata'] = {
                     'scheme': 'EMAIL_PASSWORD',
                     'authdata': {
-                        'email': self.email,
-                        'password': self.password
+                        'email': account['email'],
+                        'password': account['password']
                     }
                 }
 
                     }
                 }