following.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. # Gets latest posts from subscriptions
  30. from subprocess import *
  31. import json
  32. from flbry.variables import *
  33. from flbry import url
  34. def following():
  35. # Get the subscriptions
  36. following = check_output([flbry_globals["lbrynet"], "preference", "get"])
  37. try:
  38. following = json.loads(following)
  39. except:
  40. center("Connect to LBRY first.", "bdrd")
  41. return
  42. following = following["shared"]["value"]["subscriptions"]
  43. # Get enough results to fill the screen, then prompt user for more
  44. w, h = tsize()
  45. page_size = h - 5
  46. page = 1
  47. while True:
  48. command = [flbry_globals["lbrynet"], "claim", "search", "--page="+str(page), "--page_size="+str(page_size), "--order_by=release_time"]
  49. # Gets each channel's ID and add it to the command
  50. for i in following:
  51. i = i.split("#", 1)[1]
  52. command.append("--channel_ids="+i)
  53. out = check_output(command)
  54. out = json.loads(out)
  55. try:
  56. data_print = {"categories":["Type", "Channel", "Title"],
  57. "size":[1,2,5],
  58. "data":[]}
  59. # List what we found
  60. for n, i in enumerate(out["items"]):
  61. title = "---!Failed Loading Title---"
  62. ftype = "claim"
  63. channel = "[anonymous]"
  64. try:
  65. try:
  66. title = i["value"]["title"]
  67. except:
  68. title = i['name']
  69. try:
  70. ftype = what[i["value"]["stream_type"]]
  71. except:
  72. ftype = what[i["value_type"]]
  73. try:
  74. channel = i["signing_channel"]["value"]["title"]
  75. except:
  76. channel = i["signing_channel"]["normalized_name"]
  77. except:
  78. pass
  79. data_print["data"].append([ftype, channel, title])
  80. table(data_print)
  81. # Tell the user that they might want to load more
  82. center("---type 'more' to load more---")
  83. page = page +1
  84. except Exception as e:
  85. if "code" in out:
  86. center("Error code: "+out["code"], "bdrd")
  87. if "message" in out:
  88. center("Error: "+out["message"], "bdrd")
  89. else:
  90. center("Error: "+e, "bdrd")
  91. return
  92. while True:
  93. # Making sure that we stop every time a new page is reached
  94. c = input(typing_dots())
  95. if c == "more":
  96. break
  97. try:
  98. c = int(c)
  99. except:
  100. return
  101. url.get(out["items"][c]["canonical_url"])
  102. # Print the list again
  103. table(data_print)
  104. center("---type 'more' to load more---")
  105. def follow_channel(channel, name):
  106. # Get the shared preferences so they can be modified
  107. subscriptions = check_output([flbry_globals["lbrynet"], "preference", "get", "shared"])
  108. subscriptions = json.loads(subscriptions)["shared"]
  109. # If the channel is not in the subscriptions we add it
  110. if not channel in subscriptions["value"]["subscriptions"]:
  111. subscriptions["value"]["subscriptions"].append(channel)
  112. x = {"notificationsDisabled": True, "uri": channel}
  113. subscriptions["value"]["following"].append(x)
  114. x = check_output([flbry_globals["lbrynet"], "preference", "set", "shared", json.dumps(subscriptions)])
  115. center("Followed "+name, "bdgr")
  116. else:
  117. # Alert the user they're already subscribed
  118. center("Already following "+name, "bdrd")
  119. def unfollow_channel(channel, name):
  120. # Get the shared preferences so they can be modified
  121. subscriptions = check_output([flbry_globals["lbrynet"], "preference", "get", "shared"])
  122. subscriptions = json.loads(subscriptions)["shared"]
  123. # If the channel is not in the subscriptions we add it
  124. if channel in subscriptions["value"]["subscriptions"]:
  125. subscriptions["value"]["subscriptions"].remove(channel)
  126. x = {"notificationsDisabled": True, "uri": channel}
  127. subscriptions["value"]["following"].remove(x)
  128. x = check_output([flbry_globals["lbrynet"], "preference", "set", "shared", json.dumps(subscriptions)])
  129. center("Unfollowed "+name, "bdgr")
  130. else:
  131. # Alert the user they're already subscribed
  132. center("Not following "+name, "bdrd")