SHA1 von Python nach vb.net übersetzen

  • VB.NET

    SHA1 von Python nach vb.net übersetzen

    Hallo!
    Ich hab eine Python Funktion die ich gerne nach C# oder vb.net übersetzen möchte..
    ..als Ausgabe bekomme ich bei der SHA1 Erzeugung einen 40-stelligen Hexadezimalcode..wenn ich das jedoch nach vb.net übersetze ist der Hexadezimalcode um ein vielfaches längerVielleicht kann mir ja jemand bei der Übersetzung helfen!?

    Python Funktion:

    Python-Quellcode

    1. def playvideo(video_id, client_location, source_id=None):
    2. from hashlib import sha1
    3. adaptivaddon=xbmc.executeJSONRPC('{"jsonrpc": "2.0", "id": 1, "method": "Addons.GetAddonDetails", "params": {"addonid": "inputstream.adaptive", "properties": ["enabled"]}}')
    4. struktur = json.loads(adaptivaddon)
    5. debug("adaptivaddon struktur :")
    6. debug(struktur)
    7. is_type=""
    8. if not "error" in struktur.keys() :
    9. if struktur["result"]["addon"]["enabled"]==True:
    10. is_type="inputstream.adaptive"
    11. if is_type=="":
    12. adaptivaddon=xbmc.executeJSONRPC('{"jsonrpc": "2.0", "id": 1, "method": "Addons.GetAddonDetails", "params": {"addonid": "inputstream.mpd", "properties": ["enabled"]}}')
    13. struktur = json.loads(adaptivaddon)
    14. if not "error" in struktur.keys() :
    15. if struktur["result"]["addon"]["enabled"]==True:
    16. is_type="inputstream.mpd"
    17. if is_type=="":
    18. access_token = 'h''b''b''t''v'
    19. salt = '0''1''r''e''e''6''e''L''e''i''w''i''u''m''i''e''7''i''e''V''8''p''a''h''g''e''i''T''u''i''3''B'
    20. client_name='h''b''b''t''v'
    21. else:
    22. access_token = 'seventv-web'
    23. salt = '01!8d8F_)r9]4s[qeuXfP%'
    24. client_name=''
    25. # dialog = xbmcgui.Dialog()
    26. #nr=dialog.ok("Inputstream", "Inputstream fehlt")
    27. #return ""
    28. print "is_type :"+is_type
    29. if source_id is None:
    30. source_id=0
    31. json_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s?' \
    32. 'access_token=%s&client_location=%s&client_name=%s' \
    33. % (video_id, access_token, client_location, client_name)
    34. json_data = geturl(json_url)
    35. json_data = json.loads(json_data)
    36. print json_data
    37. print "........................"
    38. if not is_type=="":
    39. for stream in json_data['sources']:
    40. if stream['mimetype']=='application/dash+xml':
    41. if int(source_id) < int(stream['id']):
    42. source_id = stream['id']
    43. print source_id
    44. else:
    45. #debug("Protected : "+json_data["is_protected"])
    46. if json_data["is_protected"]==True:
    47. xbmc.executebuiltin('Notification("Inputstream", "DRM geschützte Folgen gehen nur mit Inputstream")')
    48. return
    49. else:
    50. for stream in json_data['sources']:
    51. if stream['mimetype']=='video/mp4':
    52. if int(source_id) < int(stream['id']):
    53. source_id = stream['id']
    54. print source_id
    55. client_id_1 = salt[:2] + sha1(
    56. ''.join([str(video_id), salt, access_token, client_location, salt, client_name]).encode(
    57. 'utf-8')).hexdigest()
    58. json_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources?' \
    59. 'access_token=%s&client_location=%s&client_name=%s&client_id=%s' \
    60. % (video_id, access_token, client_location, client_name, client_id_1)
    61. json_data = geturl(json_url)
    62. json_data = json.loads(json_data)
    63. print json_data
    64. print "........................"
    65. server_id = json_data['server_id']
    66. #client_name = 'kolibri-1.2.5'
    67. client_id = salt[:2] + sha1(''.join([salt, video_id, access_token, server_id,client_location, str(source_id), salt, client_name]).encode('utf-8')).hexdigest()
    68. url_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url?%s' % (video_id, urllib.urlencode({
    69. 'access_token': access_token,
    70. 'client_id': client_id,
    71. 'client_location': client_location,
    72. 'client_name': client_name,
    73. 'server_id': server_id,
    74. 'source_ids': str(source_id),
    75. }))
    76. print "url_api_url :"+url_api_url
    77. json_data = geturl(url_api_url)
    78. json_data = json.loads(json_data)
    79. debug ("---------------------------")
    80. debug( json_data)
    81. debug( "........................")
    82. max_id=0
    83. for stream in json_data["sources"]:
    84. ul=stream["url"]
    85. try:
    86. sid=re.compile('-tp([0-9]+).mp4', re.DOTALL).findall(ul)[0]
    87. id=int(sid)
    88. if max_id<id:
    89. max_id=id
    90. data=ul
    91. except:
    92. data=ul
    93. #data=json_data["sources"][-1]["url"]
    94. userAgent = 'User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
    95. addon_handle = int(sys.argv[1])
    96. listitem = xbmcgui.ListItem(path=data+"|"+userAgent)
    97. #listitem.setProperty('inputstream.mpd.license_type', 'com.widevine.alpha')
    98. #listitem.setProperty('inputstream.mpd.license_type', 'com.widevine.alpha')
    99. listitem.setProperty(is_type+".license_type", "com.widevine.alpha")
    100. listitem.setProperty(is_type+".manifest_type", "mpd")
    101. listitem.setProperty('inputstreamaddon', is_type)
    102. try:
    103. lic=json_data["drm"]["licenseAcquisitionUrl"]
    104. token=json_data["drm"]["token"]
    105. listitem.setProperty(is_type+'.license_key', lic +"?token="+token+"|"+userAgent+"|R{SSM}|")
    106. except:
    107. pass
    108. #listitem.setProperty('inputstreamaddon', 'inputstream.mpd')
    109. xbmcplugin.setResolvedUrl(addon_handle, True, listitem)
    110. #print "Daten lic :"+lic
    111. #print "Daten token :"+token
    112. #print "Daten data :"+data
    113. return ""



    vb.net Funktion:

    VB.NET-Quellcode

    1. Private Function _playVideo(ByVal video_id As String, ByVal client_location As String, Optional ByVal source_id As String = Nothing)
    2. 'Get JSON for sourceID
    3. Dim json_url = "http://vas.sim-technik.de/vas/live/v2/videos/" & video_id & "?access_token=" & access_token & "&client_location=" & client_location & "&client_name=" & client_name
    4. Dim _jsonString As String = Nothing
    5. Using httpClient As WebClient = New WebClient()
    6. _jsonString = httpClient.DownloadString(json_url)
    7. End Using
    8. Dim _json As JSON_Source_ID = _json_CreateFromString(Of JSON_Source_ID)(_jsonString)
    9. 'Read sourceID out of JSON
    10. source_id = 0
    11. For Each _source As Source In _json.sources
    12. If _source.mimetype = "application/dash+xml" Then
    13. If source_id < _source.id Then
    14. source_id = _source.id
    15. End If
    16. End If
    17. Next
    18. Using sha1 As System.Security.Cryptography.SHA1CryptoServiceProvider = New System.Security.Cryptography.SHA1CryptoServiceProvider
    19. Dim bytesToHash() As Byte = Encoding.UTF8.GetBytes(video_id & salt & access_token & client_location & salt & client_name)
    20. Dim client_id_1 As String = HexStringFromBytes(bytesToHash)
    21. Debug.WriteLine(client_id_1)
    22. End Using
    23. End Function

    Aufrufen tu ich die Funktion mit:
    _playVideo("5474102", "http://www.7tv.de/galileo/2018154-mittwoch-helfer-oder-last-roboter-als-familienmitglieder-ganze-folge")