variables.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 is a set of variables used by different files. It's needed
  30. # so I will not need to hard code the values each time. Stuff like
  31. # basic translations of the LBRY data into human language. And a more
  32. # complex functions like translating size in bytes into something more
  33. # readable.
  34. # Colors are used to make the
  35. clr = {
  36. "norm":"\033[00m", # Reset to normal
  37. "bold":"\033[01m", # Bold Text
  38. "ital":"\033[03m", # Italic Text
  39. "undr":"\033[04m", # Underlined
  40. "blnk":"\033[05m", # Blinking
  41. # Text
  42. "tdbl":"\033[30m", # Dark Black
  43. "tdrd":"\033[31m", # Dark Red
  44. "tdgr":"\033[32m", # Dark Green
  45. "tdyl":"\033[33m", # Dark Yellow
  46. "tdbu":"\033[34m", # Dark Blue
  47. "tdma":"\033[35m", # Dark Magenta
  48. "tdcy":"\033[36m", # Dark Cyan
  49. "tdwh":"\033[37m", # Dark White
  50. "tbbl":"\033[90m", # Bright Black
  51. "tbrd":"\033[91m", # Bright Red
  52. "tbgr":"\033[92m", # Bright Green
  53. "tbyl":"\033[93m", # Bright Yellow
  54. "tbbu":"\033[94m", # Bright Blue
  55. "tbma":"\033[95m", # Bright Magenta
  56. "tbcy":"\033[96m", # Bright Cyan
  57. "tbwh":"\033[97m", # Bright White
  58. # Background
  59. "bdbl":"\033[40m", # Dark Black
  60. "bdrd":"\033[41m", # Dark Red
  61. "bdgr":"\033[42m", # Dark Green
  62. "bdyl":"\033[43m", # Dark Yellow
  63. "bdbu":"\033[44m", # Dark Blue
  64. "bdma":"\033[45m", # Dark Magenta
  65. "bdcy":"\033[46m", # Dark Cyan
  66. "bdwh":"\033[47m", # Dark White
  67. "bbbl":"\033[100m", # Bright Black
  68. "bbrd":"\033[101m", # Bright Red
  69. "bbgr":"\033[102m", # Bright Green
  70. "bbyl":"\033[103m", # Bright Yellow
  71. "bbbu":"\033[104m", # Bright Blue
  72. "bbma":"\033[105m", # Bright Magenta
  73. "bbcy":"\033[106m", # Bright Cyan
  74. "bbwh":"\033[108m" # Bright White
  75. }
  76. # A function that insures a specific width of the printed part
  77. def wdth(x, n):
  78. # Just in case...
  79. x = str(x)
  80. if len(x) < n:
  81. x = (" "*(n-len(x)))+x
  82. elif len(x) > n:
  83. if n > 10:
  84. x = x[:n-3]+"..."
  85. else:
  86. x = x[:n]
  87. return x
  88. # A dictionary for translations of things from the SDK into
  89. # readable thing
  90. what = {
  91. "stream":"FILE",
  92. "repost":"SHARED",
  93. "channel": "CHANNEL",
  94. "collection": "PLAYLIST"
  95. }
  96. # This function will take a list and present in a pretty
  97. # way.
  98. def tgz(x):
  99. # Just in case
  100. if type(x) != list:
  101. x = x.split()
  102. y = ""
  103. for i in x:
  104. y = y + i + ", "
  105. return y[:-2]
  106. # This function will convert bites into readable data making sense
  107. def csize(x):
  108. x = float(x)
  109. l = ["B","KB", "MB", "GB", "TB"]
  110. for i in range(5):
  111. if x > 1024:
  112. x = x / 1024
  113. else:
  114. return str(round(x, 2))+" "+l[i]
  115. return str(round(x, 2))+" "+l[i]
  116. # This next function will select the amount of ::: for a given
  117. # input.
  118. def typing_dots():
  119. import inspect
  120. depth = len(inspect.stack()) # This is the depth of the stack
  121. # since this function call adds 1 to the stack we need
  122. # to decrease the number by one
  123. depth -= 1
  124. # Now I want to select a sequence of colors.
  125. x = ["bdma","bdbu", "bdrd", "bdgr", "bdcy", "bdyl"]
  126. ret = " "+clr["bold"]
  127. for i in reversed(range(depth)):
  128. ret = ret + clr["tbwh"] + clr[x[i % len(x)]] + ":"
  129. ret = ret + clr["norm"]+" "
  130. return ret