livestreams.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 time
  38. import urllib.request
  39. from flbry import fetch
  40. # This will make odysee think that we are just a normal browser running windows ( lol )
  41. # and connecting from Odysee.com
  42. headers = {"Origin":"https://odysee.com",
  43. "Referer":"https://odysee.com/",
  44. "User-Agent":"Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"}
  45. def get_data(channel_id):
  46. # This function will return data about channel livestreams.
  47. url = "https://api.odysee.live/livestream/is_live?channel_claim_id="+channel_id
  48. req = urllib.request.Request(url, data=None, headers=headers)
  49. f = urllib.request.urlopen(req)
  50. return json.loads(f.read().decode('utf-8'))
  51. def get_all():
  52. # This function will return all current livestreams on Odysee.
  53. url = "https://api.odysee.live/livestream/all"
  54. req = urllib.request.Request(url, data=None, headers=headers)
  55. f = urllib.request.urlopen(req)
  56. return json.loads(f.read().decode('utf-8'))
  57. def get_upcoming( channels=[], tags=[]):
  58. # This function will return all upcoming livestreams
  59. c = {"all_tags":["c:scheduled-livestream"],
  60. "release_time":">"+str(int(time.time())),
  61. "remove_duplicates":True}
  62. if tags:
  63. c["any_tags"] = tags
  64. if channels:
  65. c["channel_ids"] = channels
  66. out = fetch.lbrynet("claim_search", c)
  67. return out