livestreams.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # While livestreams were never officially a part of LBRY, comments weren't
  30. # either and people want to watch and interact with livestreams too while
  31. # they do not want to use Odysee.com.
  32. # The odysee devs told me that they do not want livestreams to be playable
  33. # outside of Odysee. So a number of interesting sticks will have to be done
  34. # to make them actually work outside of odysee.
  35. import os
  36. import json
  37. import urllib.request
  38. # This will make odysee think that we are just a normal browser running windows ( lol )
  39. # and connecting from Odysee.com
  40. headers = {"Origin":"https://odysee.com",
  41. "Referer":"https://odysee.com/",
  42. "User-Agent":"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"}
  43. def get_data(channel_id):
  44. # This function will return data about channel livestreams.
  45. url = "https://api.odysee.live/livestream/is_live?channel_claim_id="+channel_id
  46. req = urllib.request.Request(url, data=None, headers=headers)
  47. f = urllib.request.urlopen(req)
  48. return json.loads(f.read().decode('utf-8'))
  49. def get_all():
  50. # This function will return all current livestreams on Odysee.
  51. url = "https://api.odysee.live/livestream/all"
  52. req = urllib.request.Request(url, data=None, headers=headers)
  53. f = urllib.request.urlopen(req)
  54. return json.loads(f.read().decode('utf-8'))