run.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 plugin
  65. from flbry import analytics
  66. # Now we gonna start the main loop. It will give the user to input
  67. # any function. And when the function is executed, it will give it
  68. # again. Forever. Until the user exits.
  69. # List of commands for autocomplete feature.
  70. main_commands = [
  71. "exit",
  72. "quit",
  73. "help",
  74. "osinfo",
  75. "matrix",
  76. "clear",
  77. "repository",
  78. "report",
  79. "license",
  80. "connect",
  81. "disconnect",
  82. "publish",
  83. "history",
  84. "search",
  85. "channels",
  86. "channel",
  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. "create-channel",
  107. "plugins",
  108. "get_plugin",
  109. "sales",
  110. "analytics",
  111. "readme",
  112. "total_sales",
  113. "total_analytics",
  114. "load_graph"
  115. ]
  116. complete(main_commands)
  117. def main():
  118. to_text = True
  119. while True:
  120. # Set the global variables
  121. variables.flbry_globals["lbrynet"] = settings.get("lbrynet_binary")
  122. variables.flbry_globals["comment_api"] = settings.get("comment_api")
  123. plugin.run(address="main") # adding all the commands from plugins
  124. command = input(typing_dots("Type 'help' for more info.", to_text)) # the : will be the presented function
  125. to_text = False
  126. if command == "exit":
  127. connect.stop()
  128. break # breaks the while True: loop
  129. elif command == "quit":
  130. center("Quit does not disconnect the SDK!", "bdrd")
  131. center("To disconnect use 'exit' or 'disconnect'.")
  132. break
  133. elif command == "help":
  134. markdown.draw("help/main.md", "Help")
  135. elif command == "readme":
  136. markdown.draw("README.md", "Readme")
  137. elif command == "osinfo":
  138. markdown.draw("help/os.md", "Operating System Information")
  139. # HELP AND CONTRIBUTION FUNCTIONS
  140. elif command == "matrix":
  141. center("#FastLBRY:matrix.org")
  142. elif command == "clear":
  143. os.system("clear")
  144. elif command == "repository":
  145. center("https://notabug.org/jyamihud/FastLBRY-terminal")
  146. elif command == "report":
  147. try_getting_git_commit()
  148. center("Report issues here: https://notabug.org/jyamihud/FastLBRY-terminal/issues")
  149. elif command == "license":
  150. markdown.draw("LICENSE.md", "License (GPLv3 or later)")
  151. # LBRY COMMANDS
  152. elif command == "connect":
  153. connect.start()
  154. elif command == "disconnect":
  155. connect.stop()
  156. elif command.startswith("publish"):
  157. if " " in command:
  158. publish.configure(command[command.find(" ")+1:])
  159. else:
  160. publish.configure()
  161. elif command == "history":
  162. list_files.downloaded()
  163. elif command.startswith("search"):
  164. if " " in command:
  165. search.simple(command[command.find(" ")+1:])
  166. else:
  167. search.simple()
  168. elif command == "channels":
  169. channel.simple(channel.select())
  170. elif command.startswith("channel"):
  171. if " " in command:
  172. channel.simple(command[command.find(" ")+1:])
  173. else:
  174. channel.simple()
  175. elif command.startswith("trending"):
  176. trending.simple()
  177. elif command.startswith("articles"):
  178. trending.simple(articles=True)
  179. elif command in ("following", "subscriptions"):
  180. following.following()
  181. ###### WALLET ######
  182. elif command == "login":
  183. markdown.draw("help/login.md", "Login Help")
  184. elif command == "wallet":
  185. wallet.history()
  186. elif command == "balance":
  187. wallet.balance()
  188. elif command.startswith("inbox"):
  189. if " " in command:
  190. comments.inbox(command[command.find(" ")+1:])
  191. else:
  192. comments.inbox()
  193. elif command == "uploads":
  194. uploads.simple()
  195. elif command == "install":
  196. settings.install_desktop(False)
  197. elif command == "install_force":
  198. settings.install_desktop(True)
  199. elif command == "settings":
  200. settings.ui()
  201. elif command == "addresses":
  202. wallet.addresses()
  203. elif command == "send":
  204. wallet.address_send()
  205. elif command == "donations_update":
  206. donate.check_devs_file(save_changes=True)
  207. elif command == "donations_test":
  208. donate.check_devs_file(user_check=True)
  209. elif command == "donations_diff":
  210. donate.check_devs_file(user_check=True, diff=True)
  211. elif command == "donations_add":
  212. donate.add()
  213. elif command == "donate":
  214. donate.donate()
  215. elif command == "sales":
  216. analytics.sales()
  217. elif command == "analytics":
  218. analytics.sales("analytics")
  219. elif command.startswith("create-channel"):
  220. if " " in command:
  221. channel.create(command[command.find(" ")+1:])
  222. else:
  223. channel.create()
  224. elif command.startswith("plugins"):
  225. if " " in command:
  226. plugin.manager(command[command.find(" ")+1:])
  227. else:
  228. plugin.manager()
  229. elif command.startswith("get_plugin"):
  230. if " " in command:
  231. plugin.get_plugin(command[command.find(" ")+1:])
  232. else:
  233. plugin.get_plugin()
  234. elif command == "total_sales":
  235. items = analytics.get_data()
  236. try:
  237. analytics.graph_loop(items)
  238. except Exception as e:
  239. print(e)
  240. print()
  241. elif command == "total_analytics":
  242. items = analytics.get_data(mode="analytics")
  243. try:
  244. analytics.graph_loop(items)
  245. except Exception as e:
  246. print(e)
  247. print()
  248. elif command == "load_graph":
  249. analytics.load_graph_from_file()
  250. # If a user types anything ELSE, except just simply pressing
  251. # Enter. So if any text is in the command, but non of the
  252. # above were activated.
  253. # Here I want to just run the URL module and try to resolve
  254. # the url. The Url module will need to be able to handle a
  255. # lot of it.
  256. elif command:
  257. command = plugin.run(command, command, "main")
  258. if command:
  259. url.get(command)
  260. # Restore the commands completion
  261. complete(main_commands)
  262. if __name__ == '__main__':
  263. try:
  264. main()
  265. except KeyboardInterrupt:
  266. print()
  267. center("Ctrl-C does not disconnect the SDK!", "bdrd")
  268. center("To disconnect use 'exit' or 'disconnect'.")
  269. finally:
  270. # Save history on exit
  271. if settings.get("save_history"):
  272. try:
  273. readline.write_history_file(hist_file)
  274. except Exception as e:
  275. center("Error writing history: "+str(e), "bdrd")