odysee.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #####################################################################
  2. # #
  3. # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
  4. # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
  5. # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
  6. # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
  7. # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
  8. # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
  9. # #
  10. # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
  11. # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
  12. # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
  13. # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
  14. # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
  15. # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
  16. # #
  17. # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
  18. # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
  19. # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
  20. # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
  21. # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
  22. # #
  23. # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
  24. # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
  25. # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
  26. # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
  27. # #
  28. #####################################################################
  29. # This is for features that are developed only for Odysee. Apart from
  30. # livestreams which are in a dedicated file.
  31. import os
  32. import json
  33. import urllib.request
  34. # This will make odysee think that we are just a normal browser running windows ( lol )
  35. # and connecting from Odysee.com
  36. headers = {"Origin":"https://odysee.com",
  37. "Referer":"https://odysee.com/",
  38. "User-Agent":"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"}
  39. def get_odysee_notifications(win):
  40. # This function will query the odysee api for notifications.
  41. auth = win.settings["auth_token"]
  42. if not auth:
  43. return False
  44. url = "https://api.odysee.com/notification/list?auth_token="+auth+"&is_app_readable=true&type=comment_replies%2Chyperchat_replies"
  45. req = urllib.request.Request(url, data=None, headers=headers)
  46. f = urllib.request.urlopen(req)
  47. data = json.loads(f.read().decode('utf-8'))
  48. if "data" in data:
  49. return data["data"]
  50. else:
  51. return False
  52. def get_odysee_views(win, claim_id):
  53. # This function will return the views of a particular claim ID
  54. auth = win.settings["auth_token"]
  55. if not auth:
  56. return False
  57. url="https://api.odysee.com/file/view_count?auth_token="+auth+"&claim_id="+claim_id
  58. req = urllib.request.Request(url, data=None, headers=headers)
  59. f = urllib.request.urlopen(req)
  60. data = json.loads(f.read().decode('utf-8'))
  61. if "data" in data:
  62. return data["data"]
  63. else:
  64. return False
  65. def get_odysee_subs(win, claim_id):
  66. # This function will return the views of a particular claim ID
  67. auth = win.settings["auth_token"]
  68. if not auth:
  69. return False
  70. url="https://api.odysee.com/subscription/sub_count?auth_token="+auth+"&claim_id="+claim_id
  71. req = urllib.request.Request(url, data=None, headers=headers)
  72. f = urllib.request.urlopen(req)
  73. data = json.loads(f.read().decode('utf-8'))
  74. if "data" in data:
  75. return data["data"]
  76. else:
  77. return False