run.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # Preparing the executable of lbrynet to be running. If we don't that
  30. # there will be a nasty error of permission being denied.
  31. import os
  32. os.system("chmod u+x flbry/lbrynet")
  33. from flbry.variables import *
  34. # A welcome logo.
  35. logo()
  36. # Here I want to make a simple check for an operating system
  37. # The software is built to work on GNU / Linux so I need to
  38. # check whether the user runs it on a proper system. If not
  39. # give them a warning message.
  40. import platform
  41. if platform.system() != "Linux": # IK It should be GNU / Linux
  42. center("OS "+platform.system().upper()+" NOT SUPPORTED!", "bdrd", True)
  43. center("Type 'osinfo' to learn more.", "bdrd")
  44. # Importing all kinds of other things needed for the operations
  45. from flbry import connect
  46. from flbry import search
  47. from flbry import channel
  48. from flbry import wallet
  49. from flbry import uploads
  50. from flbry import list_files
  51. from flbry import markdown
  52. from flbry import trending
  53. from flbry import url
  54. from flbry import publish
  55. def commands(command):
  56. if command == "exit":
  57. connect.stop()
  58. elif command == "quit":
  59. print(" Quit does not disconnect the SDK!")
  60. print(" To disconnect use exit or disconnect.")
  61. elif command == "help":
  62. markdown.draw("help/main.md", "Help")
  63. elif command == "osinfo":
  64. markdown.draw("help/os.md", "Operating System Information")
  65. # HELP AND CONTRIBUTION FUNCTIONS
  66. elif command == "matrix":
  67. print(" #FastLBRY:matrix.org")
  68. elif command == "clear":
  69. os.system("clear")
  70. elif command == "repository":
  71. print(" https://notabug.org/jim41825/FastLBRY-terminal")
  72. elif command == "report":
  73. print(" https://notabug.org/jim41825/FastLBRY-terminal/issues")
  74. elif command == "license":
  75. markdown.draw("LICENSE.md", "License (GPLv3 or later)")
  76. # LBRY COMMANDS
  77. elif command == "connect":
  78. connect.start()
  79. elif command == "disconnect":
  80. connect.stop()
  81. elif command.startswith("publish"):
  82. if " " in command:
  83. publish.configure(command[command.find(" ")+1:])
  84. else:
  85. publish.configure()
  86. elif command == "history":
  87. list_files.downloaded()
  88. elif command.startswith("search"):
  89. if " " in command:
  90. search.simple(command[command.find(" ")+1:])
  91. else:
  92. search.simple()
  93. elif command == "channels":
  94. channel.simple(channel.select())
  95. elif command.startswith("channel"):
  96. if " " in command:
  97. channel.simple(command[command.find(" ")+1:])
  98. else:
  99. channel.simple()
  100. elif command.startswith("trending"):
  101. trending.simple()
  102. elif command.startswith("articles"):
  103. trending.simple(articles=True)
  104. ###### WALLET ######
  105. elif command == "login":
  106. markdown.draw("help/login.md", "Login Help")
  107. elif command == "wallet":
  108. wallet.history()
  109. elif command == "uploads":
  110. uploads.simple()
  111. # If a user types anything ELSE, except just simply pressing
  112. # Enter. So if any text is in the command, but non of the
  113. # above were activated.
  114. # Here I want to just run the URL module and try to resolve
  115. # the url. The Url module will need to be able to handle a
  116. # lot of it.
  117. elif command:
  118. url.get(command)
  119. from prompt_toolkit import PromptSession
  120. from prompt_toolkit.completion import WordCompleter
  121. def main_repl():
  122. command = ps.prompt()
  123. commands(command)
  124. if __name__ == "__main__":
  125. ps=PromptSession(": ",completer=WordCompleter(["help","exit","quit","clear","connect","disconnect","search","trending","channel","wallet","uploads","articles","report"]))
  126. while True:
  127. main_repl()