trending.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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(articles=False):
  35. # This will give out the information about trending publictions
  36. # Either
  37. # So we want to request a query to the SDK to search what ever
  38. # the user wants. The problem is it can be a very large output.
  39. # For example the "blender dumbass" query returns 1000 claims
  40. # on the LBRY network. And people will wait for a very long time
  41. # on something that might have a million claims.
  42. # So instead we are going to request only the first 20 and let
  43. # the user load more.
  44. # If could be articles
  45. text = ""
  46. if articles:
  47. text = " ARTICLES"
  48. w, h = tsize()
  49. page_size = h - 5
  50. page = 1
  51. while True:
  52. # Printing the search query and page number
  53. center("TRENDING"+text+" PAGE :"+str(page))
  54. if not articles:
  55. out = check_output([flbry_globals["lbrynet"],
  56. "claim", "search",
  57. '--page='+str(page),
  58. '--page_size='+str(page_size),
  59. "--no_totals",
  60. "--order_by=trending_mixed"])
  61. else:
  62. out = check_output([flbry_globals["lbrynet"],
  63. "claim", "search",
  64. '--page='+str(page),
  65. '--page_size='+str(page_size),
  66. "--no_totals",
  67. "--order_by=trending_mixed",
  68. '--media_types=text/markdown'])
  69. # Now we want to parse the json
  70. try:
  71. out = json.loads(out)
  72. except:
  73. center("Connect to LBRY first.", "bdrd")
  74. return
  75. d = {"categories":["Type", "Channel", "Title"],
  76. "size":[1,1,5],
  77. "data":[]}
  78. try:
  79. # List what we found
  80. for n, i in enumerate(out["items"]):
  81. title = "---!Failed Loading Title---"
  82. ftype = "claim"
  83. bywho = "[anonymous]"
  84. try:
  85. try:
  86. title = i["value"]["title"]
  87. except:
  88. title = i['name']
  89. try:
  90. ftype = what[i["value"]["stream_type"]]
  91. except:
  92. ftype = what[i["value_type"]]
  93. bywho = i["signing_channel"]["name"]
  94. except:
  95. pass
  96. d["data"].append([ftype, bywho, title])
  97. table(d)
  98. # Tell the user that they might want to load more
  99. center("---type 'more' to load more---")
  100. page = page +1
  101. # Error messages
  102. except Exception as e:
  103. if "code" in out:
  104. center("Error code: "+out["code"], "bdrd")
  105. if "message" in out:
  106. center("Error: "+out["message"], "bdrd")
  107. else:
  108. center("Error: "+e, "bdrd")
  109. return
  110. while True:
  111. # Making sure that we stop every time a new page is reached
  112. c = input(typing_dots())
  113. if c == "more":
  114. break
  115. try:
  116. c = int(c)
  117. except:
  118. return
  119. url.get(out["items"][c]["canonical_url"])
  120. # Print the list again
  121. table(d)
  122. center("---type 'more' to load more---")