lbry-rss.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. import subprocess
  3. import os
  4. import json
  5. import multiprocessing
  6. import argparse
  7. import urllib.parse
  8. LIBRARIAN_INSTANCE = "https://lbry.ix.tc/"
  9. def get_arguments():
  10. parser = argparse.ArgumentParser(description='LBRY RSS generator')
  11. parser.add_argument('-o', '--odysee', action="store_true", default=False, help='Odysee RSS')
  12. parser.add_argument('-l', '--librarian', action="store_true", default=False, help='Librarian RSS')
  13. parser.add_argument('-m', '--melroy', action="store_true", default=False, help='Melroy RSS')
  14. return parser.parse_args()
  15. def lbry_start():
  16. startnow = subprocess.Popen("lbrynet start", stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
  17. dot = "."
  18. def get():
  19. data = subprocess.getoutput("lbrynet preference get")
  20. while True:
  21. if data == "Could not connect to daemon. Are you sure it's running?":
  22. dot += "."
  23. print(dot)
  24. else:
  25. data = subprocess.getoutput("lbrynet preference get")
  26. return json.loads(data)
  27. def rss(start, end):
  28. data = get()
  29. channels = []
  30. for channel in data["shared"]["value"]["subscriptions"]:
  31. channel = channel.split("#")[0].replace("lbry://","",1)
  32. channels.append(urllib.parse.urljoin(start, channel+end))
  33. return '\n'.join(channels)
  34. def main():
  35. args = get_arguments()
  36. if args.odysee:
  37. print(rss("https://odysee.com/$/rss/",""))
  38. if args.librarian:
  39. print(rss(LIBRARIAN_INSTANCE, "/rss"))
  40. if args.melroy:
  41. print(rss("https://lbryfeed.melroy.org/channel", ""))
  42. if __name__ == '__main__':
  43. p1 = multiprocessing.Process(name='p1', target=lbry_start)
  44. p = multiprocessing.Process(name='p', target=get)
  45. p1.start()
  46. p.start()
  47. main()