lbry-uploader.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/env python
  2. import random
  3. import string
  4. import json
  5. import os
  6. import subprocess
  7. import re
  8. lbrynet = "lbrynet"
  9. # Got from: https://notabug.org/jyamihud/FastLBRY-terminal/src/master/flbry/variables.py#L502
  10. licenses = [
  11. # NAME , URL , COMMENT
  12. ["GNU General Public License Version 3 (or later)",
  13. "https://www.gnu.org/licenses/gpl-3.0.html",
  14. "Strong Copyleft. Recommended for Software."],
  15. ["GNU General Public License Version 3 (only)",
  16. "https://www.gnu.org/licenses/gpl-3.0.html",
  17. "Strong Copyleft."],
  18. ["GNU Free Documentation License",
  19. "https://www.gnu.org/licenses/fdl-1.3.html",
  20. "Strong Copyleft. Recommended for books."],
  21. ["Creative Commons Attribution-ShareAlike 4.0 International",
  22. "https://creativecommons.org/licenses/by-sa/4.0/",
  23. "Copylefted, Recommended for Art."],
  24. ["Creative Commons Attribution 4.0 International",
  25. "https://creativecommons.org/licenses/by/4.0/",
  26. "Non Copylefted, Free License."],
  27. ["Creative Commons Zero 1.0 International",
  28. "https://creativecommons.org/publicdomain/zero/1.0/",
  29. "Public Domain"],
  30. ["Creative Commons Attribution-NoDerivatives 4.0 International",
  31. "https://creativecommons.org/licenses/by-nd/4.0/",
  32. "Does not allow changes. Recommended for opinion pieces."]
  33. ]
  34. # Check that lbry sdk is running.
  35. if subprocess.getoutput(f"{lbrynet} version") == "Could not connect to daemon. Are you sure it's running?":
  36. print('It looks like lbrynet has not started yet. In another terminal window/tab do "lbrynet start" and rerun this script.')
  37. quit()
  38. # Channel
  39. channels = subprocess.getoutput(f"{lbrynet} channel list")
  40. json_stuff = json.loads(channels)
  41. for i, channel in enumerate(json_stuff["items"]):
  42. print(i, "|", channel["name"])
  43. c = 100000
  44. while not c >= 0 or not c <= i:
  45. c = input('Select a channel from 0-'+str(i)+': ')
  46. try:
  47. c = int(c)
  48. except:
  49. c = 100000
  50. channel = json_stuff["items"][c]["name"]
  51. print(f"Uploading to {channel}.\n---")
  52. # Title
  53. title = input("Title for the publication: ")
  54. # Url
  55. print("---\nPressing enter will make it the title just with removed special characters.")
  56. name = input("Custome lbry url name: ")
  57. if name == "":
  58. name = re.sub(r'[\W_]+','', str(title))
  59. # Bid
  60. try:
  61. print("---\nCould be costly to do a upload, press enter and bid will be 0.1")
  62. bid = str(input("Per upload, how much bid do you want? "))
  63. except:
  64. bid = str(0.1)
  65. # Description
  66. try:
  67. print("---\nPressing enter will make the publication not have a description")
  68. description = input("Description for publication: ")
  69. #description = description.replace("\n","\\n")
  70. description = description.replace('"','\\"')
  71. description = description.replace("'","\\'")
  72. except:
  73. description = ""
  74. # Thumbnail
  75. try:
  76. print("---\nIf you want, a thumbnail can be uploaded to lbry. It will have all atributes of the video just the lbry name will be plus 123. Press enter for no thumbnail.")
  77. thumbnail = input("Thumbnail file location: ")
  78. except:
  79. thumbnail = ""
  80. keys = ("abcdefghijklmnopqrxtuvwsyz" + "ABCDEFGHIJKLMNOPQRXTUV" + "1234567890")
  81. name_thumb = ("".join(random.sample(keys,50)))
  82. # Publication
  83. print("---\nFinally we are at the last step!")
  84. publication = input("Publication file location: ")
  85. # License
  86. for i, license in enumerate(licenses):
  87. print(i,*licenses[i],sep='\n')
  88. l = 100000
  89. while not l >= 0 or not l <= 7:
  90. l = input('Select a license from 0-7: ')
  91. try:
  92. l = int(l)
  93. except:
  94. l = 100000
  95. license = licenses[l][0]
  96. license_url = licenses[l][1]
  97. if thumbnail == "":
  98. print("---\nUploading puplication to LBRY!\n---")
  99. command = f'{lbrynet} publish --name="{name}" --bid={bid} --file_path="{publication}" --title="{title}" --description="{description}" --channel_name={channel} --license="{license}" --license_url="{license_url}"'
  100. os.system(command)
  101. else:
  102. print("\n---\nUploading thumbnail to LBRY!")
  103. thumbnail_command = f'{lbrynet} publish --name="{name_thumb}" --bid={bid} --file_path="{thumbnail}" --title="{title}" --description="{description}"'
  104. print(thumbnail_command)
  105. thumbnail_data = subprocess.getoutput(thumbnail_command)
  106. json_stuff = json.loads(thumbnail_data)
  107. thumbnail_url = json_stuff["outputs"][0]["permanent_url"].replace("lbry:/","https://spee.ch")
  108. print("\n---\nUploading puplication to LBRY!\n---")
  109. command = f'{lbrynet} publish --name={name} --bid={bid} --file_path="{publication}" --title="{title}" --description="{description}" --channel_name={channel} --thumbnail="{thumbnail_url}" --license="{license}" --license_url="{license_url}"'
  110. print(command)
  111. os.system(command)
  112. print("\n---\nLINK:\n---")
  113. print(f"https://spee.ch/{channel}/{name}")