run.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. import os
  30. import readline
  31. from flbry import variables
  32. from flbry.variables import *
  33. # Make sure the config file exists and is up to date
  34. from flbry import settings
  35. settings.check_config()
  36. settings.check_missing_keys()
  37. # Do some things with the settings
  38. hist_file = settings.get_settings_folder()+"terminal-history"
  39. settings.initial_settings_stuff(hist_file)
  40. # A welcome logo.
  41. logo()
  42. # Here I want to make a simple check for an operating system
  43. # The software is built to work on GNU / Linux so I need to
  44. # check whether the user runs it on a proper system. If not
  45. # give them a warning message.
  46. import platform
  47. if platform.system() != "Linux": # IK It should be GNU / Linux
  48. center("OS "+platform.system().upper()+" NOT SUPPORTED!", "bdrd", True)
  49. center("Type 'osinfo' to learn more.", "bdrd")
  50. # Importing all kinds of other things needed for the operations
  51. from flbry import connect
  52. from flbry import search
  53. from flbry import channel
  54. from flbry import wallet
  55. from flbry import uploads
  56. from flbry import list_files
  57. from flbry import following
  58. from flbry import markdown
  59. from flbry import trending
  60. from flbry import url
  61. from flbry import publish
  62. from flbry import comments
  63. from flbry import donate
  64. from flbry import simple
  65. # Now we gonna start the main loop. It will give the user to input
  66. # any function. And when the function is executed, it will give it
  67. # again. Forever. Until the user exits.
  68. # List of commands for autocomplete feature.
  69. main_commands = [
  70. "exit",
  71. "quit",
  72. "help",
  73. "osinfo",
  74. "matrix",
  75. "clear",
  76. "repository",
  77. "report",
  78. "license",
  79. "connect",
  80. "disconnect",
  81. "publish",
  82. "history",
  83. "search",
  84. "channels",
  85. "channel",
  86. "channel_new",
  87. "trending",
  88. "articles",
  89. "login",
  90. "wallet",
  91. "balance",
  92. "inbox",
  93. "uploads",
  94. "following",
  95. "subscriptions",
  96. "install",
  97. "install_force",
  98. "settings",
  99. "addresses",
  100. "send",
  101. "donations_test",
  102. "donations_diff",
  103. "donations_update",
  104. "donations_add",
  105. "donate",
  106. "reupload"
  107. ]
  108. complete(main_commands)
  109. while True:
  110. command = input(typing_dots()) # the : will be the presented function
  111. if command == "exit":
  112. if settings.get("save_history"):
  113. readline.write_history_file(hist_file)
  114. connect.stop()
  115. break # breaks the while True: loop
  116. elif command == "quit":
  117. if settings.get("save_history"):
  118. readline.write_history_file(hist_file)
  119. print(" Quit does not disconnect the SDK!")
  120. print(" To disconnet use exit or disconnect.")
  121. break
  122. elif command == "help":
  123. markdown.draw("help/main.md", "Help")
  124. elif command == "osinfo":
  125. markdown.draw("help/os.md", "Operating System Information")
  126. # HELP AND CONTRIBUTION FUNCTIONS
  127. elif command == "matrix":
  128. print(" #FastLBRY:matrix.org")
  129. elif command == "clear":
  130. os.system("clear")
  131. elif command == "repository":
  132. print(" https://notabug.org/jyamihud/FastLBRY-terminal")
  133. elif command == "report":
  134. print(" https://notabug.org/jyamihud/FastLBRY-terminal/issues")
  135. elif command == "license":
  136. markdown.draw("LICENSE.md", "License (GPLv3 or later)")
  137. # LBRY COMMANDS
  138. elif command == "connect":
  139. connect.start()
  140. elif command == "disconnect":
  141. connect.stop()
  142. elif command.startswith("publish"):
  143. if " " in command:
  144. publish.configure(command[command.find(" ")+1:])
  145. else:
  146. publish.configure()
  147. elif command == "history":
  148. list_files.downloaded()
  149. elif command.startswith("search"):
  150. if " " in command:
  151. search.simple(command[command.find(" ")+1:])
  152. else:
  153. search.simple()
  154. elif command == "channels":
  155. channel.simple(channel.select())
  156. elif command == "channel_new":
  157. channel.create()
  158. elif command.startswith("channel"):
  159. if " " in command:
  160. channel.simple(command[command.find(" ")+1:])
  161. else:
  162. channel.simple()
  163. elif command.startswith("trending"):
  164. trending.simple()
  165. elif command.startswith("articles"):
  166. trending.simple(articles=True)
  167. elif command in ("following", "subscriptions"):
  168. following.following()
  169. elif command.startswith("reupload"):
  170. re-upload.simple()
  171. ###### WALLET ######
  172. elif command == "login":
  173. markdown.draw("help/login.md", "Login Help")
  174. elif command == "wallet":
  175. wallet.history()
  176. elif command == "balance":
  177. wallet.balance()
  178. elif command.startswith("inbox"):
  179. if " " in command:
  180. comments.inbox(command[command.find(" ")+1:])
  181. else:
  182. comments.inbox()
  183. elif command == "uploads":
  184. uploads.simple()
  185. elif command == "install":
  186. settings.install_desktop(False)
  187. elif command == "install_force":
  188. settings.install_desktop(True)
  189. elif command == "settings":
  190. settings.ui()
  191. elif command == "addresses":
  192. wallet.addresses()
  193. elif command == "send":
  194. wallet.address_send()
  195. elif command == "donations_update":
  196. donate.check_devs_file(save_changes=True)
  197. elif command == "donations_test":
  198. donate.check_devs_file(user_check=True)
  199. elif command == "donations_diff":
  200. donate.check_devs_file(user_check=True, diff=True)
  201. elif command == "donations_add":
  202. donate.add()
  203. elif command == "donate":
  204. donate.donate()
  205. # If a user types anything ELSE, except just simply pressing
  206. # Enter. So if any text is in the command, but non of the
  207. # above were activated.
  208. # Here I want to just run the URL module and try to resolve
  209. # the url. The Url module will need to be able to handle a
  210. # lot of it.
  211. elif command:
  212. url.get(command)
  213. # Restore the commands completion
  214. complete(main_commands)