connect.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 start the lbrynet sdk.
  30. import subprocess
  31. import json
  32. import random
  33. from flbry.variables import *
  34. def start():
  35. if check():
  36. center("SDK is already running")
  37. else:
  38. retcode = subprocess.Popen([lbrynet_binary["b"], 'start'],
  39. stdout=subprocess.DEVNULL,
  40. stderr=subprocess.STDOUT)
  41. progress_bar(0.2, 10, "Checking Wallet...")
  42. count = 0
  43. while not check():
  44. count = count + ((9 - count) / (5+random.random()))
  45. #if count > 5:
  46. # count = 3
  47. progress_bar(count, 10, "Loading Wallet...")
  48. progress_bar(10, 10, "Connection established")
  49. print()
  50. def stop():
  51. if check():
  52. retcode = subprocess.Popen([lbrynet_binary["b"], 'stop'],
  53. stdout=subprocess.DEVNULL,
  54. stderr=subprocess.STDOUT)
  55. center("LBRY Connection Closed")
  56. else:
  57. center("SDK is not running")
  58. def check():
  59. # This output true or false
  60. # whether the SDK is running
  61. try:
  62. out = subprocess.check_output([lbrynet_binary["b"],
  63. "claim", "search", '--text="test"',
  64. '--page=1',
  65. '--page_size=1',
  66. "--no_totals",
  67. '--order_by=release_time'])
  68. out = json.loads(out)
  69. out["items"]
  70. return True
  71. except Exception as e:
  72. #print("ERROR = ", e)
  73. return False