list_files.py 5.5 KB

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