uploads.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. w, h = tsize()
  39. page_size = h - 5
  40. page = 1
  41. while True:
  42. # Printing the search query and page number
  43. center("UPLOADS PAGE: "+str(page))
  44. out = check_output([flbry_globals["lbrynet"],
  45. "stream", "list",
  46. '--page='+str(page),
  47. '--page_size='+str(page_size),
  48. "--no_totals"])
  49. # Now we want to parse the json
  50. try:
  51. out = json.loads(out)
  52. except:
  53. center("Connect to LBRY first.", "bdrd")
  54. return
  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. bywho = "[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. bywho = i["signing_channel"]["name"]
  74. except:
  75. pass
  76. data_print["data"].append([ftype, bywho, title])
  77. table(data_print)
  78. # Tell the user that they might want to load more
  79. center("---type more to load more---")
  80. page = page +1
  81. # Error messages
  82. except Exception as e:
  83. if "code" in out:
  84. center("Error code: "+out["code"], "bdrd")
  85. if "message" in out:
  86. center("Error: "+out["message"], "bdrd")
  87. else:
  88. center("Error: "+e, "bdrd")
  89. return
  90. # Making sure that we stop every time a new page is reached
  91. c = input(typing_dots())
  92. if c != "more":
  93. break
  94. w, h = tsize()
  95. try:
  96. c = int(c)
  97. except:
  98. return
  99. while True:
  100. url.get(out["items"][c]["permanent_url"])
  101. # Print the list again
  102. table(data_print)
  103. center("---type more to load more---")
  104. c = input(typing_dots())
  105. if not c:
  106. break
  107. try:
  108. c = int(c)
  109. except:
  110. return