uploads.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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():
  35. # This file will show the upload history of the user.
  36. # So instead we are going to request only the first 20 and let
  37. # the user load more.
  38. page_size = 20
  39. page = 1
  40. while True:
  41. # Printing the search query and page number
  42. print(" "+clr["bold"]+clr["bdma"], " UPLOADS ",
  43. wdth(" ", 20), " PAGE :",
  44. wdth(page, 3),
  45. wdth(" ", 32)+clr["norm"])
  46. out = check_output(["flbry/lbrynet",
  47. "stream", "list",
  48. '--page='+str(page),
  49. '--page_size='+str(page_size),
  50. "--no_totals"])
  51. # Now we want to parse the json
  52. try:
  53. out = json.loads(out)
  54. except:
  55. print(" Connect to LBRY first.")
  56. return
  57. # Print the categories
  58. print(" "+clr["bold"]+clr["bdma"],wdth(" ", 3),
  59. "", wdth("TYPE", 8),
  60. "", wdth("CHANNEL", 20),
  61. "", wdth("TITLE", 20)+wdth(" ", 31)+clr["norm"])
  62. try:
  63. # List what we found
  64. for n, i in enumerate(out["items"]):
  65. # This will make each new line a different shade
  66. if n % 2:
  67. b = "d"
  68. else:
  69. b = "b"
  70. title = "---!Failed Loading Title---"
  71. ftype = "claim"
  72. bywho = "@Anonymous"
  73. try:
  74. try:
  75. title = i["value"]["title"]
  76. except:
  77. title = i['name']
  78. ftype = i["value_type"]
  79. bywho = i["signing_channel"]["name"]
  80. except:
  81. pass
  82. print(" "+clr["bold"]+clr["b"+b+"ma"],wdth(n, 3) ,
  83. clr["norm"]+clr["b"+b+"bu"]+clr["ital"],wdth(what[ftype], 8),
  84. clr["norm"]+clr["bold"]+clr["b"+b+"bu"], wdth(bywho, 20),
  85. clr["norm"]+clr["tbwh"]+clr["b"+b+"bu"], wdth(title, 50), clr["norm"])
  86. # Tell the user that he might want to load more
  87. print(" "+clr["bold"]+clr["bdma"],
  88. " ---type more to load more---",
  89. wdth(" ",40)+clr["norm"])
  90. page = page +1
  91. # Error messages
  92. except Exception as e:
  93. if "code" in out:
  94. print(" Error code: ", out["code"] )
  95. if out["code"] == -32500:
  96. print(" SDK is still starting. Patience!")
  97. else:
  98. print(" Error :", e)
  99. return
  100. # Making sure that we stop every time a new page is reached
  101. c = input(" :: ")
  102. if c != "more":
  103. break
  104. try:
  105. c = int(c)
  106. except:
  107. return
  108. while True:
  109. url.get(out["items"][c]["permanent_url"])
  110. c = input(" :: ")
  111. if not c:
  112. break
  113. try:
  114. c = int(c)
  115. except:
  116. return