list_files.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. w, h = tsize()
  40. page_size = h - 5
  41. page = 1
  42. while True:
  43. # Printing the search query and page number
  44. center("DOWNLOAD HISTORY. PAGE :"+str(page))
  45. out = check_output([flbry_globals["lbrynet"],
  46. "file", "list",
  47. '--page='+str(page),
  48. '--page_size='+str(page_size),
  49. '--sort=added_on',
  50. '--completed=true'])
  51. # Now we want to parse the json
  52. try:
  53. out = json.loads(out)
  54. except:
  55. center("Connect to LBRY first.", "bdrd")
  56. return
  57. data_print = {"categories":["Type", "Channel", "Title"],
  58. "size":[1,2,5],
  59. "data":[]}
  60. try:
  61. # List what we found
  62. for n, i in enumerate(out["items"]):
  63. title = "---!Failed Loading Title---"
  64. ftype = "claim"
  65. bywho = "[anonymous]"
  66. try:
  67. try:
  68. title = i["metadata"]["title"]
  69. except:
  70. title = i['claim_name']
  71. bywho = i["channel_name"]
  72. if bywho == None:
  73. bywho = "[anonymous]"
  74. try:
  75. ftype = what[i["metadata"]["stream_type"]]
  76. except:
  77. ftype = what['stream']
  78. except:
  79. pass
  80. data_print["data"].append([ftype, bywho, title])
  81. table(data_print)
  82. # Tell the user that they might want to load more
  83. center("---type more to load more---")
  84. page = page +1
  85. # Error messages
  86. except Exception as e:
  87. if "code" in out:
  88. center("Error code: "+out["code"], "bdrd")
  89. if "message" in out:
  90. center("Error: "+out["message"], "bdrd")
  91. else:
  92. center("Error: "+e, "bdrd")
  93. return
  94. # Making sure that we stop every time a new page is reached
  95. c = input(typing_dots())
  96. if c != "more":
  97. break
  98. try:
  99. c = int(c)
  100. except:
  101. return
  102. while True:
  103. url.get("lbry://"+out["items"][c]["claim_name"]+"#"+out["items"][c]["claim_id"])
  104. # Print the list again
  105. table(data_print)
  106. center("---type more to load more---")
  107. c = input(typing_dots())
  108. if not c:
  109. break
  110. try:
  111. c = int(c)
  112. except:
  113. return