channel.py 5.9 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. # This file will perform a simple search on the LBRY network.
  30. from subprocess import *
  31. import json
  32. from flbry import url
  33. from flbry.variables import *
  34. def simple(args=""):
  35. # The user might write the search argument right in the same
  36. # line as the work search.
  37. #
  38. # : seach blenderdumbass
  39. #
  40. # Or they can type nothing. And be confused of what happened.
  41. # So I want to provide a catcher here. If they type nothing it
  42. # will ask them to provide a search query.
  43. if not args:
  44. args = input(" Channel url :: ")
  45. if not args.startswith("@"):
  46. args = "@"+args
  47. # So we want to request a query to the SDK to search what ever
  48. # the user wants. The problem is it can be a very large output.
  49. # For example the "blender dumbass" query returns 1000 claims
  50. # on the LBRY network. And people will wait for a very long time
  51. # on something that might have a million claims.
  52. # So instead we are going to request only the first 20 and let
  53. # the user load more.
  54. page_size = 20
  55. page = 1
  56. while True:
  57. # Printing the search query and page number
  58. print(" "+clr["bold"]+clr["bdma"], " CHANNEL: ",
  59. wdth(args, 20), " PAGE :",
  60. wdth(page, 3),
  61. wdth(" ", 32)+clr["norm"])
  62. out = check_output(["flbry/lbrynet",
  63. "claim", "search", '--channel='+args,
  64. '--page='+str(page),
  65. '--page_size='+str(page_size),
  66. "--no_totals",
  67. '--order_by=release_time'])
  68. # Now we want to parse the json
  69. try:
  70. out = json.loads(out)
  71. except:
  72. print(" Connect to LBRY first.")
  73. return
  74. # Print the categories
  75. print(" "+clr["bold"]+clr["bdma"],wdth(" ", 3),
  76. "", wdth("TYPE", 8),
  77. "", wdth("TITLE", 22)+wdth(" ", 51)+clr["norm"])
  78. try:
  79. # List what we found
  80. for n, i in enumerate(out["items"]):
  81. # This will make each new line a different shade
  82. if n % 2:
  83. b = "d"
  84. else:
  85. b = "b"
  86. title = "---!Failed Loading Title---"
  87. ftype = "claim"
  88. try:
  89. try:
  90. title = i["value"]["title"]
  91. except:
  92. title = i['name']
  93. ftype = i["value_type"]
  94. except:
  95. pass
  96. print(" "+clr["bold"]+clr["b"+b+"ma"]
  97. ,wdth(n, 3) ,
  98. clr["norm"]+clr["b"+b+"bu"]+clr["ital"],
  99. wdth(what[ftype], 8),
  100. clr["norm"]+clr["tbwh"]+clr["b"+b+"bu"],
  101. wdth(title, 72), clr["norm"])
  102. # Tell the user that he might want to load more
  103. print(" "+clr["bold"]+clr["bdma"],
  104. " ---type more to load more---",
  105. wdth(" ",40)+clr["norm"])
  106. page = page +1
  107. # Error messages
  108. except Exception as e:
  109. if "code" in out:
  110. print(" Error code: ", out["code"] )
  111. if out["code"] == -32500:
  112. print(" SDK is still starting. Patience!")
  113. else:
  114. print(" Error :", e)
  115. return
  116. # Making sure that we stop every time a new page is reached
  117. c = input(typing_dots())
  118. if c != "more":
  119. break
  120. try:
  121. c = int(c)
  122. except:
  123. return
  124. while True:
  125. url.get(out["items"][c]["canonical_url"])
  126. c = input(typing_dots())
  127. if not c:
  128. break
  129. try:
  130. c = int(c)
  131. except:
  132. return